Skip to content

Commit a727489

Browse files
sahrizviclaude
andauthored
fix(workspace): count an IDE pin and this client's manifest as binding evidence (#1376)
#1374 stays quiet when a binding lookup fails for a project with no sign of a workspace. Two cases slipped through that check: - An IDE pin (`ALTIMATE_PINNED_WORKSPACE_*`) is a workspace the user chose, but it is never written to disk. An inaccessible pinned workspace, or an offline first validation, was silent — including in the IDE's Refresh report. A pin for this tree now counts, and so does a malformed one: the extension set it, and resolution fails closed on it. - Any `_workspace` folder counted, including one the user or another tool created. Only this client's manifest does now. Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 960b936 commit a727489

2 files changed

Lines changed: 99 additions & 6 deletions

File tree

‎packages/opencode/src/altimate/workspace/skill-sync.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,22 @@ async function hasManagedSnapshot(directory: string): Promise<boolean> {
772772
}
773773
}
774774

775-
/** Whether local state says this project has a workspace: a snapshot a sync
776-
* once published, or a cached binding. Decides if a failed binding lookup is
777-
* worth telling the user about. */
775+
/** Whether this project is known to have a workspace. Decides if a failed
776+
* binding lookup is worth telling the user about. */
778777
async function hasBindingEvidence(directory: string): Promise<boolean> {
779-
if (await hasManagedSnapshot(directory)) return true
778+
// The IDE's pin is a workspace the user chose for this tree, and it is never
779+
// written to disk — an inaccessible pinned workspace would otherwise be
780+
// silent. A malformed pin counts as well: the extension set one, and
781+
// resolution fails closed on it for every directory. Scoped with the same
782+
// `resolveWithinRoot` as the pin purge in `syncSkills`, so the purge and the
783+
// warning always agree on which folders a pin speaks for — and the warning
784+
// still fires after that purge has removed the manifest.
785+
const pin = readPin()
786+
if (pin.kind === "invalid") return true
787+
if (pin.kind === "valid" && resolveWithinRoot(directory, pin.root) !== null) return true
788+
// This client's manifest, not merely a `_workspace` folder: a tree the user
789+
// or another tool created says nothing about a binding.
790+
if ((await readManifest(directory).catch(() => null)) !== null) return true
780791
return (await readLocalBinding(directory).catch(() => null)) !== null
781792
}
782793

@@ -930,8 +941,9 @@ export async function syncSkills(directory: string): Promise<SyncResult> {
930941
// workspace. With a local binding row, offline resolves to a stale "bound"
931942
// and fails later at the list; without one, the server is always asked,
932943
// so offline lands here for EVERY opted-in project, including ones never
933-
// linked. A snapshot on disk (a server-side binding that synced before)
934-
// or a local row is that evidence; without either, stay quiet.
944+
// linked. An IDE pin for this tree, this client's manifest (a server-side
945+
// binding that synced before) or a local row is that evidence — see
946+
// `hasBindingEvidence`; without any of them, stay quiet.
935947
if (outcome.status === "unknown" && (await hasBindingEvidence(canon)))
936948
syncError = "could not confirm this project's workspace (offline, or no access to it)"
937949
return

‎packages/opencode/test/altimate/workspace/skill-sync.test.ts‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,87 @@ describe("workspace skill sync", () => {
388388
expect(result.skipped).toEqual([])
389389
})
390390

391+
// What counts as "this project has a workspace" when the lookup fails.
392+
const offline = () => {
393+
globalThis.fetch = (async () => {
394+
throw new Error("offline")
395+
}) as unknown as typeof fetch
396+
}
397+
const PIN_KEYS = [
398+
"ALTIMATE_CODE_SERVE",
399+
"ALTIMATE_PINNED_WORKSPACE_ID",
400+
"ALTIMATE_PINNED_WORKSPACE_NAME",
401+
"ALTIMATE_PINNED_WORKSPACE_ROOT",
402+
] as const
403+
async function withEnv<T>(env: Partial<Record<(typeof PIN_KEYS)[number], string>>, fn: () => Promise<T>) {
404+
const saved = Object.fromEntries(PIN_KEYS.map((k) => [k, process.env[k]]))
405+
for (const k of PIN_KEYS) delete process.env[k]
406+
Object.assign(process.env, env)
407+
try {
408+
return await fn()
409+
} finally {
410+
for (const k of PIN_KEYS) {
411+
if (saved[k] === undefined) delete process.env[k]
412+
else process.env[k] = saved[k]
413+
}
414+
}
415+
}
416+
417+
test("a _workspace folder this client did not write is not evidence of a workspace", async () => {
418+
mkdirSync(path.join(project, MANAGED), { recursive: true })
419+
writeFileSync(path.join(project, MANAGED, "mine.md"), "the user's own file")
420+
unbind()
421+
offline()
422+
const result = await syncSkills(project)
423+
expect(result.error).toBeUndefined()
424+
})
425+
426+
test("an IDE pin for this project is evidence, so an unconfirmable pinned workspace is reported", async () => {
427+
unbind()
428+
offline()
429+
const result = await withEnv(
430+
{
431+
ALTIMATE_CODE_SERVE: "1",
432+
ALTIMATE_PINNED_WORKSPACE_ID: "4242",
433+
ALTIMATE_PINNED_WORKSPACE_NAME: "pinned",
434+
ALTIMATE_PINNED_WORKSPACE_ROOT: project,
435+
},
436+
() => syncSkills(project),
437+
)
438+
expect(result.error).toBe("could not confirm this project's workspace (offline, or no access to it)")
439+
})
440+
441+
test("an unhonourable pin removes the skills AND says why", async () => {
442+
// The pin purge removes the manifest before the evidence check runs; the
443+
// pin itself must still count, or the purge would be silent.
444+
serve({ "pub-1": { "SKILL.md": "one" } })
445+
await syncSkills(project)
446+
expect(existsSync(skillFile("pub-1", "SKILL.md"))).toBe(true)
447+
448+
unbind()
449+
offline()
450+
const result = await withEnv(
451+
{
452+
ALTIMATE_CODE_SERVE: "1",
453+
ALTIMATE_PINNED_WORKSPACE_ID: "4243",
454+
ALTIMATE_PINNED_WORKSPACE_NAME: "pinned",
455+
ALTIMATE_PINNED_WORKSPACE_ROOT: project,
456+
},
457+
() => syncSkills(project),
458+
)
459+
expect(existsSync(skillFile("pub-1", "SKILL.md"))).toBe(false)
460+
expect(result.error).toBe("could not confirm this project's workspace (offline, or no access to it)")
461+
})
462+
463+
test("a malformed pin is evidence too: the extension set one", async () => {
464+
unbind()
465+
offline()
466+
const result = await withEnv({ ALTIMATE_CODE_SERVE: "1", ALTIMATE_PINNED_WORKSPACE_ID: "4242" }, () =>
467+
syncSkills(project),
468+
)
469+
expect(result.error).toBe("could not confirm this project's workspace (offline, or no access to it)")
470+
})
471+
391472
test("an unusable remote id is shown sanitised and bounded, never raw", async () => {
392473
const esc = String.fromCharCode(27)
393474
const raw = `../evil${esc}[31m${String.fromCharCode(10)}${String.fromCharCode(0x2028)}${"x".repeat(100)}`

0 commit comments

Comments
 (0)