mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The restart chaos harness grades how real tasks survive control-plane restarts, and its grades decide which product fixes come next > - Reviewers left 46 unresolved threads on ten merged harness PRs (#20071, #20094, #20106, #20111, #20119, #20147, #20158, #20161, #20178, #20194) > - Several are real harness defects: false speed breaches from one-sample rows, a codex-only wave that cannot start, event paging that can loop forever, an S1 task failed for a Stop the harness never sent, and a readiness wait that aborts on a transient lifecycle error > - Wave S1 t05 (w-20261109T091247-s9806) hit the S1 defect: the run finished before the stop window, so neither the Stop nor the continue comment was sent, and the task was graded `done_too_late Infinity` > - This pull request fixes the valid findings and adds the missing tests > - The benefit is that a failed task points at the product, not at the harness ## Linked Issues or Issue Description Refs #20071, #20094, #20111, #20147, #20158, #20161, #20178, #20194 (review threads). The security finding from #20111 was fixed separately in #20228. **What happened?** Harness defects found in review and in waves: - Aggregate p50/p95 rows breached at n = 1–3, which caused most marginal speed failures. - `--adapters codex` with the default workloads failed at parse because M1 needs two adapters. - `runEvents` paged forever if a full page had no `seq`. - A timed-out task whose last sample was `done` was graded `done_too_late Infinity`, and could pass when a fault had no ready time. - S1 waited forever for a running run to stop; it also clicked Stop while another task's fault had the server down or recovering. - The readiness wait aborted on any `lifecycleError`, including the transient one lifecycle `defer` sets before a 60 s retry, and hid read errors as "not ready". Daytona used the 240 s local timeout. - One failed parent read could hide an M1 stall for the whole 10 s check window. ## What Changed - Speed: aggregate rows breach only from 5 samples (`insufficient sample (n < 5)` otherwise). Restart recoveries over the control-plane p95 budget now count in the per-run check, so a single slow recovery still fails. - Config: the default workloads skip M1 when fewer than two adapters are given; an explicit `--workloads M1` with one adapter still fails. - `runEvents` throws when a full page has no later `seq`; the run's speed read fails instead of hanging. - `gradeR1` fails a timed-out task as `no_rest_within_budget` before checking its status. - S1: the Stop waits for a ready server with no fault in progress. If the run already finished when the window opens, the harness records a missed Stop, skips the stop-triggered fault, still posts the continue comment, and the oracle checks only the continue. - Readiness: only a terminal lifecycle state (rejected, terminating, cleaning up, terminated) aborts at once. Any other lifecycle error is logged when it changes (`seed_agent_lifecycle_error`) and the wait continues until ready or the timeout, which names each agent's last lifecycle or read error. The agent API exposes neither `lifecycleOperation.retryRequired` nor a retry-claim timestamp, so a deferred retry cannot be told apart from a parked failure earlier. Daytona waits up to 10 min. - M1: a failed parent read retries on the next poll. - Child speed collection moved into `childSpeedTasksInTurn` so its one-at-a-time order is tested. - Tests for each change, plus the gaps reviewers named: the stop trigger's arming, stall-wake parsing, and `seedChaosLab`'s readiness wiring. - README: S1 missed Stop, R1 timeout rule, speed sample minimum. ## Verification - `npx vitest run --config tests/restart-chaos/vitest.config.ts`: 230 passed. Each new test failed before its fix, such as the paging test running out of memory in the loop and the stop-trigger test firing a fault after a missed Stop. - `node scripts/typecheck-test-projects.mjs tests/restart-chaos`: clean. - Wave evidence for the defects: S1 t05 in w-20261109T091247-s9806 (missed Stop); codex warm agent_boot p50 breach at n = 3 in w-20261109T104527-s9901. ## Risks - Aggregate rows with fewer than 5 samples no longer fail a wave. Per-run p95 checks still catch individual slow runs and recoveries, but a consistently slightly slow p50 in a small wave is now only reported. - A lifecycle error that persists without `retryRequired` now waits for the readiness timeout (4 min local, 10 min Daytona) instead of failing at once. The timeout message names the error. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code execution in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
283 lines
18 KiB
TypeScript
283 lines
18 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { ChaosApi } from "./api.js";
|
|
import { parseCommand } from "./config.js";
|
|
import { gradeR1 } from "./grader.js";
|
|
import { BUDGET_PAUSE_HOLD_MS, BUDGET_RESUME_HEADROOM_CENTS, REST_CONFIRM_MS, TaskObserver, approvalTitleMatches, runsStartedAfter } from "./observer.js";
|
|
import { planTasks, replayOnCurrentBuild, triggerFitsWorkload } from "./scheduler.js";
|
|
import type { ChaosLab } from "./seed.js";
|
|
import { Timeline } from "./timeline.js";
|
|
import type { FaultReceipt, OracleArtifacts, TaskPlan, TaskRecord, TaskSample, WavePlan } from "./types.js";
|
|
import { g1ApprovalTitle, g1ChildTitle, g1Decision, workloadDefinitions } from "./workloads.js";
|
|
|
|
process.env.RESTART_CHAOS_QUIET = "1";
|
|
const lab: ChaosLab = { companyId: "c1", environmentId: "e1", environmentKind: "local", projectId: "p1", fixtureRepositoryPath: "/tmp/none",
|
|
agents: { codex: { id: "a1", name: "Chaos codex" }, claude: { id: "a2", name: "Chaos claude" }, opencode: { id: "a3", name: "Chaos opencode" } } };
|
|
const ready = { serverReady: true, faultInProgress: false };
|
|
const APPROVE = "0bcd1234";
|
|
const REJECT = "1bcd1234";
|
|
|
|
/** Fake board API: routes answered by prefix, every write recorded. */
|
|
function fakeApi(routes: Record<string, (route: string) => unknown>) {
|
|
const writes: Array<{ method: string; route: string; body: unknown }> = [];
|
|
const answer = (route: string) => {
|
|
for (const [prefix, handler] of Object.entries(routes)) if (route.includes(prefix)) return handler(route);
|
|
if (route.endsWith("/runs")) return [];
|
|
return { id: "i1", status: "blocked", interruption: null };
|
|
};
|
|
const api = {
|
|
async get(route: string) { return answer(route); },
|
|
async post(route: string, body: unknown) { writes.push({ method: "POST", route, body }); return route.endsWith("/issues") ? { id: "i1", identifier: "CHA-1" } : {}; },
|
|
async patch(route: string, body: unknown) { writes.push({ method: "PATCH", route, body }); return {}; },
|
|
};
|
|
return { api: api as unknown as ChaosApi, writes };
|
|
}
|
|
|
|
const g1Plan = (nonce: string): TaskPlan => ({ taskId: "t01", index: 0, workload: "G1", adapter: "codex", fault: "K1", fireAfterMs: 30_000,
|
|
holdMs: 0, followUpAfterMs: null, nonce, trigger: "approval", triggerDelayMs: 0 });
|
|
|
|
describe("G1: approval-gated action across a restart", () => {
|
|
it("splits the board's decisions by nonce", () => {
|
|
expect(g1Decision(APPROVE)).toBe("approve");
|
|
expect(g1Decision(REJECT)).toBe("reject");
|
|
});
|
|
|
|
it.each([[APPROVE, "approve"], [REJECT, "reject"]] as const)("decides (%s) only after the fault the pending approval armed, with the server ready",
|
|
async (nonce, kind) => {
|
|
const pending = { id: "ap1", status: "pending", payload: { title: g1ApprovalTitle(nonce) } };
|
|
const { api, writes } = fakeApi({ "/approvals": () => [pending], "view=index": () => [] });
|
|
const observer = new TaskObserver(g1Plan(nonce), api, lab, new Timeline(null), ready);
|
|
await observer.launch();
|
|
const start = observer.record.createdAt!;
|
|
await observer.poll(start + 1_000);
|
|
expect(observer.record.governance?.approvalSeenAt).toBe(start + 1_000);
|
|
// The board does not act before the fault the pending approval armed.
|
|
expect(observer.record.governance?.decision).toBeUndefined();
|
|
expect(observer.faultDue(start + 1_001)).toMatchObject({ kind: "K1", trigger: "approval" });
|
|
observer.noteFault("f01", start + 1_001);
|
|
await observer.poll(start + 60_000);
|
|
expect(observer.record.governance?.decision).toMatchObject({ kind, error: null, pendingWhenDecided: true, afterFault: true });
|
|
expect(observer.record.governance?.childrenBeforeDecision).toBe(0);
|
|
expect(writes.filter(write => write.route === `/api/approvals/ap1/${kind}`)).toHaveLength(1);
|
|
expect(writes.some(write => write.method === "PATCH" && (write.body as { status?: string }).status === "cancelled")).toBe(kind === "reject");
|
|
});
|
|
|
|
it("holds a task blocked on its approval as waiting, not resting, while its fault is still to come", async () => {
|
|
const pending = { id: "ap1", status: "pending", payload: { title: g1ApprovalTitle(APPROVE) } };
|
|
const { api, writes } = fakeApi({ "/approvals": () => [pending] });
|
|
const observer = new TaskObserver({ ...g1Plan(APPROVE), trigger: undefined, triggerDelayMs: undefined, fireAfterMs: 999_999 },
|
|
api, lab, new Timeline(null), ready);
|
|
await observer.launch();
|
|
const start = observer.record.createdAt!;
|
|
await observer.poll(start + 1_000);
|
|
await observer.poll(start + 1_000 + REST_CONFIRM_MS + 1);
|
|
await observer.poll(start + 1_000 + 2 * REST_CONFIRM_MS + 2);
|
|
expect(observer.done).toBe(false);
|
|
expect(observer.record.governance?.decision).toBeUndefined();
|
|
expect(writes.some(write => write.route.startsWith("/api/approvals/"))).toBe(false);
|
|
});
|
|
|
|
const artifacts = (nonce: string, overrides: Partial<OracleArtifacts> = {}): OracleArtifacts => {
|
|
const approve = g1Decision(nonce) === "approve";
|
|
return { issueStatus: approve ? "done" : "cancelled", documents: {}, agentComments: [], files: {}, commands: {}, workspacePath: null,
|
|
approvals: [{ id: "ap1", status: approve ? "approved" : "rejected", title: g1ApprovalTitle(nonce) }],
|
|
children: approve ? [{ id: "c1", title: g1ChildTitle(nonce), status: "backlog", assigneeAgentId: null, documents: {} }] : [],
|
|
governance: { approvalSeenAt: 1, childrenBeforeDecision: 0,
|
|
decision: { kind: g1Decision(nonce), at: 2, httpStatus: 200, error: null, pendingWhenDecided: true, afterFault: true } },
|
|
...overrides };
|
|
};
|
|
|
|
it("passes an approved action that ran once and a rejected one that never ran", () => {
|
|
expect(workloadDefinitions.G1.grade(APPROVE, artifacts(APPROVE)).verdict).toBe("pass");
|
|
expect(workloadDefinitions.G1.grade(REJECT, artifacts(REJECT)).verdict).toBe("pass");
|
|
});
|
|
|
|
it("fails a duplicate request, an action that ran twice or after a rejection, and a decision that crossed no restart", () => {
|
|
const failed = (nonce: string, overrides: Partial<OracleArtifacts>) =>
|
|
workloadDefinitions.G1.grade(nonce, artifacts(nonce, overrides)).checks.filter(check => !check.ok).map(check => check.name);
|
|
expect(failed(APPROVE, { approvals: [{ id: "ap1", status: "approved", title: g1ApprovalTitle(APPROVE) },
|
|
{ id: "ap2", status: "pending", title: g1ApprovalTitle(APPROVE) }] })).toContain("one_approval_requested");
|
|
const child = { id: "c", title: g1ChildTitle(APPROVE), status: "backlog", assigneeAgentId: null, documents: {} };
|
|
expect(failed(APPROVE, { children: [child, { ...child, id: "d" }] })).toEqual(["approved_action_ran_once"]);
|
|
expect(failed(REJECT, { children: [{ ...child, title: g1ChildTitle(REJECT) }] })).toEqual(["rejected_action_never_ran"]);
|
|
expect(failed(APPROVE, { governance: { approvalSeenAt: 1, childrenBeforeDecision: 0, decision: { kind: "approve", at: 2, httpStatus: 200,
|
|
error: null, pendingWhenDecided: true, afterFault: false } } })).toEqual(["board_decided_after_restart"]);
|
|
// The agent created the subtask while the approval was still pending: the approval did not gate it.
|
|
expect(failed(APPROVE, { governance: { approvalSeenAt: 1, childrenBeforeDecision: 1, decision: { kind: "approve", at: 2, httpStatus: 200,
|
|
error: null, pendingWhenDecided: true, afterFault: true } } })).toEqual(["action_gated_by_approval"]);
|
|
});
|
|
|
|
it("ends a task whose approval a restart lost at its deadline instead of waiting forever", async () => {
|
|
let approvals: unknown[] = [{ id: "ap1", status: "pending", payload: { title: g1ApprovalTitle(APPROVE) } }];
|
|
const { api } = fakeApi({ "/approvals": () => approvals, "view=index": () => [] });
|
|
const observer = new TaskObserver({ ...g1Plan(APPROVE), trigger: undefined, triggerDelayMs: undefined, fireAfterMs: 999_999 },
|
|
api, lab, new Timeline(null), ready);
|
|
await observer.launch();
|
|
const start = observer.record.createdAt!;
|
|
await observer.poll(start + 1_000);
|
|
approvals = [];
|
|
const late = observer.record.deadlineAt! + 1;
|
|
await observer.poll(late - REST_CONFIRM_MS - 1);
|
|
await observer.poll(late);
|
|
expect(observer.done).toBe(true);
|
|
expect(observer.record.timedOut).toBe(true);
|
|
});
|
|
|
|
it("grades a rejected task that rests cancelled as continuing correctly (R1)", () => {
|
|
const record = { plan: g1Plan(REJECT), launchError: null, retry: null, finalStatus: "cancelled", timedOut: false,
|
|
createdAt: 0, restAt: 60_000, samples: [] } as unknown as TaskRecord;
|
|
expect(gradeR1(record, 15 * 60_000, []).verdict).toBe("pass");
|
|
expect(gradeR1({ ...record, finalStatus: "done" }, 15 * 60_000, []).verdict).toBe("fail");
|
|
const unrested = gradeR1({ ...record, timedOut: true, restAt: null }, 15 * 60_000,
|
|
[{ startedAt: 1_000, readyAt: null, healthyAt: null } as unknown as FaultReceipt]);
|
|
expect(unrested).toEqual({ verdict: "fail", detail: "no_rest_within_budget (last status cancelled)" });
|
|
});
|
|
|
|
it("counts a redacted approval title as the task's own", () => {
|
|
expect(approvalTitleMatches({ payload: { title: g1ApprovalTitle(APPROVE) } }, APPROVE)).toBe(true);
|
|
expect(approvalTitleMatches({ payload: {} }, APPROVE)).toBe(true);
|
|
expect(approvalTitleMatches({ payload: { title: "Approve something else" } }, APPROVE)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("H1: budget hard stop across a restart", () => {
|
|
const h1Plan: TaskPlan = { taskId: "t01", index: 0, workload: "H1", adapter: "codex", fault: "K2", fireAfterMs: 30_000,
|
|
holdMs: 0, followUpAfterMs: null, nonce: "abcd1234", trigger: "paused", triggerDelayMs: 0 };
|
|
|
|
it("sets the budget to spend plus one cent, then resumes through the incident after the pause held across the fault", async () => {
|
|
const pausedAt = new Date(Date.now() + 2_000).toISOString();
|
|
let paused = false;
|
|
const { api, writes } = fakeApi({
|
|
"/budgets/overview": () => ({ policies: [{ scopeType: "company", observedAmount: 40.25 }],
|
|
activeIncidents: paused ? [{ id: "inc1", scopeType: "company", amountObserved: 55.5 }] : [] }),
|
|
"/api/companies/c1": () => paused ? { id: "c1", status: "paused", pauseReason: "budget", pausedAt } : { id: "c1", status: "active" },
|
|
});
|
|
const observer = new TaskObserver(h1Plan, api, lab, new Timeline(null), ready);
|
|
await observer.launch();
|
|
// Whole cents: observed spend can be fractional.
|
|
expect(writes[0]).toMatchObject({ method: "PATCH", route: "/api/companies/c1/budgets", body: { budgetMonthlyCents: 42 } });
|
|
const start = observer.record.createdAt!;
|
|
paused = true;
|
|
await observer.poll(start + 3_000);
|
|
expect(observer.record.governance?.budgetPausedAt).toBeDefined();
|
|
expect(observer.faultDue(start + 3_001)).toMatchObject({ kind: "K2", trigger: "paused" });
|
|
observer.noteFault("f01", start + 3_001);
|
|
// The pause must hold with the server ready before the board resumes.
|
|
await observer.poll(start + 10_000);
|
|
expect(observer.record.governance?.resume).toBeUndefined();
|
|
await observer.poll(start + 10_000 + BUDGET_PAUSE_HOLD_MS + 1);
|
|
expect(observer.record.governance?.resume).toMatchObject({ incidentId: "inc1", amount: 56 + BUDGET_RESUME_HEADROOM_CENTS,
|
|
error: null, afterFault: true });
|
|
expect(observer.record.governance?.runsStartedWhilePaused).toEqual([]);
|
|
expect(writes.at(-1)).toMatchObject({ method: "POST", route: "/api/companies/c1/budget-incidents/inc1/resolve",
|
|
body: { action: "raise_budget_and_resume", amount: 56 + BUDGET_RESUME_HEADROOM_CENTS } });
|
|
});
|
|
|
|
it("catches, at grading, a run that started after the last poll but before the resume returned", async () => {
|
|
let paused = true;
|
|
let runs: unknown[] = [];
|
|
const { api } = fakeApi({
|
|
"/budgets/overview": () => ({ policies: [{ scopeType: "company", observedAmount: 0 }],
|
|
activeIncidents: [{ id: "inc1", scopeType: "company", amountObserved: 1 }] }),
|
|
"/api/companies/c1": () => paused ? { id: "c1", status: "paused", pauseReason: "budget" } : { id: "c1", status: "active" },
|
|
"/runs": () => runs,
|
|
"/documents/": () => null,
|
|
"/comments": () => [],
|
|
});
|
|
const observer = new TaskObserver(h1Plan, api, lab, new Timeline(null), ready);
|
|
await observer.launch();
|
|
const start = observer.record.createdAt!;
|
|
await observer.poll(start + 1_000);
|
|
observer.faultDue(start + 1_001);
|
|
observer.noteFault("f01", start + 1_001);
|
|
await observer.poll(start + 5_000);
|
|
await observer.poll(start + 5_000 + BUDGET_PAUSE_HOLD_MS + 1);
|
|
expect(observer.record.governance?.runsStartedWhilePaused).toEqual([]);
|
|
const resumeDone = observer.record.governance!.resume!.doneAt!;
|
|
paused = false;
|
|
// Dispatched while still paused, but only visible after the resume.
|
|
runs = [{ runId: "sneaky", status: "succeeded", startedAt: new Date(resumeDone - 1).toISOString(), createdAt: null, finishedAt: null }];
|
|
const artifacts = await observer.collectArtifacts();
|
|
expect(artifacts.governance?.runsStartedWhilePaused).toEqual(["sneaky"]);
|
|
});
|
|
|
|
it("records a pause that clears before the board resumes it, and does not resume", async () => {
|
|
let paused = true;
|
|
const { api, writes } = fakeApi({
|
|
"/budgets/overview": () => ({ policies: [{ scopeType: "company", observedAmount: 0 }], activeIncidents: [{ id: "inc1", scopeType: "company" }] }),
|
|
"/api/companies/c1": () => paused ? { id: "c1", status: "paused", pauseReason: "budget" } : { id: "c1", status: "active" },
|
|
});
|
|
const observer = new TaskObserver(h1Plan, api, lab, new Timeline(null), ready);
|
|
await observer.launch();
|
|
const start = observer.record.createdAt!;
|
|
await observer.poll(start + 1_000);
|
|
observer.faultDue(start + 1_001);
|
|
observer.noteFault("f01", start + 1_001);
|
|
paused = false;
|
|
await observer.poll(start + 1_000 + BUDGET_PAUSE_HOLD_MS + 10_000);
|
|
await observer.poll(start + 1_000 + 2 * BUDGET_PAUSE_HOLD_MS + 20_000);
|
|
expect(observer.record.governance?.pauseLostAt).toBeDefined();
|
|
expect(observer.record.governance?.resume).toBeUndefined();
|
|
expect(writes.some(write => write.route.includes("/resolve"))).toBe(false);
|
|
});
|
|
|
|
it("finds runs that started while the company was paused", () => {
|
|
const sample = (runs: Array<{ id: string; startedAt: string | null }>): TaskSample => ({ at: 0, reachable: true, serverReady: true,
|
|
runs: runs.map(run => ({ ...run, status: "running", createdAt: null, finishedAt: null, errorCode: null, retryOfRunId: null,
|
|
wakeCommentIds: [], livenessState: null })) });
|
|
expect(runsStartedAfter([sample([{ id: "before", startedAt: new Date(1_000).toISOString() }]),
|
|
sample([{ id: "after", startedAt: new Date(5_000).toISOString() }, { id: "queued", startedAt: null }])], 2_000)).toEqual(["after"]);
|
|
});
|
|
|
|
it("grades a missing pause, a dispatch while paused and a resume that crossed no restart as failures", () => {
|
|
const base: OracleArtifacts = { issueStatus: "done", documents: { brief: "CHAOS-abcd1234\n- a\n- b\n- c" }, agentComments: [], files: {},
|
|
commands: {}, workspacePath: null, governance: { budgetSetCents: 41, budgetPausedAt: 1, runsStartedWhilePaused: [],
|
|
resume: { at: 2, amount: 3055, incidentId: "inc1", httpStatus: 200, error: null, afterFault: true }, companyActiveAtRest: true } };
|
|
expect(workloadDefinitions.H1.grade("abcd1234", base).verdict).toBe("pass");
|
|
const failed = (governance: OracleArtifacts["governance"]) => workloadDefinitions.H1.grade("abcd1234", { ...base, governance })
|
|
.checks.filter(check => !check.ok).map(check => check.name);
|
|
expect(failed({ ...base.governance, budgetPausedAt: null })).toContain("company_paused_for_budget");
|
|
expect(failed({ ...base.governance, pauseLostAt: 5 })).toEqual(["pause_held_until_resume"]);
|
|
expect(failed({ ...base.governance, runsStartedWhilePaused: ["r2"] })).toEqual(["nothing_dispatched_while_paused"]);
|
|
expect(failed({ ...base.governance, resume: { ...base.governance!.resume!, afterFault: false } })).toEqual(["board_resumed_after_restart"]);
|
|
});
|
|
});
|
|
|
|
describe("K14 replay", () => {
|
|
it("replays a task that launched after the upgrade on the current build, its K14 restarts as K2", () => {
|
|
const plan = { schema: "paperclip.restart-chaos.wave-plan/v1", waveId: "w", seed: 1, createdAt: "",
|
|
options: { env: "local", adapters: ["codex"], workloads: ["A1"], faults: ["K14", "K1"], concurrency: 1, tasks: 1, seed: 1,
|
|
budgetCents: 3_000, pollMs: 3_000, upgradeFrom: "/old" },
|
|
tasks: [{ taskId: "t02", index: 0, workload: "A1", adapter: "codex", fault: "K14", fireAfterMs: 1, holdMs: 0, followUpAfterMs: null,
|
|
nonce: "n", replayFaults: [{ kind: "K14", holdMs: 0, atMs: 5 }, { kind: "K1", holdMs: 0, atMs: 9 }] }] } as WavePlan;
|
|
const replay = replayOnCurrentBuild(plan);
|
|
expect(replay.options.upgradeFrom).toBeUndefined();
|
|
expect(replay.options.faults).toEqual(["K2", "K1"]);
|
|
expect(replay.tasks[0]).toMatchObject({ fault: "K2", replayFaults: [{ kind: "K2" }, { kind: "K1" }] });
|
|
});
|
|
});
|
|
|
|
describe("governance wave options", () => {
|
|
it("keeps G1 and H1 out of default waves and gates their triggers", () => {
|
|
const command = parseCommand(["--seed", "3"]);
|
|
if (command.mode !== "wave") throw new Error("expected a wave");
|
|
expect(command.options.workloads).not.toContain("G1");
|
|
expect(command.options.workloads).not.toContain("H1");
|
|
expect(triggerFitsWorkload("approval", "G1")).toBe(true);
|
|
expect(triggerFitsWorkload("stop", "S1")).toBe(true);
|
|
expect(triggerFitsWorkload("stop", "C1")).toBe(false);
|
|
expect(triggerFitsWorkload("approval", "A1")).toBe(false);
|
|
expect(triggerFitsWorkload("paused", "H1")).toBe(true);
|
|
expect(() => planTasks({ seed: 1, tasks: 2, workloads: ["A1"], adapters: ["codex"], faults: ["K1"], triggers: ["approval"] }))
|
|
.toThrow(/needs workload G1/);
|
|
const tasks = planTasks({ seed: 1, tasks: 4, workloads: ["G1"], adapters: ["codex"], faults: ["K1", "K2"], triggers: ["approval"] });
|
|
expect(tasks.every(task => task.trigger === "approval")).toBe(true);
|
|
});
|
|
|
|
it("runs H1 alone, one task at a time, with the hard stop on", () => {
|
|
expect(parseCommand(["--workloads", "H1", "--concurrency", "1", "--triggers", "paused"]).mode).toBe("wave");
|
|
expect(() => parseCommand(["--workloads", "H1,A1", "--concurrency", "1"])).toThrow(/its own wave/);
|
|
expect(() => parseCommand(["--workloads", "H1"])).toThrow(/--concurrency 1/);
|
|
expect(() => parseCommand(["--workloads", "H1", "--concurrency", "1", "--rc06-masked"])).toThrow(/hard stop/);
|
|
});
|
|
});
|