1- import { chmod , mkdir , mkdtemp , rm , symlink , writeFile } from 'node:fs/promises' ;
1+ import { chmod , mkdir , mkdtemp , realpath , rm , symlink , writeFile } from 'node:fs/promises' ;
22import { tmpdir } from 'node:os' ;
33import { join , sep } from 'node:path' ;
44
55import { IModelCatalog , IWorkspaceInstanceManager } from '@pymodel/agent-core-v2' ;
66import { HostFileSystem } from '@pymodel/agent-core-v2/os/backends/node-local/hostFsService' ;
77import { FakeRuntime } from '@pymodel/agent-core-v2/runtime/fakeRuntime' ;
88import { ErrorCode } from '../src/protocol/error-codes' ;
9- import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
9+ import { afterAll , afterEach , beforeAll , beforeEach , describe , expect , it , vi } from 'vitest' ;
1010
1111import { type RunningServer , startServer } from '../src/start' ;
1212import { TEST_HOST_IDENTITY } from './helpers/hostIdentity' ;
1313import { authHeaders } from './helpers/auth' ;
14+ import { fakeModelCatalog } from './helpers/fakeModelCatalog' ;
1415
1516interface Envelope < T > {
1617 code : number ;
@@ -36,45 +37,31 @@ describe('server-v2 /api/v1 fs routes', () => {
3637 let work : string | undefined ;
3738 let base : string ;
3839
39- beforeEach ( async ( ) => {
40+ beforeAll ( async ( ) => {
4041 home = await mkdtemp ( join ( tmpdir ( ) , 'pythinker-server-v2-fs-home-' ) ) ;
41- work = await mkdtemp ( join ( tmpdir ( ) , 'pythinker-server-v2-fs-work-' ) ) ;
42- const modelCatalog : IModelCatalog = {
43- _serviceBrand : undefined ,
44- get : ( ) => {
45- throw new Error ( 'modelCatalog.get not exercised in this test' ) ;
46- } ,
47- getRequester : ( ) => {
48- throw new Error ( 'modelCatalog.getRequester not exercised in this test' ) ;
49- } ,
50- inspect : ( ) => {
51- throw new Error ( 'modelCatalog.inspect not exercised in this test' ) ;
52- } ,
53- ping : ( ) => {
54- throw new Error ( 'modelCatalog.ping not exercised in this test' ) ;
55- } ,
56- findByName : ( ) => [ ] ,
57- listModels : async ( ) => [ ] ,
58- listProviders : async ( ) => [ ] ,
59- getProvider : async ( ) => {
60- throw new Error ( 'modelCatalog.getProvider not exercised in this test' ) ;
61- } ,
62- setDefaultModel : async ( ) => {
63- throw new Error ( 'modelCatalog.setDefaultModel not exercised in this test' ) ;
64- } ,
65- } ;
6642 server = await startServer ( {
6743 hostIdentity : TEST_HOST_IDENTITY ,
6844 host : '127.0.0.1' ,
6945 port : 0 ,
7046 homeDir : home ,
7147 logLevel : 'silent' ,
72- seeds : [ [ IModelCatalog , modelCatalog ] ] ,
48+ seeds : [ [ IModelCatalog , fakeModelCatalog ( ) ] ] ,
7349 } ) ;
7450 base = `http://127.0.0.1:${ server . port } ` ;
7551 } ) ;
7652
53+ beforeEach ( async ( ) => {
54+ work = await mkdtemp ( join ( tmpdir ( ) , 'pythinker-server-v2-fs-work-' ) ) ;
55+ } ) ;
56+
7757 afterEach ( async ( ) => {
58+ if ( work !== undefined ) {
59+ await rm ( work , { recursive : true , force : true , maxRetries : 5 , retryDelay : 50 } ) ;
60+ work = undefined ;
61+ }
62+ } ) ;
63+
64+ afterAll ( async ( ) => {
7865 if ( server !== undefined ) {
7966 await server . close ( ) ;
8067 server = undefined ;
@@ -83,10 +70,6 @@ describe('server-v2 /api/v1 fs routes', () => {
8370 await rm ( home , { recursive : true , force : true , maxRetries : 5 , retryDelay : 50 } ) ;
8471 home = undefined ;
8572 }
86- if ( work !== undefined ) {
87- await rm ( work , { recursive : true , force : true , maxRetries : 5 , retryDelay : 50 } ) ;
88- work = undefined ;
89- }
9073 } ) ;
9174
9275 async function createSession ( ) : Promise < string > {
@@ -701,15 +684,21 @@ describe('server-v2 /api/v1 fs routes', () => {
701684 expect ( body . code ) . toBe ( 0 ) ;
702685 expect ( body . data . items . map ( ( i ) => i . path ) ) . toContain ( 'kappa.ts' ) ;
703686
704- expect ( await listWorkspaces ( ) ) . toEqual ( [ ] ) ;
705- expect ( server ! . core . accessor . get ( IWorkspaceInstanceManager ) . list ( ) ) . toEqual ( [ ] ) ;
687+ const workAliases = new Set ( [ work ! , await realpath ( work ! ) ] ) ;
688+ expect ( ( await listWorkspaces ( ) ) . some ( ( w ) => workAliases . has ( w . root ) ) ) . toBe ( false ) ;
689+ expect (
690+ server ! . core . accessor
691+ . get ( IWorkspaceInstanceManager )
692+ . list ( )
693+ . some ( ( w ) => workAliases . has ( w . root ) ) ,
694+ ) . toBe ( false ) ;
706695
707696 const again = await postRootSuggest < { items : SuggestItemWire [ ] } > ( {
708697 roots : [ work ] ,
709698 query : 'kappa' ,
710699 } ) ;
711700 expect ( again . code ) . toBe ( 0 ) ;
712- expect ( await listWorkspaces ( ) ) . toEqual ( [ ] ) ;
701+ expect ( ( await listWorkspaces ( ) ) . some ( ( w ) => workAliases . has ( w . root ) ) ) . toBe ( false ) ;
713702 } ) ;
714703
715704 it ( 'fs:suggest matches the workspace route for the same single root' , async ( ) => {
0 commit comments