-
Notifications
You must be signed in to change notification settings - Fork 0
test: make git isolation structural via test preload #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aorumbayev
merged 5 commits into
fix/verify-gate-gaps
from
fix/test-hermeticity-structural
Jul 10, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2421cc5
test: make git hermeticity structural via preload
aorumbayev 6278686
test: rename hermeticity wording to git isolation
aorumbayev d936c61
test: wait for the merge-conflict notice instead of asserting notice …
aorumbayev 9bd1d0f
test: allow slow CI git spawns to deliver the merge-conflict notice
aorumbayev 4d9bdad
fix: make update promotion crash-safe and trim speculative machinery …
aorumbayev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| #!/bin/sh | ||
| set -e | ||
| # git exports GIT_DIR/GIT_INDEX_FILE into hooks (always, in linked worktrees), | ||
| # which hijacks the real-git test repos the suite creates under tmpdir. | ||
| unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR GIT_PREFIX | ||
| bun run verify -- --check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import type { TuiPluginMeta } from "@opencode-ai/plugin/tui" | ||
| import { basename, dirname, join } from "node:path" | ||
| import { isAutomaticUpdateInstall, parseRelease } from "./updates" | ||
| import { | ||
| defaultFileSystem, | ||
| type FileSystem, | ||
| markerMatches, | ||
| stat, | ||
| type UpdateMarker, | ||
| type UpdatePaths, | ||
| updatePaths, | ||
| validateWrapper, | ||
| } from "./update-paths" | ||
|
|
||
| async function readMarker(fs: FileSystem, markerPath: string): Promise<UpdateMarker | undefined> { | ||
| const info = await stat(fs, markerPath) | ||
| if (!info?.isFile()) return | ||
| try { | ||
| return JSON.parse(await fs.readFile(markerPath, "utf8")) as UpdateMarker | ||
| } catch { | ||
| await fs.rm(markerPath, { force: true }) | ||
| } | ||
| } | ||
|
|
||
| async function removeOrphanBackup( | ||
| fs: FileSystem, | ||
| paths: UpdatePaths, | ||
| target: string, | ||
| currentVersion: string, | ||
| marker: UpdateMarker | undefined, | ||
| matchesCurrent: boolean, | ||
| ) { | ||
| if (!(await stat(fs, paths.backup))) return | ||
| if (marker && matchesCurrent) return | ||
| await validateWrapper(fs, paths.current, target, currentVersion) | ||
| await fs.rm(paths.backup, { recursive: true }) | ||
| } | ||
|
|
||
| // Guard against a corrupted marker naming an arbitrary path: only sweep prepared dirs Kagan itself | ||
| // could have created — a `kagan@<x.y.z>` sibling of the current wrapper in the same scope cache. | ||
| function preparedInCache(preparedPath: string, paths: UpdatePaths): boolean { | ||
| if (dirname(preparedPath) !== dirname(paths.current)) return false | ||
| const name = basename(preparedPath) | ||
| if (!name.startsWith("kagan@")) return false | ||
| return parseRelease(name.slice("kagan@".length)) !== undefined | ||
| } | ||
|
|
||
| async function removeStaleMarker(fs: FileSystem, paths: UpdatePaths, marker: UpdateMarker) { | ||
| if (marker.prepared && preparedInCache(marker.prepared, paths)) { | ||
| await fs.rm(marker.prepared, { recursive: true, force: true }).catch(() => {}) | ||
| } | ||
| await fs.rm(paths.marker, { force: true }) | ||
| } | ||
|
|
||
| export async function cleanupPreparedUpdate( | ||
| meta: TuiPluginMeta, | ||
| currentVersion: string, | ||
| fs: FileSystem = defaultFileSystem, | ||
| ): Promise<void> { | ||
| if (!isAutomaticUpdateInstall({ source: meta.source, spec: meta.spec, version: currentVersion })) return | ||
| const paths = updatePaths(meta.target, currentVersion) | ||
| const marker = await readMarker(fs, paths.marker) | ||
| const matches = Boolean(marker && markerMatches(marker, paths, currentVersion)) | ||
|
|
||
| await removeOrphanBackup(fs, paths, meta.target, currentVersion, marker, matches) | ||
|
|
||
| if (marker && !matches) { | ||
| await removeStaleMarker(fs, paths, marker) | ||
| } | ||
|
|
||
| const markerForCleanup = await readMarker(fs, paths.marker) | ||
| if (!markerForCleanup || !markerMatches(markerForCleanup, paths, currentVersion)) return | ||
|
|
||
| await validateWrapper(fs, paths.current, meta.target, currentVersion) | ||
| if (await stat(fs, paths.backup)) { | ||
| await validateWrapper(fs, paths.backup, join(paths.backup, "node_modules", "@kagan-sh", "kagan")) | ||
| await fs.rm(paths.backup, { recursive: true }) | ||
| } | ||
| // Interrupted promotion + host re-download leaves the prepared dir behind; it is self-computed, so sweep it. | ||
| if (await stat(fs, paths.prepared)) await fs.rm(paths.prepared, { recursive: true }) | ||
| await fs.rm(paths.marker) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import type { TuiPluginApi, TuiPluginMeta } from "@opencode-ai/plugin/tui" | ||
| import { cleanupPreparedUpdate } from "./update-cleanup" | ||
| import { prepareUpdate } from "./update-manager" | ||
| import { checkForUpdate, type UpdateStatus } from "./updates" | ||
| import { defaultFileSystem, type FileSystem } from "./update-paths" | ||
|
|
||
| export function showUpdateToast(api: TuiPluginApi, currentVersion: string, status: Exclude<UpdateStatus, undefined>) { | ||
| if (status.kind === "broken") return | ||
| if (api.route.current.name !== "home" && api.route.current.name !== "session") return | ||
| api.ui.toast({ | ||
| variant: status.kind === "ready" ? "success" : "warning", | ||
| title: "Kagan", | ||
| message: | ||
| status.kind === "ready" | ||
| ? `Kagan v${status.version} is ready. Restart OpenCode to apply.` | ||
| : `Kagan v${currentVersion} remains active. Kagan v${status.version} requires OpenCode ${status.requiredOpenCode}.`, | ||
| }) | ||
| } | ||
|
|
||
| export async function runAutomaticUpdateLaunch(input: { | ||
| api: TuiPluginApi | ||
| meta: TuiPluginMeta | ||
| currentVersion: string | ||
| now: number | ||
| setUpdateStatus: (status: UpdateStatus) => void | ||
| showToast?: typeof showUpdateToast | ||
| fetchImpl?: typeof fetch | ||
| fs?: FileSystem | ||
| }): Promise<void> { | ||
| const { api, meta, currentVersion, now, setUpdateStatus } = input | ||
| const showToast = input.showToast ?? showUpdateToast | ||
| const fs = input.fs ?? defaultFileSystem | ||
|
|
||
| try { | ||
| await cleanupPreparedUpdate(meta, currentVersion, fs) | ||
| } catch { | ||
| setUpdateStatus({ kind: "broken" }) | ||
| return | ||
| } | ||
|
|
||
| const status = await checkForUpdate({ | ||
| kv: api.kv, | ||
| currentVersion, | ||
| openCodeVersion: api.app.version, | ||
| source: meta.source, | ||
| spec: meta.spec, | ||
| now, | ||
| fetchImpl: input.fetchImpl, | ||
| }) | ||
|
|
||
| if (!status || api.lifecycle.signal.aborted) return | ||
|
|
||
| if (status.kind === "ready" && !(await prepareUpdate({ api, meta, currentVersion, status, fs }))) { | ||
| setUpdateStatus({ kind: "broken" }) | ||
| return | ||
| } | ||
|
|
||
| setUpdateStatus(status) | ||
| showToast(api, currentVersion, status) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
KAGAN_WORKTREE_ROOTis set to an empty string or a relative path,taskWorktreePath()builds a relative worktree directory andcreateTaskWorktree()creates it from the plugin process cwd. A test or deployment that exports this value can place managed git worktrees inside the checkout or another unintended directory instead of the per-user worktree root.Context Used: AGENTS.md (source)
Prompt To Fix With AI