@@ -77,36 +77,54 @@ describe("HTTP shutdown wiring", () => {
7777 }
7878 } ) ;
7979
80- it ( "registers HTTP server cleanup before final DB cleanup " , ( ) => {
80+ it ( "stops HTTP producers before draining work and persisting usage " , ( ) => {
8181 const source = readFileSync (
8282 join ( process . cwd ( ) , "src" , "cli" , "commands" , "serve.ts" ) ,
8383 "utf8" ,
8484 ) ;
85- const httpCleanupIndex = source . indexOf (
85+ const serveSource = source . slice (
86+ source . indexOf ( "export async function serveCommand" ) ,
87+ ) ;
88+ const httpCleanupIndex = serveSource . indexOf (
8689 'shutdownMgr.addCleanup("httpServer"' ,
8790 ) ;
88- const persistUsageIndex = source . indexOf (
91+ const earlyPersistUsageIndex = serveSource . indexOf (
8992 'shutdownMgr.addCleanup("persistUsage"' ,
9093 ) ;
91- const dbCleanupIndex = source . lastIndexOf (
94+ const watcherCleanupIndex = serveSource . indexOf (
95+ 'shutdownMgr.addCleanup("watchers"' ,
96+ ) ;
97+ const verifierCleanupIndex = serveSource . indexOf (
98+ 'shutdownMgr.addCleanup("graphIntegrityVerifier"' ,
99+ ) ;
100+ const finalCleanupIndex = serveSource . indexOf (
92101 "registerServeFinalCleanups(shutdownMgr" ,
93102 ) ;
94- const loggerCleanupIndex = source . indexOf (
103+ const loggerCleanupIndex = serveSource . indexOf (
95104 'shutdownMgr.addCleanup("logger"' ,
96105 ) ;
97106
98107 assert . ok ( httpCleanupIndex >= 0 , "HTTP cleanup should be registered" ) ;
99- assert . ok (
100- persistUsageIndex >= 0 ,
101- "usage persistence cleanup should be registered" ,
108+ assert . equal (
109+ earlyPersistUsageIndex ,
110+ - 1 ,
111+ "usage persistence must not run before producer shutdown and work drain" ,
102112 ) ;
103- assert . ok ( dbCleanupIndex >= 0 , "DB cleanup should be registered" ) ;
113+ assert . ok ( watcherCleanupIndex >= 0 , "watcher cleanup should be registered" ) ;
114+ assert . ok ( verifierCleanupIndex >= 0 , "verifier cleanup should be registered" ) ;
115+ assert . ok ( finalCleanupIndex >= 0 , "final cleanup should be registered" ) ;
104116 assert . ok ( loggerCleanupIndex >= 0 , "logger cleanup should be registered" ) ;
105117 assert . ok (
106- httpCleanupIndex < persistUsageIndex &&
107- persistUsageIndex < dbCleanupIndex &&
108- dbCleanupIndex < loggerCleanupIndex ,
109- "HTTP transport cleanup must run before usage persistence and final DB/logger cleanup" ,
118+ httpCleanupIndex < watcherCleanupIndex &&
119+ watcherCleanupIndex < verifierCleanupIndex &&
120+ verifierCleanupIndex < finalCleanupIndex &&
121+ finalCleanupIndex < loggerCleanupIndex ,
122+ "HTTP transport and producers must stop before final drain/usage/DB cleanup" ,
123+ ) ;
124+ assert . match (
125+ serveSource ,
126+ / r e g i s t e r S e r v e F i n a l C l e a n u p s \( s h u t d o w n M g r , \s * \{ [ \s \S ] * ?p e r s i s t U s a g e : \s * a s y n c \s * \( \) \s * = > / ,
127+ "serve cleanup must persist usage through the post-drain final cleanup path" ,
110128 ) ;
111129 } ) ;
112130
0 commit comments