card #223: update quc/test/runs.test.js
time/worker-run cd quc && node --test 2>&1 | tail -25
ci / test (pull_request) Successful in 44s
heartbeat / tick (pull_request_review) Successful in 12s

This commit is contained in:
time committed 2026-10-22 10:09:06 +00:00
1 parent 5b64e59b46
commit f1bd32d617
1 file changed
+51
+51
View File
@@ -0,0 +1,51 @@
import test from "node:test";
import assert from "node:assert/strict";
import { createRun, setStatus, addEvent, getRun, getEvents } from "../src/runs.js";
const mem = () => { const m = new Map(); return { get: async (k) => m.get(k) ?? null, put: async (k, v) => void m.set(k, v), delete: async (k) => void m.delete(k) }; };
const input = (visitor = "v1") => ({ repo: "https://github.com/a/b", task: "Fix the flaky date test", visitor });
const code = (p) => p.then(() => null, (e) => e.code);
test("a run walks queued -> running -> ended and persists in the store", async () => {
const s = mem();
const run = await createRun(s, input());
assert.equal(run.status, "queued");
assert.equal((await setStatus(s, run.id, "running")).status, "running");
const done = await setStatus(s, run.id, "ended", "finished");
assert.deepEqual([done.status, done.outcome], ["ended", "finished"]);
assert.ok(done.startedAt && done.endedAt);
assert.deepEqual(await getRun(s, run.id), done);
});
test("bad transitions, outcomes and inputs are refused", async () => {
const s = mem();
const { id } = await createRun(s, input());
assert.equal(await code(setStatus(s, id, "ended")), "outcome");
assert.equal(await code(setStatus(s, id, "queued")), "transition");
await setStatus(s, id, "ended", "safeworded");
assert.equal(await code(setStatus(s, id, "running")), "transition");
assert.equal(await code(setStatus(s, "nope", "running")), "not_found");
assert.equal(await code(createRun(s, { ...input(), repo: "x" })), "invalid");
assert.equal(await code(createRun(s, input(""))), "visitor");
});
test("one active run per visitor; ending frees the slot; other visitors are unaffected", async () => {
const s = mem();
const a = await createRun(s, input("v1"));
assert.equal(await code(createRun(s, input("v1"))), "active");
await setStatus(s, a.id, "running");
assert.equal(await code(createRun(s, input("v1"))), "active");
await createRun(s, input("v2"));
await setStatus(s, a.id, "ended", "unlocked");
await createRun(s, input("v1"));
});
test("events append in order and unknown kinds are refused", async () => {
const s = mem();
const { id } = await createRun(s, input());
await addEvent(s, id, "commentary", "reading the tests");
await addEvent(s, id, "diff", "--- a\n+++ b");
assert.deepEqual((await getEvents(s, id)).map((e) => [e.seq, e.kind]), [[1, "commentary"], [2, "diff"]]);
assert.equal(await code(addEvent(s, id, "nope", "")), "kind");
assert.equal(await code(addEvent(s, "nope", "commit", "")), "not_found");
});