feat(background): add background registry and status tool with tests
This commit is contained in:
42
src/background-registry.test.ts
Normal file
42
src/background-registry.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createBackgroundRegistry } from "./background-registry.ts";
|
||||
|
||||
test("recordLaunch and counts update correctly", () => {
|
||||
const reg = createBackgroundRegistry();
|
||||
reg.recordLaunch({ runId: "r1", preset: "p1", task: "t1" });
|
||||
reg.recordLaunch({ runId: "r2", preset: "p2", task: "t2" });
|
||||
|
||||
let counts = reg.getCounts();
|
||||
assert.equal(counts.running, 2);
|
||||
assert.equal(counts.total, 2);
|
||||
|
||||
reg.recordUpdate("r2", { status: "completed", exitCode: 0, finalText: "done" });
|
||||
counts = reg.getCounts();
|
||||
assert.equal(counts.running, 1);
|
||||
assert.equal(counts.completed, 1);
|
||||
assert.equal(counts.total, 2);
|
||||
|
||||
const r1 = reg.getRun("r1");
|
||||
const r2 = reg.getRun("r2");
|
||||
assert.ok(r1);
|
||||
assert.ok(r2);
|
||||
assert.equal(r2?.finalText, "done");
|
||||
});
|
||||
|
||||
test("replay seeds registry and counts", () => {
|
||||
const reg = createBackgroundRegistry();
|
||||
const now = Date.now();
|
||||
reg.replay([
|
||||
{ runId: "a", preset: "p", task: "x", status: "running", startTime: now },
|
||||
{ runId: "b", preset: "p2", task: "y", status: "failed", startTime: now - 1000, endTime: now - 500 },
|
||||
]);
|
||||
|
||||
const counts = reg.getCounts();
|
||||
assert.equal(counts.running, 1);
|
||||
assert.equal(counts.failed, 1);
|
||||
assert.equal(counts.total, 2);
|
||||
|
||||
const snap = reg.getSnapshot({ includeCompleted: true });
|
||||
assert.equal(snap.length, 2);
|
||||
});
|
||||
Reference in New Issue
Block a user