Files
stack/extensions/goal/test/quiet-wait.test.ts
T

28 lines
1.6 KiB
TypeScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { initialState, setGoal, recordInProgressReport } from "../lib/state.ts";
import { decideSettle } from "../lib/settle.ts";
import { parseGoalCommand } from "../lib/parse.ts";
const wait = { evidence: "Dependency pending", progress: { kind: "wait" as const, gate: "input", owner: "operator", lastMeasurement: "input absent", nextAction: "Read input when available", nextCheck: "input file arrives" } };
test("opted-in waits suspend settle injection", () => {
const state = { ...setGoal(initialState(), "prepare output"), waitTimeoutSeconds: 60 };
const waiting = recordInProgressReport(state, wait).state;
assert.equal(decideSettle(waiting, "stop").action, "wait");
});
test("operator can select bounded waits per goal", () => {
assert.deepEqual(parseGoalCommand("--wait-timeout 60 --max 5 prepare output"), { kind: "set", text: "prepare output", max: 5, waitTimeoutSeconds: 60 });
});
test("timeout input is bounded and opt-in never leaks to another goal", () => {
for (const args of ["--wait-timeout", "--wait-timeout=", "--wait-timeout 0 x", "--wait-timeout 9 x", "--wait-timeout 86401 x", "--wait-timeout 60.0 x", "--wait-timeout 60", "--wait-timeout 60 --wait-timeout 30 x"]) {
assert.equal(parseGoalCommand(args).kind, "error", args);
}
const opted = setGoal(initialState(), "one", undefined, 60);
assert.equal(setGoal(opted, "two").waitTimeoutSeconds, undefined);
const legacyWait = recordInProgressReport(setGoal(initialState(), "legacy"), wait).state;
assert.equal(decideSettle(legacyWait, "stop").action, "wait");
});