@@ -298,59 +298,61 @@ describe("memory-wiki plugin", () => {
298298 await expect ( loadMemoryWikiCompiledCache ( config ) ) . resolves . toBeNull ( ) ;
299299 } ) ;
300300
301- it ( "closes queued dashboard source sync before it can activate a vault" , async ( ) => {
302- const rootDir = await createTempDir ( "memory-wiki-index-stop-sync-" ) ;
303- const { api, registerGatewayMethod, registerService } = createPluginApi ( ) ;
304- api . pluginConfig = { vault : { path : rootDir } } ;
305- plugin . register ( api ) ;
306- const config = resolveMemoryWikiConfig ( api . pluginConfig ) ;
307- const service = registerService . mock . calls [ 0 ] ?. [ 0 ] ;
308- await service ?. start ?.( ) ;
301+ it . each ( [ "wiki.importInsights" , "wiki.compile" ] ) (
302+ "closes queued %s source sync before it can activate a vault" ,
303+ async ( method ) => {
304+ const rootDir = await createTempDir ( "memory-wiki-index-stop-sync-" ) ;
305+ const { api, registerGatewayMethod, registerService } = createPluginApi ( ) ;
306+ api . pluginConfig = { vault : { path : rootDir } } ;
307+ plugin . register ( api ) ;
308+ const config = resolveMemoryWikiConfig ( api . pluginConfig ) ;
309+ const service = registerService . mock . calls [ 0 ] ?. [ 0 ] ;
310+ await service ?. start ?.( ) ;
309311
310- const mutationEntered = deferred ( ) ;
311- const releaseMutation = deferred ( ) ;
312- const mutation = withMemoryWikiVaultMutation ( rootDir , async ( ) => {
313- mutationEntered . resolve ( ) ;
314- await releaseMutation . promise ;
315- } ) ;
316- await mutationEntered . promise ;
317- const handler = registerGatewayMethod . mock . calls . find (
318- ( [ method ] ) => method === "wiki.importInsights" ,
319- ) ?. [ 1 ] ;
320- if ( ! handler ) {
321- throw new Error ( "Expected wiki.importInsights gateway handler" ) ;
322- }
323- await handler ( { params : { } , respond : vi . fn ( ) } ) ;
324- await vi . waitFor ( async ( ) => {
325- const drainState = await Promise . race ( [
326- waitForMemoryWikiImportedSourceSyncs ( ) . then ( ( ) => "settled" as const ) ,
327- new Promise < "pending" > ( ( resolve ) => {
328- setImmediate ( ( ) => resolve ( "pending" ) ) ;
329- } ) ,
330- ] ) ;
331- expect ( drainState ) . toBe ( "pending" ) ;
332- } ) ;
312+ const mutationEntered = deferred ( ) ;
313+ const releaseMutation = deferred ( ) ;
314+ const mutation = withMemoryWikiVaultMutation ( rootDir , async ( ) => {
315+ mutationEntered . resolve ( ) ;
316+ await releaseMutation . promise ;
317+ } ) ;
318+ await mutationEntered . promise ;
319+ const handler = registerGatewayMethod . mock . calls . find ( ( [ name ] ) => name === method ) ?. [ 1 ] ;
320+ if ( ! handler ) {
321+ throw new Error ( `Expected ${ method } gateway handler` ) ;
322+ }
323+ const request = handler ( { params : { } , respond : vi . fn ( ) } ) ;
324+ await vi . waitFor ( async ( ) => {
325+ const drainState = await Promise . race ( [
326+ waitForMemoryWikiImportedSourceSyncs ( ) . then ( ( ) => "settled" as const ) ,
327+ new Promise < "pending" > ( ( resolve ) => {
328+ setImmediate ( ( ) => resolve ( "pending" ) ) ;
329+ } ) ,
330+ ] ) ;
331+ expect ( drainState ) . toBe ( "pending" ) ;
332+ } ) ;
333333
334- const stop = service ?. stop ?.( ) ;
335- releaseMutation . resolve ( ) ;
336- await mutation ;
337- await stop ;
334+ const stop = service ?. stop ?.( ) ;
335+ releaseMutation . resolve ( ) ;
336+ await mutation ;
337+ await request ;
338+ await stop ;
338339
339- const snapshot = emptyCompiledSnapshot ( ) ;
340- await expect (
341- writeMemoryWikiCompiledCache (
342- config ,
343- snapshot ,
344- resolveMemoryWikiCompiledCacheGeneration ( snapshot ) ,
345- createMemoryWikiCompiledCachePublicationId ( ) ,
346- null ,
347- async ( ) => { } ,
348- async ( ) => { } ,
349- ( ) => loadMemoryWikiValidatedVaultIdentity ( rootDir ) ,
350- ) ,
351- ) . rejects . toThrow ( "vault is not active" ) ;
352- await expect ( loadMemoryWikiCompiledCache ( config ) ) . resolves . toBeNull ( ) ;
353- } ) ;
340+ const snapshot = emptyCompiledSnapshot ( ) ;
341+ await expect (
342+ writeMemoryWikiCompiledCache (
343+ config ,
344+ snapshot ,
345+ resolveMemoryWikiCompiledCacheGeneration ( snapshot ) ,
346+ createMemoryWikiCompiledCachePublicationId ( ) ,
347+ null ,
348+ async ( ) => { } ,
349+ async ( ) => { } ,
350+ ( ) => loadMemoryWikiValidatedVaultIdentity ( rootDir ) ,
351+ ) ,
352+ ) . rejects . toThrow ( "vault is not active" ) ;
353+ await expect ( loadMemoryWikiCompiledCache ( config ) ) . resolves . toBeNull ( ) ;
354+ } ,
355+ ) ;
354356
355357 it ( "clears active owners before a fallible lifecycle identity refresh" , async ( ) => {
356358 const rootDir = await createTempDir ( "memory-wiki-index-refresh-failure-" ) ;
0 commit comments