1// @effect-diagnostics nodeBuiltinImport:off - memory assertions run in an isolated Node process with explicit GC.
2import * as NodeChildProcess from "node:child_process";
3import * as NodeURL from "node:url";
4import * as NodeUtil from "node:util";
5import { expect, it } from "vite-plus/test";
6
7const execFile = NodeUtil.promisify(NodeChildProcess.execFile);
8
9it.each(["regular", "handoff", "handoff-compact", "handoff-failure"])(
10 "releases startup history while %s run workers remain alive",
11 async (mode) => {
12 const root = NodeURL.fileURLToPath(new URL("../../../../", import.meta.url));
13 const fixture = NodeURL.fileURLToPath(
14 new URL("./testkit/ProviderTurnStartMemory.fixture.mjs", import.meta.url),
15 );
16 const { stdout } = await execFile(process.execPath, ["--expose-gc", fixture, root, mode]);
17 const result = JSON.parse(stdout) as {
18 checkpoints: ReadonlyArray<{ runs: number; retained: number }>;
19 };
20 expect(result.checkpoints.map(({ runs, retained }) => ({ runs, retained }))).toEqual([
21 { runs: 2, retained: 0 },
22 { runs: 4, retained: 0 },
23 ]);
24 },
25);