feat: queue countdown, hold on stop, reply when blocked

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 11:22:30 +01:00
1 parent 0558449439
commit 7ec35215c6
9 files changed
+361 -44

No files matched your search

+52
View File
@@ -139,3 +139,55 @@ test("hold_queue holds queued and sending, keeps uncertain", () => {
const s = reduce(reduce(createState(), q3()), { type: "hold_queue", agent: "t2" });
assert.deepEqual(s.queue.t2.map((i) => i.state), ["held", "held", "uncertain"]);
});
const mk = (...items) => reduce(createState(), { type: "restore", agent: "a", items });
const it = (id, state, extra = {}) => ({ id, text: id, state, createdAt: 1, ...extra });
const states = (s) => s.queue.a.map((i) => i.state);
test("countdown_start starts the first queued entry, uncertain untouched", () => {
let s = mk(it("u", "uncertain"), it("q1", "queued"), it("q2", "queued"));
s = reduce(s, { type: "countdown_start", agent: "a", id: "q1" });
assert.deepEqual(states(s), ["uncertain", "countdown", "queued"]);
assert.equal(s.queue.a[1].left, 3);
});
test("countdown_start ignores a non-first queued entry and a busy queue", () => {
const s = mk(it("q1", "queued"), it("q2", "queued"));
assert.equal(reduce(s, { type: "countdown_start", agent: "a", id: "q2" }), s);
const c = reduce(s, { type: "countdown_start", agent: "a", id: "q1" });
assert.equal(reduce(c, { type: "countdown_start", agent: "a", id: "q2" }), c);
const w = mk(it("s", "sending"), it("q", "queued"));
assert.equal(reduce(w, { type: "countdown_start", agent: "a", id: "q" }), w);
});
test("countdown_tick decrements and stops at 0", () => {
let s = reduce(mk(it("q", "queued")), { type: "countdown_start", agent: "a", id: "q" });
for (let i = 0; i < 5; i++) s = reduce(s, { type: "countdown_tick", agent: "a", id: "q" });
assert.equal(s.queue.a[0].left, 0);
assert.equal(s.queue.a[0].state, "countdown");
});
test("countdown_cancel -> held, countdown_reset -> queued, both drop left", () => {
const c = reduce(mk(it("q", "queued")), { type: "countdown_start", agent: "a", id: "q" });
const h = reduce(c, { type: "countdown_cancel", agent: "a", id: "q" });
assert.deepEqual(h.queue.a[0], { id: "q", text: "q", state: "held", createdAt: 1 });
const r = reduce(c, { type: "countdown_reset", agent: "a", id: "q" });
assert.deepEqual(r.queue.a[0], { id: "q", text: "q", state: "queued", createdAt: 1 });
});
test("hold_all holds queued and countdown; sending and uncertain stay", () => {
const s = mk(it("a1", "queued"), it("c", "countdown", { left: 2 }), it("s", "sending"), it("u", "uncertain"), it("h", "held"));
const out = reduce(s, { type: "hold_all", agent: "a" });
assert.deepEqual(states(out), ["held", "held", "sending", "uncertain", "held"]);
assert.equal(out.queue.a[1].left, undefined);
});
test("claim takes a countdown entry", () => {
const s = reduce(mk(it("c", "countdown", { left: 0 })), { type: "claim", agent: "a", id: "c" });
assert.equal(s.queue.a[0].state, "sending");
});
test("restart turns a countdown into held", () => {
const s = reduce(mk(it("c", "countdown", { left: 2 })), { type: "restart", agent: "a" });
assert.deepEqual(states(s), ["held"]);
});