Skip to content

Commit 03fbb9d

Browse files
sahrizviclaude
andcommitted
fix(workspace): attribute a drive-root project's snapshot to C:\, not C:
`snapshotProjectOf` joined the path segments before the snapshot folder, so a project opened at a Windows drive root came back as the bare drive `C:`, which resolves to that drive's current directory rather than its root. It now returns the platform's root (`/`, `C:\`, or a UNC share root) for a root-level project. The function takes an optional path implementation so the Windows behaviour is tested on every platform. Found in the v0.12.4 release PR review. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018fJ3X7pcGT4R9yzjsJnqsV
1 parent 1d715c6 commit 03fbb9d

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎packages/opencode/src/altimate/workspace/snapshot-path.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ const SNAPSHOT_SEGMENTS = [".altimate-code", "skill", "_workspace"]
1414
* A project opened AT the filesystem root puts the snapshot's first segment at index 0, which is a
1515
* project of `/` and not "no project" — the difference decides whether discovery gates the file or
1616
* serves it, so it is spelled out rather than left to a truthiness test. (review) */
17-
export function snapshotProjectOf(location: string): string | null {
18-
const parts = path.resolve(location).split(path.sep)
17+
export function snapshotProjectOf(location: string, p: path.PlatformPath = path): string | null {
18+
const resolved = p.resolve(location)
19+
const parts = resolved.split(p.sep)
1920
for (let i = 0; i + SNAPSHOT_SEGMENTS.length <= parts.length; i++) {
20-
if (SNAPSHOT_SEGMENTS.every((segment, j) => parts[i + j] === segment))
21-
return parts.slice(0, i).join(path.sep) || path.sep
21+
if (SNAPSHOT_SEGMENTS.every((segment, j) => parts[i + j] === segment)) {
22+
const project = parts.slice(0, i).join(p.sep)
23+
// The filesystem root as the platform writes it: `/`, or `C:\` rather than the bare
24+
// drive `C:`, which resolves to the drive's current directory instead of its root.
25+
const root = p.parse(resolved).root
26+
return project === "" || project + p.sep === root ? root : project
27+
}
2228
}
2329
return null
2430
}

‎packages/opencode/test/skill/release-v0.12.4-adversarial.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ describe("v0.12.4 adversarial: snapshot attribution by path segments", () => {
6060
expect(path.resolve(result!)).toBe(path.resolve(ROOT))
6161
})
6262

63+
test("a Windows drive-root project is the drive root, not the bare drive", () => {
64+
const w = path.win32
65+
expect(snapshotProjectOf("C:\\.altimate-code\\skill\\_workspace\\a\\SKILL.md", w)).toBe("C:\\")
66+
expect(snapshotProjectOf("C:\\p\\.altimate-code\\skill\\_workspace\\a\\SKILL.md", w)).toBe("C:\\p")
67+
expect(snapshotProjectOf("\\\\srv\\share\\.altimate-code\\skill\\_workspace\\a\\SKILL.md", w)).toBe("\\\\srv\\share\\")
68+
expect(snapshotProjectOf("C:\\p\\_workspace\\SKILL.md", w)).toBeNull()
69+
})
70+
6371
test("nested snapshots attribute to the outermost project", () => {
6472
expect(snapshotProjectOf(abs("p", SNAP, "q", SNAP, "a", "SKILL.md"))).toBe(P)
6573
})

0 commit comments

Comments
 (0)