Skip to content

Commit 411f32b

Browse files
test(workspace): pin that linking clears the memoized lookup miss
The existing test passes on the link's validation stamp alone, with or without `clearLookupMiss`. The new one expires the stamp first, so the next sync asks the server, and fails if the link leaves the miss memo in place. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_0174HUYiaceApqHP7EKMNgnb
1 parent b093196 commit 411f32b

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ const {
6969
snapshotWorkspaceId,
7070
} =
7171
await import("@/altimate/workspace/skill-sync")
72-
const { cachePath, recordApprovedBinding, credentialDigest } = await import("@/altimate/workspace/state")
72+
const { cachePath, recordApprovedBinding, credentialDigest, expireValidationForTests } = await import(
73+
"@/altimate/workspace/state"
74+
)
7375
const { Global } = await import("@/global")
7476
const FIXTURE_ACCOUNT = credentialDigest(API_URL, TENANT, ACCOUNT_KEY)
7577

@@ -2419,6 +2421,44 @@ describe("workspace skill sync", () => {
24192421
expect(existsSync(skillFile("pub-1", "SKILL.md"))).toBe(true)
24202422
})
24212423

2424+
test("linking just after an unbound turn clears the memoized miss", async () => {
2425+
// The test above passes on the link's validation stamp alone: inside the
2426+
// revalidation window the row is trusted without a lookup, so the memo is
2427+
// never read. With the stamp expired the next sync asks again, and only the
2428+
// link having cleared the memo stops that lookup from answering "unbound"
2429+
// from the miss recorded before the link and deleting the row.
2430+
rmSync(cachePath(), { force: true })
2431+
globalThis.fetch = (async (input: string | URL) => {
2432+
if (String(input).includes("/datamate-project-bindings/by-")) {
2433+
return new Response(JSON.stringify({ detail: "not found" }), { status: 404 })
2434+
}
2435+
return json({ items: [], total: 0, page: 1, size: 50, pages: 1 })
2436+
}) as unknown as typeof fetch
2437+
await syncSkills(project)
2438+
2439+
await recordApprovedBinding(project, {
2440+
datamateId: 1,
2441+
datamateName: "ws-1",
2442+
repoRemote: null,
2443+
projectPath: project,
2444+
linkedAt: Date.now(),
2445+
}, { awaitBackfill: true })
2446+
expireValidationForTests(project)
2447+
serveWithServerBinding({ "pub-1": { "SKILL.md": "one" } })
2448+
const inner = globalThis.fetch
2449+
let lookups = 0
2450+
globalThis.fetch = (async (input: string | URL, init?: RequestInit) => {
2451+
if (String(input).includes("/datamate-project-bindings/by-")) lookups++
2452+
return inner(input as never, init as never)
2453+
}) as unknown as typeof fetch
2454+
await syncSkills(project)
2455+
2456+
// The server was asked, so the row below survived a real revalidation.
2457+
expect(lookups).toBe(1)
2458+
expect(JSON.parse(readFileSync(cachePath(), "utf8")).bindings[realpathSync(project)]).toBeDefined()
2459+
expect(existsSync(skillFile("pub-1", "SKILL.md"))).toBe(true)
2460+
})
2461+
24222462
test("a cached binding survives a server that cannot be reached", async () => {
24232463
// Revalidation must not tear down a working setup over a network blip.
24242464
serve({ "pub-1": { "SKILL.md": "one" } })

0 commit comments

Comments
 (0)