@@ -68,6 +68,44 @@ describe('server-v2 /api/v1/workspaces', () => {
6868 delete process . env [ 'PYTHINKER_CODE_WATCH' ] ;
6969 } ) ;
7070
71+ async function restartWithFreshHome ( ) : Promise < void > {
72+ if ( server !== undefined ) {
73+ await server . close ( ) ;
74+ server = undefined ;
75+ }
76+ if ( home !== undefined ) {
77+ await new Promise ( ( resolve ) => setTimeout ( resolve , 25 ) ) ;
78+ await rm ( home , { recursive : true , force : true , maxRetries : 5 , retryDelay : 50 } as never ) ;
79+ }
80+ home = await mkdtemp ( join ( tmpdir ( ) , 'pythinker-server-v2-workspaces-' ) ) ;
81+ process . env [ 'PYTHINKER_CODE_WATCH' ] = '1' ;
82+ server = await startServer ( {
83+ hostIdentity : TEST_HOST_IDENTITY ,
84+ host : '127.0.0.1' ,
85+ port : 0 ,
86+ homeDir : home ,
87+ logLevel : 'silent' ,
88+ } ) ;
89+ base = `http://127.0.0.1:${ server . port } ` ;
90+ }
91+
92+ async function restartSameHome ( ) : Promise < void > {
93+ if ( server !== undefined ) {
94+ await server . close ( ) ;
95+ server = undefined ;
96+ }
97+ process . env [ 'PYTHINKER_CODE_WATCH' ] = '1' ;
98+ server = await startServer ( {
99+ hostIdentity : TEST_HOST_IDENTITY ,
100+ host : '127.0.0.1' ,
101+ port : 0 ,
102+ homeDir : home as string ,
103+ logLevel : 'silent' ,
104+ } ) ;
105+ base = `http://127.0.0.1:${ server . port } ` ;
106+ }
107+
108+
71109 async function postJson < T > (
72110 path : string ,
73111 body ?: unknown ,
@@ -206,6 +244,7 @@ describe('server-v2 /api/v1/workspaces', () => {
206244 } ) ;
207245
208246 it ( 'sums session_count across legacy split buckets of one root' , async ( ) => {
247+ await restartWithFreshHome ( ) ;
209248 const typedRoot = 'C:\\Users\\Foo\\Proj' ;
210249 const lowerRoot = 'c:\\users\\foo\\proj' ;
211250 const typedId = encodeWorkDirKey ( typedRoot ) ;
@@ -246,14 +285,18 @@ describe('server-v2 /api/v1/workspaces', () => {
246285 } ;
247286 await seedBucket ( typedId , 's-typed' , { } ) ;
248287 await seedBucket ( lowerId , 's-lower' , { archived : true , updatedAt : 2 } ) ;
249-
250- await vi . waitFor ( async ( ) => {
251- const { body } = await getJson < ListWire > ( '/api/v1/workspaces' ) ;
252- expect ( body . code ) . toBe ( 0 ) ;
253- const unions = body . data . items . filter ( ( w ) => [ typedId , lowerId ] . includes ( w . id ) ) ;
254- expect ( unions ) . toHaveLength ( 1 ) ;
255- expect ( unions [ 0 ] ?. session_count ) . toBe ( 2 ) ;
256- } ) ;
288+ await restartSameHome ( ) ;
289+
290+ await vi . waitFor (
291+ async ( ) => {
292+ const { body } = await getJson < ListWire > ( '/api/v1/workspaces' ) ;
293+ expect ( body . code ) . toBe ( 0 ) ;
294+ const unions = body . data . items . filter ( ( w ) => [ typedId , lowerId ] . includes ( w . id ) ) ;
295+ expect ( unions ) . toHaveLength ( 1 ) ;
296+ expect ( unions [ 0 ] ?. session_count ) . toBe ( 2 ) ;
297+ } ,
298+ { timeout : 10_000 } ,
299+ ) ;
257300 } ) ;
258301
259302 it ( 'adds an additional directory and persists it by default' , async ( ) => {
0 commit comments