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

+38 -3
View File
@@ -1,15 +1,15 @@
import test from "node:test";
import assert from "node:assert/strict";
import { decide, gateAfter, onRestart } from "../mod/ovis-composer/delivery.js";
import { decide, gateAfter, onRestart, shouldDrain, drain } from "../mod/ovis-composer/delivery.js";
test("decide idle/done -> send", () => {
assert.equal(decide("idle").kind, "send");
assert.equal(decide("done").kind, "send");
});
test("decide working -> queue, blocked -> hold", () => {
test("decide working -> queue, blocked -> send (reply to the agent)", () => {
assert.equal(decide("working").kind, "queue");
assert.equal(decide("blocked").kind, "hold");
assert.equal(decide("blocked").kind, "send");
});
test("decide unknown status -> queue", () => {
@@ -35,3 +35,38 @@ test("onRestart sending -> uncertain, others untouched", () => {
test("onRestart tolerates non-array", () => {
assert.deepEqual(onRestart(null), []);
});
test("shouldDrain: only working|blocked -> idle|done, not after a stop by the composer", () => {
const all = ["idle", "working", "blocked", "done"];
for (const prev of all) {
for (const next of all) {
const want = (prev === "working" || prev === "blocked") && (next === "idle" || next === "done");
assert.equal(shouldDrain(prev, next, false), want, `${prev}->${next}`);
assert.equal(shouldDrain(prev, next, true), false, `${prev}->${next} stopped`);
}
}
});
test("onRestart: countdown -> held without left, sending -> uncertain", () => {
const out = onRestart([
{ id: "1", state: "countdown", left: 2 },
{ id: "2", state: "sending" },
]);
assert.deepEqual(out, [{ id: "1", state: "held" }, { id: "2", state: "uncertain" }]);
});
test("drain sends an entry whose countdown ran out", async () => {
const { createState, reduce } = await import("../mod/ovis-composer/state.js");
let s = reduce(createState(), { type: "queue", agent: "t2", item: { id: "1", text: "a", createdAt: 1 } });
s = reduce(s, { type: "countdown_start", agent: "t2", id: "1" });
const calls = [];
const ctx = { agent: "t2", terminal: "t2", status: () => "idle", gate: () => true,
hc: async (args) => (calls.push(args), { code: 0, stdout: "{}", stderr: "" }) };
let r = await drain(ctx, s);
assert.equal(r.sent, false); // left is still 3
for (let i = 0; i < 3; i++) s = reduce(s, { type: "countdown_tick", agent: "t2", id: "1" });
r = await drain(ctx, s);
assert.equal(r.sent, true);
assert.equal(calls.length, 1);
assert.deepEqual(r.state.queue.t2, []);
});