@@ -22,6 +22,7 @@ const { resolvePinnedBindingForRouting, recordApprovedBinding, __resetPinValidat
2222const { refresh, precedenceInternals } = await import ( "../../../src/altimate/workspace/precedence" )
2323const { Instance } = await import ( "../../../src/project/instance" )
2424const { SNOWFLAKE_TOOLS } = await import ( "./precedence-fixture" )
25+ const { stubEmptySkillList } = await import ( "./skill-list-fixture" )
2526const { AltimateApi } = await import ( "../../../src/altimate/api/client" )
2627const { WorkspaceApi } = await import ( "../../../src/altimate/workspace/api-client" )
2728
@@ -39,27 +40,6 @@ function stubCreds() {
3940 ( { altimateInstanceName : "acme" , altimateUrl : "https://api.test" , altimateApiKey : "k" } ) as Creds
4041}
4142
42- const originalFetch = globalThis . fetch
43-
44- /** Seeding a link runs a skill sync (awaited, see `seedLocalLink`) that lists the workspace's
45- * skills from `api.test`. Answered here with an empty page, so that sync finishes offline instead
46- * of waiting on however long a resolver takes to fail a name that cannot exist. */
47- function stubFetch ( ) {
48- globalThis . fetch = ( async ( input : string | URL , init ?: RequestInit ) => {
49- const url = new URL ( String ( input ) )
50- if ( url . host !== "api.test" ) return originalFetch ( input , init )
51- const skills = url . pathname . endsWith ( "/skills" )
52- // The page is echoed back: the skill-list parser rejects a page that does not match its request.
53- const body = skills
54- ? { items : [ ] , page : Number ( url . searchParams . get ( "page" ) ?? "1" ) , pages : 1 , total : 0 }
55- : { detail : "not found" }
56- return new Response ( JSON . stringify ( body ) , {
57- status : skills ? 200 : 404 ,
58- headers : { "content-type" : "application/json" } ,
59- } )
60- } ) as typeof fetch
61- }
62-
6343let listCalls = 0
6444
6545function stubList ( rows : { id : number ; name : string } [ ] ) {
@@ -118,6 +98,7 @@ async function seedLocalLink(datamateId = 7, datamateName = "project-link") {
11898}
11999
120100const ORIGINAL_PILOT = process . env . ALTIMATE_WORKSPACE
101+ let restoreFetch = ( ) => { }
121102
122103beforeEach ( ( ) => {
123104 // `derive` short-circuits on `pilot-off` before it ever reads a binding.
@@ -126,7 +107,8 @@ beforeEach(() => {
126107 listCalls = 0
127108 __resetPinValidation ( )
128109 stubCreds ( )
129- stubFetch ( )
110+ // Seeding a link awaits its skill sync (`seedLocalLink`); answered offline, per test.
111+ restoreFetch = stubEmptySkillList ( "api.test" )
130112 stubList ( [
131113 { id : 42 , name : "pinned-workspace" } ,
132114 { id : 7 , name : "project-link" } ,
@@ -135,6 +117,7 @@ beforeEach(() => {
135117} )
136118
137119afterEach ( ( ) => {
120+ restoreFetch ( )
138121 clearPin ( )
139122 delete process . env . ALTIMATE_INTEGRATIONS
140123 // Restored per test, not only in `afterAll`: `beforeEach` sets it unconditionally, so leaving
@@ -155,7 +138,6 @@ afterAll(() => {
155138 ; ( AltimateApi as unknown as { isConfigured : unknown } ) . isConfigured = originalIsConfigured
156139 ; ( AltimateApi as unknown as { getCredentials : unknown } ) . getCredentials = originalGetCreds
157140 ; ( WorkspaceApi as unknown as { listDatamates : unknown } ) . listDatamates = originalList
158- globalThis . fetch = originalFetch
159141 if ( ORIGINAL_XDG_STATE_HOME === undefined ) delete process . env . XDG_STATE_HOME
160142 else process . env . XDG_STATE_HOME = ORIGINAL_XDG_STATE_HOME
161143 rmSync ( SANDBOX , { recursive : true , force : true } )
0 commit comments