Skip to content

Commit a87dd0b

Browse files
fix: require fully qualified folder paths on Windows (codex r4)
isAbsolute("\repo") is true on win32, but resolve() completes a drive-relative path with the process's current drive — a corrupt sidecar entry could match any cwd on that drive and defeat the two-bridge decline. Folders now require a drive-qualified or UNC prefix on Windows; POSIX keeps plain isAbsolute. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MaT4GH2aCGEmTg6bBPZBeU
1 parent 179e433 commit a87dd0b

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎packages/opencode/src/altimate/workspace/engine-probes.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,12 @@ export function liveBridge(cwd: string, dir: string = join(homedir(), ".altimate
196196
continue
197197
// Validate the folders shape: this is an unvalidated JSON file, and a
198198
// non-array must degrade to "live bridge, no recorded folders", not
199-
// throw out of the probe. Only nonempty absolute strings survive —
200-
// resolve("") is the process cwd, so an empty or relative entry would
201-
// spuriously match and bypass the two-bridge decline. (codex r3)
199+
// throw out of the probe. Only fully qualified strings survive —
200+
// anything resolve() would complete from the process's own cwd or
201+
// drive could spuriously match and bypass the two-bridge decline.
202+
// (codex r3+r4)
202203
const folders = Array.isArray(data.workspaceFolders)
203-
? data.workspaceFolders.filter((f): f is string => typeof f === "string" && isAbsolute(f))
204+
? data.workspaceFolders.filter((f): f is string => typeof f === "string" && qualifiedFolder(f))
204205
: []
205206
bridges.push(folders)
206207
} catch {
@@ -221,6 +222,17 @@ export function liveBridge(cwd: string, dir: string = join(homedir(), ".altimate
221222
return bridges.length === 1
222223
}
223224

225+
/** A recorded folder must be fully qualified. On Windows, drive-relative
226+
* paths like "\repo" count as absolute to Node, but resolve() completes them
227+
* with the process's CURRENT drive — so a corrupt entry could match any cwd
228+
* on that drive and defeat the two-bridge decline. Drive-qualified (C:\ or
229+
* C:/) or UNC (\\server\share) only; POSIX keeps plain isAbsolute. The
230+
* platform parameter exists for tests. (codex r4) */
231+
export function qualifiedFolder(f: string, win: boolean = process.platform === "win32"): boolean {
232+
if (!f) return false
233+
return win ? /^([a-zA-Z]:[\\/]|\\\\)/.test(f) : isAbsolute(f)
234+
}
235+
224236
function pidAlive(pid: number): boolean {
225237
try {
226238
process.kill(pid, 0)

‎packages/opencode/test/altimate/workspace/engine-probes.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { describe, expect, test } from "bun:test"
66
import { chmodSync, mkdtempSync, statSync, utimesSync, writeFileSync } from "node:fs"
77
import os from "node:os"
88
import path from "node:path"
9-
import { fingerprint, liveBridge, versionOf } from "../../../src/altimate/workspace/engine-probes"
9+
import { fingerprint, liveBridge, qualifiedFolder, versionOf } from "../../../src/altimate/workspace/engine-probes"
1010

1111
const posix = process.platform !== "win32"
1212

@@ -111,6 +111,21 @@ describe("liveBridge", () => {
111111
}
112112
})
113113

114+
test("a recorded folder must be fully qualified on Windows — drive-relative resolves onto the current drive", () => {
115+
// win branch
116+
expect(qualifiedFolder("C:\\ws", true)).toBe(true)
117+
expect(qualifiedFolder("c:/ws", true)).toBe(true)
118+
expect(qualifiedFolder("\\\\server\\share\\ws", true)).toBe(true)
119+
expect(qualifiedFolder("\\repo", true)).toBe(false)
120+
expect(qualifiedFolder("\\", true)).toBe(false)
121+
expect(qualifiedFolder("C:relative", true)).toBe(false)
122+
expect(qualifiedFolder("", true)).toBe(false)
123+
// posix branch
124+
expect(qualifiedFolder("/home/ws", false)).toBe(true)
125+
expect(qualifiedFolder("relative/dir", false)).toBe(false)
126+
expect(qualifiedFolder("", false)).toBe(false)
127+
})
128+
114129
test("empty and relative folder strings are dropped — resolve('') is the process cwd", () => {
115130
const cwd = mkdtempSync(path.join(os.tmpdir(), "bridge-ws-"))
116131
// Bridge A is malformed, bridge B is live elsewhere: A must not match via

0 commit comments

Comments
 (0)