From c5e5db8b70273e5ed261a05e0f042f482aed76bd Mon Sep 17 00:00:00 2001 From: Mnigos Date: Fri, 9 Oct 2026 19:30:42 +0200 Subject: [PATCH] test(usage): v4 cache upgrade test waits for the migrated cache write The restarted service writes the migrated cache in the background, and that write could land while the test layer was removing the temp state directory, failing with ENOTEMPTY. The test now awaits the restarted service's pending write before the layer tears down. --- apps/server/src/usage/UsageService.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/server/src/usage/UsageService.test.ts b/apps/server/src/usage/UsageService.test.ts index 52e98f0eaf7d..4a532e583d56 100644 --- a/apps/server/src/usage/UsageService.test.ts +++ b/apps/server/src/usage/UsageService.test.ts @@ -1149,7 +1149,8 @@ describe("UsageService", () => { return text; }); - const summary = yield* (yield* UsageService.make).readSummary(WINDOW); + const restarted = yield* UsageService.make; + const summary = yield* restarted.readSummary(WINDOW); // The live rollout re-parses at the ultrafast rate (10 x 6); the // deleted one keeps its saved v4 usage at the standard rate (20 x 1). assert.strictEqual(totalOutputTokens(summary), 30); @@ -1162,6 +1163,9 @@ describe("UsageService", () => { yield* Effect.promise(() => NodeFSP.readFile(legacyPath, "utf8")), legacy, ); + // The migrated cache is written in the background; let it land before + // the layer removes the state directory under it. + yield* restarted.awaitPersisted; }).pipe( Effect.provide( layerService({