Files
loki/scripts/test/dod-gate.ts
T
GandClaude Opus 4.8 4fcccef200 feat(autopilot): definition-of-done stop-gate — don't stop on the agent's own say-so (#43)
The /goal pattern. closeRunFromSession closes a run the moment the agent writes
status: ready — the agent grading its own homework (Ralph Wiggum). When a project
declares a definition_of_done (now a first-class profile field, injected into
every dispatch), the close is gated by a DIFFERENT-lineage model:

- dod-gate.ts: verifyDefinitionOfDone(dod, handoff) — gpt-oss-120b (not the
  worker's lineage) reads the handoff against the stated bar, returns {met, gap}.
  Fail-OPEN (a judge error lets the run close rather than wedge the loop).
- applyDoDGate (pure, unit-tested): a SUCCESS close with an unmet bar is
  downgraded to "partial" with the gap written into `next`, so autopilot's
  existing continue-loop keeps working instead of stopping. Only gates success;
  error/partial are untouched.
- Wired at the control close seam, fire-and-forget + an in-flight guard so the
  judge fires at most once per run and never blocks the control response.

This makes "done" an objective, cross-model-verified condition per project —
the lever the loop-engineering literature calls the real one. scripts/test/
dod-gate.ts (7 cases) added to the pre-push suite. tsc=0, eslint=0.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-25 11:57:30 +02:00

43 lines
2.0 KiB
TypeScript

// Self-test for the definition-of-done stop-gate decision (pure part).
// Run: npx tsx scripts/test/dod-gate.ts
import { applyDoDGate } from "@/lib/orchestration/dod-gate";
import type { RunClosePatch } from "@/lib/orchestration/close-from-session";
let pass = 0, fail = 0;
function ok(name: string, cond: boolean) {
if (cond) { pass++; console.log(` ✓ ${name}`); }
else { fail++; console.log(` ✗ ${name}`); }
}
const base = (outcome: RunClosePatch["outcome"]): RunClosePatch => ({
state: outcome === "error" ? "error" : "done",
outcome,
summary: { done: "did the thing", next: "" } as RunClosePatch["summary"],
finishedAt: new Date(0),
});
// 1. success + met → unchanged
const r1 = applyDoDGate(base("success"), { met: true, gap: "" });
ok("success + DoD met → stays success", r1.outcome === "success");
// 2. success + NOT met → downgraded to partial, gap surfaced in next
const r2 = applyDoDGate(base("success"), { met: false, gap: "tests not run" });
ok("success + DoD unmet → partial", r2.outcome === "partial");
ok("success + DoD unmet → gap written to next", typeof r2.summary.next === "string" && r2.summary.next.includes("tests not run"));
ok("success + DoD unmet → next signals not-done", r2.summary.next!.toLowerCase().includes("not yet met"));
// 3. partial + NOT met → unchanged (only gates success)
const r3 = applyDoDGate(base("partial"), { met: false, gap: "x" });
ok("partial + DoD unmet → stays partial (not re-gated)", r3.outcome === "partial");
// 4. error + NOT met → unchanged
const r4 = applyDoDGate(base("error"), { met: false, gap: "x" });
ok("error + DoD unmet → stays error", r4.outcome === "error");
// 5. empty gap still produces an actionable next
const r5 = applyDoDGate(base("success"), { met: false, gap: "" });
ok("success + DoD unmet + empty gap → still has actionable next", !!r5.summary.next && r5.summary.next.length > 10);
console.log(`\n${fail === 0 ? "✓" : "✗"} dod-gate: ${pass} passed, ${fail} failed`);
process.exit(fail === 0 ? 0 : 1);