authorgravatar for admin@snappeh.comTristan Knight <admin@snappeh.com> 2026-10-10 03:09:23+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-10-09 19:09:23-07:00
loge858ddb65668d54be5de3996f30c0bd5c3149657
tree871fe24f7b2e16c3806d677309ffdf31cf6c9497
parent0caa95d6eb471ab033ea670914d61070c65be806
signature Signed by PGP key B5690EEEBB952194

test(usage): usage service tests keep their state directory until cache writes land (#17636)


1 files changed, 4 insertions(+), 6 deletions(-)

apps/server/src/usage/UsageService.test.ts+4-6
...@@ -132,7 +132,9 @@ const layerService = (input: {...@@ -132,7 +132,9 @@ const layerService = (input: {
132 Layer.provideMerge(ProviderHostLive.layer),132 Layer.provideMerge(ProviderHostLive.layer),
133 Layer.provideMerge(Layer.mock(BackgroundPolicy.BackgroundPolicy)({})),133 Layer.provideMerge(Layer.mock(BackgroundPolicy.BackgroundPolicy)({})),
134 Layer.provideMerge(Layer.mock(ServerSecretStore.ServerSecretStore)({})),134 Layer.provideMerge(Layer.mock(ServerSecretStore.ServerSecretStore)({})),
135 Layer.provideMerge(ServerConfig.layerTest(process.cwd(), { prefix: input.prefix })),135 Layer.provideMerge(
136 ServerConfig.layerTest(process.cwd(), NodePath.join(input.home, input.prefix)),
137 ),
136 Layer.provideMerge(NodeServices.layer),138 Layer.provideMerge(NodeServices.layer),
137 Layer.provideMerge(Layer.succeed(HostProcess.Platform, input.platform ?? "linux")),139 Layer.provideMerge(Layer.succeed(HostProcess.Platform, input.platform ?? "linux")),
138 Layer.provideMerge(ServerSettings.layerTest(input.settings)),140 Layer.provideMerge(ServerSettings.layerTest(input.settings)),
...@@ -1203,8 +1205,7 @@ describe("UsageService", () => {...@@ -1203,8 +1205,7 @@ describe("UsageService", () => {
1203 return text;1205 return text;
1204 });1206 });
12051207
1206 const restarted = yield* UsageService.make;1208 const summary = yield* (yield* UsageService.make).readSummary(WINDOW);
1207 const summary = yield* restarted.readSummary(WINDOW);
1208 // The live rollout re-parses at the ultrafast rate (10 x 6); the1209 // The live rollout re-parses at the ultrafast rate (10 x 6); the
1209 // deleted one keeps its saved v4 usage at the standard rate (20 x 1).1210 // deleted one keeps its saved v4 usage at the standard rate (20 x 1).
1210 assert.strictEqual(totalOutputTokens(summary), 30);1211 assert.strictEqual(totalOutputTokens(summary), 30);
...@@ -1217,9 +1218,6 @@ describe("UsageService", () => {...@@ -1217,9 +1218,6 @@ describe("UsageService", () => {
1217 yield* Effect.promise(() => NodeFSP.readFile(legacyPath, "utf8")),1218 yield* Effect.promise(() => NodeFSP.readFile(legacyPath, "utf8")),
1218 legacy,1219 legacy,
1219 );1220 );
1220 // The migrated cache is written in the background; let it land before
1221 // the layer removes the state directory under it.
1222 yield* restarted.awaitPersisted;
1223 }).pipe(1221 }).pipe(
1224 Effect.provide(1222 Effect.provide(
1225 layerService({1223 layerService({