fix: start queue countdown from state, clear stale stop flag, drop dead watch code
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
7ec35215c6
commit
86ca415d96
3 files changed
+111
-68
No files matched your search
+36
-1
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { decide, gateAfter, onRestart, shouldDrain, drain } from "../mod/ovis-composer/delivery.js";
|
||||
import { decide, gateAfter, onRestart, shouldDrain, shouldStartCountdown, drain } from "../mod/ovis-composer/delivery.js";
|
||||
|
||||
test("decide idle/done -> send", () => {
|
||||
assert.equal(decide("idle").kind, "send");
|
||||
@@ -70,3 +70,38 @@ test("drain sends an entry whose countdown ran out", async () => {
|
||||
assert.equal(calls.length, 1);
|
||||
assert.deepEqual(r.state.queue.t2, []);
|
||||
});
|
||||
|
||||
const sc = (over = {}) => ({
|
||||
status: "idle", queue: [{ id: "1", state: "queued" }], gateOpen: true, stopped: false, ...over,
|
||||
});
|
||||
|
||||
test("shouldStartCountdown: idle/done + queued + open gate", () => {
|
||||
assert.equal(shouldStartCountdown(sc()), true);
|
||||
assert.equal(shouldStartCountdown(sc({ status: "done" })), true);
|
||||
});
|
||||
|
||||
test("shouldStartCountdown: not while the agent works, is blocked or unknown", () => {
|
||||
for (const status of ["working", "blocked", "error"]) {
|
||||
assert.equal(shouldStartCountdown(sc({ status })), false, status);
|
||||
}
|
||||
});
|
||||
|
||||
test("shouldStartCountdown: held does not start, uncertain in front does not block", () => {
|
||||
assert.equal(shouldStartCountdown(sc({ queue: [{ state: "held" }] })), false);
|
||||
assert.equal(shouldStartCountdown(sc({ queue: [{ state: "uncertain" }, { state: "queued" }] })), true);
|
||||
assert.equal(shouldStartCountdown(sc({ queue: [] })), false);
|
||||
});
|
||||
|
||||
test("shouldStartCountdown: nothing starts while another entry counts or sends", () => {
|
||||
assert.equal(shouldStartCountdown(sc({ queue: [{ state: "countdown" }, { state: "queued" }] })), false);
|
||||
assert.equal(shouldStartCountdown(sc({ queue: [{ state: "sending" }, { state: "queued" }] })), false);
|
||||
});
|
||||
|
||||
test("shouldStartCountdown: stopped or closed gate blocks", () => {
|
||||
assert.equal(shouldStartCountdown(sc({ stopped: true })), false);
|
||||
assert.equal(shouldStartCountdown(sc({ gateOpen: false })), false);
|
||||
});
|
||||
|
||||
test("shouldStartCountdown tolerates a non-array queue", () => {
|
||||
assert.equal(shouldStartCountdown(sc({ queue: null })), false);
|
||||
});
|
||||
Reference in new issue
Block a user