Emit job events, checkpoint at terminal, and bound the run wait

This commit is contained in:
alex committed 2026-12-01 11:39:54 +00:00
1 parent bf70be5729
commit df929590e8
17 files changed
+501 -166

No files matched your search

+14 -8
View File
@@ -19,7 +19,7 @@ import {
import { prepareWorkflowInvocation, type PrepareContext } from "../src/prepare.ts";
import { parseWorkflow, type WorkflowPlan, type WorkflowSource } from "../src/workflow-plan.ts";
import { emptyUsage, type JobSnapshot, type TaskSnapshot, type TaskStatus, type WorkflowJournal, type WorkflowJournalItem, type WorkflowJournalStep } from "../src/types.ts";
import { FakeRunner } from "./helpers.ts";
import { FakeRunner, waitForSnapshot } from "./helpers.ts";
const tempRoots: string[] = [];
@@ -85,6 +85,7 @@ function serialized(entry: unknown): unknown {
/** One row of a run's DAG index: the shared record the journal projects. */
function taskRow(stepId: string, status: TaskStatus, output = "", extra: Partial<TaskSnapshot> = {}): InternalTask {
return {
messages: [],
snapshot: {
agent: "scout",
agentSource: "user",
@@ -130,7 +131,7 @@ test("a finished run persists one journal entry with per-step records and usage"
completeStep(runner, "scan", "src/a.ts");
await tick();
completeStep(runner, "audit", "no findings");
const terminal = await manager.wait(started.id, 1);
const terminal = await waitForSnapshot(manager, started.id, 1);
assert.equal(terminal.status, "succeeded");
assert.equal(journals.length, 1);
@@ -168,7 +169,10 @@ test("an unfinished run journals once as interrupted and restores interrupted af
const jobs: JobSnapshot[] = [];
const manager = new SubagentManager(runner, {
maxWorkers: 2,
onJobChange: (job) => jobs.push(job),
onJobEvent: (event) => {
// Persistence checkpoints at the terminal transition only (ADR 0004).
if (event.kind === "finalized") jobs.push(manager.get(event.jobId));
},
onWorkflowJournal: (journal) => journals.push(journal),
});
const started = manager.startWorkflow(
@@ -290,7 +294,7 @@ test("journals hash the step inputs, not the outputs, so identical runs agree",
completeStep(runner, "scan", `${output} sources`);
await tick();
completeStep(runner, "audit", output);
await manager.wait(started.id, 1);
await waitForSnapshot(manager, started.id, 1);
assert.equal(journals.length, 1);
return journals[0];
}
@@ -351,7 +355,7 @@ test("a failed run journals skipped dependents and retains the independent branc
completeStep(runner, "scan", "partial", { exitCode: 1, errorMessage: "scan exploded" });
await tick();
completeStep(runner, "notify", "sent");
assert.equal((await manager.wait(started.id, 1)).status, "failed");
assert.equal((await waitForSnapshot(manager, started.id, 1)).status, "failed");
assert.equal(journals.length, 1);
assert.equal(journals[0].status, "failed");
@@ -380,7 +384,7 @@ test("a cancelled run journals once, with every unfinished step settled cancelle
);
manager.cancel(started.id);
assert.equal((await manager.wait(started.id, 1)).status, "cancelled");
assert.equal((await waitForSnapshot(manager, started.id, 1)).status, "cancelled");
assert.equal(journals.length, 1);
assert.equal(journals[0].status, "cancelled");
assert.deepEqual(
@@ -570,7 +574,9 @@ test("a run journals each item's source line, status, and timings through the ma
const journals: WorkflowJournal[] = [];
const jobs: JobSnapshot[] = [];
const manager = new SubagentManager(runner, {
onJobChange: (job) => jobs.push(job),
onJobEvent: (event) => {
if (event.kind === "finalized") jobs.push(manager.get(event.jobId));
},
onWorkflowJournal: (journal) => journals.push(journal),
});
const started = manager.startWorkflow(
@@ -580,7 +586,7 @@ test("a run journals each item's source line, status, and timings through the ma
await tick();
runner.complete("audit src/a.ts", "ok a");
runner.complete("audit src/b.ts", "bad b", { exitCode: 1, errorMessage: "b exploded" });
assert.equal((await manager.wait(started.id, 1)).status, "failed", "a failed item fails the run");
assert.equal((await waitForSnapshot(manager, started.id, 1)).status, "failed", "a failed item fails the run");
assert.equal(journals.length, 1);
return { journal: journals[0], job: jobs.at(-1)! };
}