@@ -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+ )
7375const { Global } = await import ( "@/global" )
7476const 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