Hash whole plan steps under payload version 2

workflowStepInputHash and workflowItemInputHash feed the canonical
serializer the plan with provenance stripped, so every step field is
hashed by default and a new one cannot vanish from the replay contract.
The payload marker moves 1 -> 2 to separate hash eras; nothing replays
today (ADR 0004).
This commit is contained in:
alex committed 2026-12-01 11:19:33 +00:00
1 parent 1fcc6130c7
commit fa747145ce
2 files changed
+42 -24

No files matched your search

+25 -4
View File
@@ -4,7 +4,7 @@ import * as os from "node:os";
import * as path from "node:path";
import test, { after } from "node:test";
import fc from "fast-check";
import { buildWorkflowJournal, workflowItemInputHash, workflowStepInputHash } from "../src/journal.ts";
import { buildWorkflowJournal, WORKFLOW_HASH_PAYLOAD_VERSION, workflowItemInputHash, workflowStepInputHash } from "../src/journal.ts";
import { SubagentManager } from "../src/manager.ts";
import { MAX_TASK_OUTPUT_BYTES, truncateUtf8Head } from "../src/output.ts";
import {
@@ -16,7 +16,7 @@ import {
WORKFLOW_RUN_ENTRY,
} from "../src/persistence.ts";
import { prepareWorkflowInvocation, type PrepareContext } from "../src/prepare.ts";
import { parseWorkflow, type WorkflowPlan } from "../src/workflow-plan.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";
@@ -49,9 +49,16 @@ function makeWorkspace(agentNames = ["scout"]): { cwd: string; ctx: PrepareConte
};
}
function makePlan(steps: Array<Record<string, unknown>>, args: string[] = []): WorkflowPlan {
function makePlan(
steps: Array<Record<string, unknown>>,
args: string[] = [],
provenance: { source?: WorkflowSource; filePath?: string } = {},
): WorkflowPlan {
const content = `---\n${JSON.stringify({ name: "test-workflow", description: "Test workflow", args, steps }, null, 2)}\n---\n\nNotes.\n`;
return parseWorkflow(content, { source: "user", filePath: "/tmp/test-workflow.md" });
return parseWorkflow(content, {
source: provenance.source ?? "user",
filePath: provenance.filePath ?? "/tmp/test-workflow.md",
});
}
function pending(runner: FakeRunner, stepId: string) {
@@ -239,6 +246,20 @@ test("step input hashes are stable across identical inputs and change with args
workflowStepInputHash(first, "scan", { target: "src" }),
);
assert.notEqual(workflowStepInputHash(first, "ghost", { target: "src" }), workflowStepInputHash(first, "scan", { target: "src" }));
// Whole steps are hashed: a step field beyond the brief still moves the hash.
const withCwd = makePlan([{ id: "scan", agent: "scout", task: "scan {args.target}", cwd: "src" }], ["target"]);
assert.notEqual(workflowStepInputHash(withCwd, "scan", { target: "src" }), workflowStepInputHash(first, "scan", { target: "src" }));
// Provenance is not an input: the same plan copied elsewhere hashes alike.
const elsewhere = makePlan(steps, ["target"], { source: "project", filePath: "/repo/.pi/workflows/test-workflow.md" });
assert.equal(workflowStepInputHash(elsewhere, "scan", { target: "src" }), workflowStepInputHash(first, "scan", { target: "src" }));
});
test("the input-hash payload carries the replay-contract version", () => {
// Nothing replays today (ADR 0004 journal-only); the marker only separates
// hash eras, so moving it is a deliberate migration, never a refactor.
assert.equal(WORKFLOW_HASH_PAYLOAD_VERSION, 2);
});
test("journals hash the step inputs, not the outputs, so identical runs agree", async () => {