Repository navigation
refactor(tasks): extract delivery policy - #57475
Conversation
Greptile SummaryThis PR extracts terminal/state-change delivery policy and message formatting from Key changes:
Confidence Score: 5/5Safe to merge — pure refactor with no behavior changes and comprehensive test coverage of the extracted policy surface. All inline policy functions are extracted with verified behavior parity, including edge cases. The only finding is a P2 test-coverage gap for two 'don't suppress' branches in shouldSuppressDuplicateTerminalDelivery, which does not block correctness. src/tasks/task-executor-policy.test.ts — minor test gap in shouldSuppressDuplicateTerminalDelivery coverage.
|
| Filename | Overview |
|---|---|
| src/tasks/task-executor-policy.ts | New pure-policy module extracted from task-registry.ts. All policy functions are behavior-equivalent to their inline predecessors. |
| src/tasks/task-executor.ts | New thin semantic façade over task-registry.ts primitives. Functions delegate 1-to-1 with renamed, more descriptive identifiers. |
| src/tasks/task-registry.ts | Removed inline policy helpers and replaced call sites with imports from task-executor-policy.ts. Behavior-preserving. |
| src/agents/acp-spawn-parent-stream.ts | Import updated from recordTaskProgressByRunId (task-registry) to recordTaskRunProgressByRunId (task-executor). All three call-sites are unaffected. |
| src/tasks/task-executor-policy.test.ts | Good focused tests for the new pure-policy module. Missing two 'don't suppress' branches in shouldSuppressDuplicateTerminalDelivery coverage. |
| src/tasks/task-executor.test.ts | New integration-style tests for the executor façade covering queued→running→completed and running→failed→delivery-status flows. |
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/tasks/task-executor-policy.test.ts
Line: 100-108
Comment:
**Missing "don't suppress" test cases for `shouldSuppressDuplicateTerminalDelivery`**
The test only covers the suppression-active path (`preferredTaskId !== task.taskId → true`). The two "don't suppress" branches aren't tested:
1. When `preferredTaskId === task.taskId` (current task _is_ the preferred one → should return `false`)
2. When `preferredTaskId` is `undefined` (no competing task found → should return `false`)
These fall naturally out of the new signature change (the registry now pre-computes `preferred?.taskId` before calling the policy). Adding explicit assertions here would guard against future regressions in those paths:
```
// Current task is preferred → do not suppress
expect(
shouldSuppressDuplicateTerminalDelivery({
task: createTask({ runtime: "acp", runId: "run-dup" }),
preferredTaskId: "task-1", // same as default taskId
}),
).toBe(false);
// No competing task found → do not suppress
expect(
shouldSuppressDuplicateTerminalDelivery({
task: createTask({ runtime: "acp", runId: "run-dup" }),
preferredTaskId: undefined,
}),
).toBe(false);
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Merge branch 'main' into pr2/task-delive..." | Re-trigger Greptile
| expect( | ||
| shouldSuppressDuplicateTerminalDelivery({ | ||
| task: createTask({ | ||
| runtime: "acp", | ||
| runId: "run-duplicate", | ||
| }), | ||
| preferredTaskId: "task-2", | ||
| }), | ||
| ).toBe(true); |
There was a problem hiding this comment.
Missing "don't suppress" test cases for
shouldSuppressDuplicateTerminalDelivery
The test only covers the suppression-active path (preferredTaskId !== task.taskId → true). The two "don't suppress" branches aren't tested:
- When
preferredTaskId === task.taskId(current task is the preferred one → should returnfalse) - When
preferredTaskIdisundefined(no competing task found → should returnfalse)
These fall naturally out of the new signature change (the registry now pre-computes preferred?.taskId before calling the policy). Adding explicit assertions here would guard against future regressions in those paths:
// Current task is preferred → do not suppress
expect(
shouldSuppressDuplicateTerminalDelivery({
task: createTask({ runtime: "acp", runId: "run-dup" }),
preferredTaskId: "task-1", // same as default taskId
}),
).toBe(false);
// No competing task found → do not suppress
expect(
shouldSuppressDuplicateTerminalDelivery({
task: createTask({ runtime: "acp", runId: "run-dup" }),
preferredTaskId: undefined,
}),
).toBe(false);
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/tasks/task-executor-policy.test.ts
Line: 100-108
Comment:
**Missing "don't suppress" test cases for `shouldSuppressDuplicateTerminalDelivery`**
The test only covers the suppression-active path (`preferredTaskId !== task.taskId → true`). The two "don't suppress" branches aren't tested:
1. When `preferredTaskId === task.taskId` (current task _is_ the preferred one → should return `false`)
2. When `preferredTaskId` is `undefined` (no competing task found → should return `false`)
These fall naturally out of the new signature change (the registry now pre-computes `preferred?.taskId` before calling the policy). Adding explicit assertions here would guard against future regressions in those paths:
```
// Current task is preferred → do not suppress
expect(
shouldSuppressDuplicateTerminalDelivery({
task: createTask({ runtime: "acp", runId: "run-dup" }),
preferredTaskId: "task-1", // same as default taskId
}),
).toBe(false);
// No competing task found → do not suppress
expect(
shouldSuppressDuplicateTerminalDelivery({
task: createTask({ runtime: "acp", runId: "run-dup" }),
preferredTaskId: undefined,
}),
).toBe(false);
```
How can I resolve this? If you propose a fix, please make it concise.* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
* refactor(tasks): add executor facade * refactor(tasks): extract delivery policy
Summary
src/tasks/task-registry.ts, mixing persistence/orchestration code with product policy.src/tasks/task-executor-policy.ts, added focused policy tests, and kept registry behavior wired through the new module.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause / Regression History (if applicable)
git blame, prior PR, issue, or refactor if known): N/ARegression Test Plan (if applicable)
src/tasks/task-executor-policy.test.tssrc/tasks/task-registry.test.tsUser-visible / Behavior Changes
None.
Diagram (if applicable)
Security Impact (required)
Yes, explain risk + mitigation:Repro + Verification
Environment
Steps
Expected
Actual
Evidence
Human Verification (required)
pnpm test -- src/tasks/task-executor-policy.test.ts src/tasks/task-registry.test.tspnpm buildReview Conversations
Compatibility / Migration
Risks and Mitigations
src/tasks/task-registry.test.tsstill exercises the integrated flow.AI-assisted: yes. Fully tested on the touched surface.