Files
PaperClipAI/tests/runner-e2e/product-journeys/task-dependency-resume-evidence.test.ts
DottaandClaude Opus 5.5 7c0c116edf test(e2e): accept every dependency wake producer for the one automatic resume (#21732)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - When a blocker task is completed, Paperclip wakes the blocked
dependent task automatically
> - Two producers emit that `issue_blockers_resolved` wake: the issue
update route and the issue-graph liveness backstop (plus workspace
finalize); they share one idempotency key and coalesce into one wake run
> - The QA task-dependency-resume journey requires the run's
`contextSnapshot.source` to be exactly `issue.blockers_resolved`
> - On QA both producers emitted 43 ms apart; the run was created once,
but the later backstop wake recorded its source on the run, so the
journey failed a resume that happened exactly once
> - This pull request accepts any of the three producers and keeps every
other resume condition
> - The benefit is that the journey tests the user-visible promise (one
automatic resume caused by this blocker) instead of which internal
producer won a race

## Linked Issues or Issue Description

**What happened?**
QA run (launch 3937) failed task-dependency-resume on
`dependency_one_automatic_resume`. The dependent's activity log shows
`issue.blockers_resolved_wake_emitted` from `issue_update` at
06:59:39.973 and from `issue_graph_liveness_backstop` at 06:59:40.016
with the same idempotency key and the same wake run. Exactly one run
executed, started after the blocker completed, and succeeded.

**Expected behavior**
The journey accepts one automatic, blocker-caused resume regardless of
which producer's label the coalesced run kept.

**Steps to reproduce**
Grade the retained evidence with `contextSnapshot.source =
"issue_graph_liveness.backstop"`: `dependency-one-automatic-resume`
fails although every other condition holds.

## What Changed

- `task-dependency-resume-evidence.ts`: the wake source must be one of
`issue.blockers_resolved`, `issue_graph_liveness.backstop`,
`workspace.finalize` (the producers of this wake reason in
`server/src`).
- Still required: one dependent run, `invocationSource` automation /
`triggerDetail` system, wake reason `issue_blockers_resolved`, the
resolved blocker id, start after blocker completion, committed native
run, no leftover checkout.

## Verification

- Red/green: new cases "accepts the same automatic resume when the
issue_graph_liveness.backstop / workspace.finalize dependency wake
recorded its source" fail before and pass after.
- Existing mutants still fail: "mutation name used as wake source"
(`issue.blocker_done`) and "missing saved wake source".
- `tests/runner-e2e` task-dependency tests: 3 files, 108 tests pass.

## Risks

- Low risk: journey grading only. Separate note: the coalesced run keeps
the last producer's source label; whether it should keep the first is a
provenance question, not addressed here.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and
code execution.

## 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>
2026-11-15 07:29:19 +00:00

129 lines
11 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { dependencyOutputMatches, gradeTaskDependencyResume, TASK_DEPENDENCY_RESUME_CHECKS, type DependencyEvidence } from "./task-dependency-resume-evidence.js";
import { dependencyEvidenceFixture } from "./task-dependency-resume-fixture.js";
describe("task dependency resume evidence", () => {
it("accepts a finite blocked observation followed by one automatic, attributed native result", () => {
const checks = gradeTaskDependencyResume(dependencyEvidenceFixture());
expect(checks).toEqual(TASK_DEPENDENCY_RESUME_CHECKS.map(id => ({ id, passed: true })));
});
const changeRuns = (f: DependencyEvidence, mutate: (run: Record<string, any>) => void) => {
for (const point of [f.finished, f.reopened]) for (const run of [...point.dependentRuns, ...point.agentRuns]) mutate(run);
};
it.each([
["provider", (f: DependencyEvidence) => changeRuns(f, run => { run.runnerProfileJson.nativeExecutionInput.provider.kind = "other"; }), "configured-model-and-environment"],
["model", (f: DependencyEvidence) => changeRuns(f, run => { run.runnerProfileJson.nativeExecutionInput.provider.model = "other"; }), "configured-model-and-environment"],
["environment", (f: DependencyEvidence) => changeRuns(f, run => { run.contextSnapshot.paperclipEnvironment.id = "other"; }), "configured-model-and-environment"],
["runtime mode", (f: DependencyEvidence) => changeRuns(f, run => { run.runtimeMode = "legacy"; }), "configured-model-and-environment"],
["uncommitted phase", (f: DependencyEvidence) => changeRuns(f, run => { run.nativePhase = "saving"; }), "configured-model-and-environment"],
["document author", (f: DependencyEvidence) => { f.finished.document!.createdByUserId = "user"; }, "dependency-output-authored-by-run"],
["revision run", (f: DependencyEvidence) => { f.finished.revision!.createdByRunId = "foreign"; }, "dependency-output-authored-by-run"],
["reload visibility", (f: DependencyEvidence) => { f.reopened.resultVisible = false; }, "dependency-result-reopened"],
["activity coverage", (f: DependencyEvidence) => { f.reopened.activityCoverage.agent = false; }, "dependency-history-preserved"],
["extra child work", (f: DependencyEvidence) => { f.reopened.activity.push({ runId: "run", action: "issue.created" }); }, "dependency-history-preserved"],
["retained completion", (f: DependencyEvidence) => { f.reopened.blocker.completedAt = "2020-01-01T00:00:22.000Z"; }, "dependency-history-preserved"],
] as const)("attributes the %s defect to its own evidence check", (_name, mutate, failedId) => {
const f = dependencyEvidenceFixture(); mutate(f);
expect(gradeTaskDependencyResume(f).filter(check => !check.passed).map(check => check.id)).toEqual([failedId]);
});
const mutants: Array<[string, (value: DependencyEvidence) => void]> = [
["missing observation", f => { f.waiting = []; }],
["short quiet window", f => { f.waiting[1]!.observedAt--; }],
["non-monotonic observation", f => { f.waiting.reverse(); }],
["quiet window before creation", f => { f.created.observedAt = f.waiting[0]!.observedAt + 1; }],
["release before final quiet read", f => { f.releaseRequestedAt = f.waiting[1]!.observedAt - 1; }],
["blocker not completed", f => { f.released.blocker.status = "todo"; }],
["wrong board actor", f => { f.reopened.activity[0]!.actorId = "foreign"; }],
["agent claimed board completion", f => { f.reopened.activity[0]!.actorType = "agent"; }],
["missing board completion audit", f => { f.reopened.activity = []; }],
["duplicate board completion", f => { f.reopened.activity.push({ ...f.reopened.activity[0] }); }],
["wrong blocker relation", f => { f.waiting[0]!.dependent.blockedByIssueIds = ["foreign"]; }],
["removed relation after completion", f => { f.reopened.dependent.blockedByIssueIds = []; }],
["parked backlog instead of blocked", f => { f.waiting[0]!.dependent.status = "backlog"; }],
["premature execution", f => { f.waiting[0]!.dependentRuns = [f.finished.dependentRuns[0]!]; }],
["unknown work on owned agent", f => { f.waiting[0]!.agentRuns = [f.finished.agentRuns[0]!]; }],
["blocker ran an agent", f => { f.reopened.blockerRuns = [f.finished.dependentRuns[0]!]; }],
["dependency never resumed", f => { f.finished.dependent.status = "blocked"; }],
["duplicate native run", f => { f.reopened.dependentRuns.push({ ...f.reopened.dependentRuns[0], id: "extra" }); }],
["native run preceded blocker completion", f => { f.finished.dependentRuns[0]!.startedAt = "2020-01-01T00:00:19.000Z"; }],
["manual run instead of automatic resume", f => { f.finished.dependentRuns[0]!.invocationSource = "on_demand"; }],
["wrong wake reason", f => { f.finished.dependentRuns[0]!.contextSnapshot.wakeReason = "issue_assigned"; }],
["mutation name used as wake source", f => { for (const p of [f.finished, f.reopened]) for (const r of [...p.dependentRuns, ...p.agentRuns]) r.contextSnapshot.source = "issue.blocker_done"; }],
["missing saved wake source", f => { for (const p of [f.finished, f.reopened]) for (const r of [...p.dependentRuns, ...p.agentRuns]) delete r.contextSnapshot.source; }],
["wrong resolved blocker", f => { f.finished.dependentRuns[0]!.contextSnapshot.resolvedBlockerIssueId = "foreign"; }],
["conflicting native issue binding", f => { f.finished.dependentRuns[0]!.issueId = "foreign"; }],
["reopened run changed status", f => { f.reopened.dependentRuns[0]!.status = "running"; }],
["reopened native work still owns checkout", f => { f.reopened.dependent.executionRunId = "run"; }],
["wrong provider", f => { f.finished.dependentRuns[0]!.runnerProfileJson.nativeExecutionInput.provider.kind = "other"; }],
["wrong model", f => { f.finished.dependentRuns[0]!.runnerProfileJson.nativeExecutionInput.provider.model = "other"; }],
["wrong environment", f => { f.finished.dependentRuns[0]!.contextSnapshot.paperclipEnvironment.id = "other"; }],
["uncommitted native phase", f => { for (const p of [f.finished, f.reopened]) for (const r of [...p.dependentRuns, ...p.agentRuns]) r.nativePhase = "saving"; }],
["missing native phase", f => { for (const p of [f.finished, f.reopened]) for (const r of [...p.dependentRuns, ...p.agentRuns]) delete r.nativePhase; }],
["incomplete activity coverage", f => { f.reopened.activityCoverage.agent = false; }],
["wrong saved reference", f => { f.finished.document!.body = '{"reference":"wrong","blockerIdentifier":"QA-1"}'; }],
["wrong document task", f => { f.finished.document!.issueId = "foreign"; }],
["board-authored document", f => { f.finished.document!.createdByUserId = "user"; }],
["revision from another run", f => { f.finished.revision!.createdByRunId = "foreign"; }],
["missing saved result", f => { delete f.finished.document; }],
["missing revision", f => { delete f.finished.revision; }],
["result not visible after reload", f => { f.reopened.resultVisible = false; }],
["replaced document after reload", f => { f.reopened.document!.id = "replacement"; }],
["reference leaked in task prompt", f => { f.scope.prompt += f.scope.reference; }],
["foreign creator", f => { f.created.dependent.createdByUserId = "foreign"; }],
["unrequested child work", f => { f.reopened.activity.push({ runId: "run", action: "issue.created" }); }],
];
it.each(mutants)("rejects %s", (_name, mutate) => {
const f = dependencyEvidenceFixture(); mutate(f);
expect(gradeTaskDependencyResume(f).some(check => !check.passed)).toBe(true);
});
it.each(["issue_graph_liveness.backstop", "workspace.finalize"])("accepts the same automatic resume when the %s dependency wake recorded its source", source => {
const f = dependencyEvidenceFixture();
for (const p of [f.finished, f.reopened]) for (const r of [...p.dependentRuns, ...p.agentRuns]) r.contextSnapshot.source = source;
expect(gradeTaskDependencyResume(f)).toEqual(TASK_DEPENDENCY_RESUME_CHECKS.map(id => ({ id, passed: true })));
});
it("missing input never becomes a pass", () => { expect(gradeTaskDependencyResume(undefined).every(c => !c.passed)).toBe(true); });
it.each([null, {}, { summary: "Compacted result" }])("accepts the public run projection without duplicate finalization metadata: %j", resultJson => {
const f = dependencyEvidenceFixture();
for (const point of [f.finished, f.reopened]) for (const run of [...point.dependentRuns, ...point.agentRuns]) run.resultJson = resultJson;
expect(gradeTaskDependencyResume(f).every(check => check.passed)).toBe(true);
});
const withHistory = () => {
const f = dependencyEvidenceFixture();
const prior = { ...structuredClone(f.finished.agentRuns[0]!), id: "prior", nativeIssueId: "prior-task",
contextSnapshot: { issueId: "prior-task" }, status: "failed", startedAt: "2019-12-31T23:00:00Z" };
f.startingAgentRuns = [prior];
for (const p of [f.created, ...f.waiting, f.released, f.finished, f.reopened]) p.agentRuns.push(structuredClone(prior));
return f;
};
it("retains completed earlier campaign work while measuring only new runs", () => {
const f = withHistory();
expect(gradeTaskDependencyResume(f).every(check => check.passed)).toBe(true);
expect(f.reopened.agentRuns.map(run => run.id)).toEqual(["run", "prior"]);
});
it.each([
["missing baseline", (f: DependencyEvidence) => { delete (f as Partial<DependencyEvidence>).startingAgentRuns; }],
["foreign baseline", (f: DependencyEvidence) => { f.startingAgentRuns[0]!.agentId = "foreign"; }],
["active baseline", (f: DependencyEvidence) => { f.startingAgentRuns[0]!.status = "running"; }],
["baseline run disappeared", (f: DependencyEvidence) => { f.waiting[0]!.agentRuns = []; }],
["duplicate baseline ID", (f: DependencyEvidence) => { f.startingAgentRuns.push(f.startingAgentRuns[0]!); }],
["premature run hidden as prior work", (f: DependencyEvidence) => { f.startingAgentRuns.push(structuredClone(f.finished.dependentRuns[0]!)); }],
["new unrelated run while blocked", (f: DependencyEvidence) => { f.waiting[0]!.agentRuns.push({ ...structuredClone(f.startingAgentRuns[0]!), id: "extra" }); }],
] as const)("rejects %s", (_name, mutate) => {
const f = withHistory(); mutate(f);
expect(gradeTaskDependencyResume(f).some(check => !check.passed)).toBe(true);
});
it("has no global activity length cap after complete scoped observation", () => {
const f = dependencyEvidenceFixture();
f.reopened.activity.push(...Array.from({ length: 600 }, (_, i) => ({ id: `prior-${i}`, companyId: f.scope.companyId,
entityType: "issue", entityId: f.scope.dependentId, action: "issue.observed" })));
expect(gradeTaskDependencyResume(f).every(check => check.passed)).toBe(true);
});
it("accepts plain or fenced JSON but rejects extra keys and prose", () => {
const s = dependencyEvidenceFixture().scope, body = JSON.stringify({ reference: s.reference, blockerIdentifier: s.blockerIdentifier });
expect(dependencyOutputMatches(body, s)).toBe(true);
expect(dependencyOutputMatches(`\`\`\`json\n${body}\n\`\`\``, s)).toBe(true);
expect(dependencyOutputMatches(JSON.stringify({ reference: s.reference, blockerIdentifier: s.blockerIdentifier, extra: true }), s)).toBe(false);
expect(dependencyOutputMatches(`Completed ${body}`, s)).toBe(false);
});
});