-
Notifications
You must be signed in to change notification settings - Fork 604
fix(opencode): handle Windows project basenames #656
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
Open
dnlrsls
wants to merge
7
commits into
Gentleman-Programming:main
Choose a base branch
from
dnlrsls:fix/652-windows-project-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+194
−12
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6eb13b
fix(opencode): handle Windows project basenames
dnlrsls b8ee6d6
fix(opencode): handle trailing project separators
dnlrsls 560fe42
fix(opencode): preserve legacy migration key
dnlrsls 4cd6312
fix(opencode): migrate legacy Git-root keys
dnlrsls b6132d3
test(opencode): cover legacy migration payloads
dnlrsls a9794f3
test(opencode): cover trailing POSIX migration
dnlrsls d0ee245
fix(opencode): reject Windows drive roots
dnlrsls 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
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,158 @@ | ||
| import assert from "node:assert/strict" | ||
| import { test } from "node:test" | ||
|
|
||
| import { Engram } from "./engram.ts" | ||
|
|
||
| type SpawnResult = { | ||
| exitCode: number | ||
| stdout?: Buffer | ||
| } | ||
|
|
||
| async function createPlugin( | ||
| directory: string, | ||
| spawnSync: (command: string[]) => SpawnResult, | ||
| ) { | ||
| const requests: Array<{ path: string; body?: unknown }> = [] | ||
|
|
||
| globalThis.Bun = { | ||
| spawnSync, | ||
| file: () => ({ exists: async () => false }), | ||
| } as typeof Bun | ||
|
|
||
| globalThis.fetch = (async (input: string | URL | Request, init?: RequestInit) => { | ||
| const url = new URL(input.toString()) | ||
| const body = init?.body ? JSON.parse(init.body.toString()) : undefined | ||
| requests.push({ path: url.pathname, body }) | ||
|
|
||
| return new Response(JSON.stringify({}), { | ||
| status: 200, | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| }) as typeof fetch | ||
|
|
||
| const plugin = await Engram({ directory } as never) | ||
| return { plugin, requests } | ||
| } | ||
|
|
||
| test("uses the Windows basename in compaction recovery outside Git", async () => { | ||
| const { plugin, requests } = await createPlugin("C:\\Users\\Blackie", () => ({ exitCode: 1 })) | ||
| const output = { context: [] as string[] } | ||
|
|
||
| await plugin["experimental.session.compacting"]?.( | ||
| { sessionID: "session-652" } as never, | ||
| output, | ||
| ) | ||
|
|
||
| assert.match(output.context.at(-1) ?? "", /Use project: 'Blackie'/) | ||
| assert.doesNotMatch(output.context.at(-1) ?? "", /C:\\Users\\Blackie/) | ||
| assert.deepEqual( | ||
| requests.find(({ path }) => path === "/projects/migrate")?.body, | ||
| { old_project: "C:\\Users\\Blackie", new_project: "Blackie" }, | ||
| ) | ||
| }) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| test("ignores trailing Windows separators in the basename fallback", async () => { | ||
| const { plugin, requests } = await createPlugin("C:\\Users\\Blackie\\", () => ({ exitCode: 1 })) | ||
| const output = { context: [] as string[] } | ||
|
|
||
| await plugin["experimental.session.compacting"]?.( | ||
| { sessionID: "session-652-trailing" } as never, | ||
| output, | ||
| ) | ||
|
|
||
| assert.match(output.context.at(-1) ?? "", /Use project: 'Blackie'/) | ||
| assert.deepEqual( | ||
| requests.find(({ path }) => path === "/projects/migrate")?.body, | ||
| { old_project: "C:\\Users\\Blackie\\", new_project: "Blackie" }, | ||
| ) | ||
| }) | ||
|
|
||
| test("uses the Windows basename from the Git-root fallback", async () => { | ||
| const { plugin } = await createPlugin("C:\\Users\\Blackie\\project", (command) => { | ||
| if (command.includes("rev-parse")) { | ||
| return { | ||
| exitCode: 0, | ||
| stdout: Buffer.from("C:\\Users\\Blackie\\worktrees\\engram-652\n"), | ||
| } | ||
| } | ||
| return { exitCode: 1 } | ||
| }) | ||
| const output = { context: [] as string[] } | ||
|
|
||
| await plugin["experimental.session.compacting"]?.( | ||
| { sessionID: "session-652-git-root" } as never, | ||
| output, | ||
| ) | ||
|
|
||
| assert.match(output.context.at(-1) ?? "", /Use project: 'engram-652'/) | ||
| }) | ||
|
|
||
| test("does not migrate when the legacy remote project is unchanged", async () => { | ||
| const { requests } = await createPlugin("C:\\Users\\Blackie", (command) => { | ||
| if (command.includes("get-url")) { | ||
| return { | ||
| exitCode: 0, | ||
| stdout: Buffer.from("https://github.com/Gentleman-Programming/engram.git\n"), | ||
| } | ||
| } | ||
| return { exitCode: 1 } | ||
| }) | ||
|
|
||
| assert.equal(requests.some(({ path }) => path === "/projects/migrate"), false) | ||
| }) | ||
|
|
||
| test("migrates the legacy Windows Git-root key from a nested directory", async () => { | ||
| const { requests } = await createPlugin("C:\\repos\\engram\\nested", (command) => { | ||
| if (command.includes("rev-parse")) { | ||
| return { | ||
| exitCode: 0, | ||
| stdout: Buffer.from("C:\\repos\\engram\n"), | ||
| } | ||
| } | ||
| return { exitCode: 1 } | ||
| }) | ||
|
|
||
| assert.deepEqual( | ||
| requests.find(({ path }) => path === "/projects/migrate")?.body, | ||
| { old_project: "C:\\repos\\engram", new_project: "engram" }, | ||
| ) | ||
| }) | ||
|
|
||
| test("preserves POSIX basename fallback behavior", async () => { | ||
| const { plugin } = await createPlugin("/home/blackie", () => ({ exitCode: 1 })) | ||
| const output = { context: [] as string[] } | ||
|
|
||
| await plugin["experimental.session.compacting"]?.( | ||
| { sessionID: "session-posix" } as never, | ||
| output, | ||
| ) | ||
|
|
||
| assert.match(output.context.at(-1) ?? "", /Use project: 'blackie'/) | ||
| }) | ||
|
|
||
| test("migrates the legacy empty POSIX key for a trailing separator", async () => { | ||
| const { requests } = await createPlugin("/home/blackie/", () => ({ exitCode: 1 })) | ||
|
|
||
| assert.deepEqual( | ||
| requests.find(({ path }) => path === "/projects/migrate")?.body, | ||
| { old_project: "", new_project: "blackie" }, | ||
| ) | ||
| }) | ||
|
|
||
| for (const [directory, oldProject] of [["C:\\", "C:\\"], ["C:/", ""]]) { | ||
| test(`uses unknown for the Windows drive root ${directory}`, async () => { | ||
| const { plugin, requests } = await createPlugin(directory, () => ({ exitCode: 1 })) | ||
| const output = { context: [] as string[] } | ||
|
|
||
| await plugin["experimental.session.compacting"]?.( | ||
| { sessionID: `session-drive-root-${directory}` } as never, | ||
| output, | ||
| ) | ||
|
|
||
| assert.match(output.context.at(-1) ?? "", /Use project: 'unknown'/) | ||
| assert.deepEqual( | ||
| requests.find(({ path }) => path === "/projects/migrate")?.body, | ||
| { old_project: oldProject, new_project: "unknown" }, | ||
| ) | ||
| }) | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.