From c64cb8eb6f3714630b2b59387ee32b1bb0c90b93 Mon Sep 17 00:00:00 2001 From: pgermishuys Date: Sun, 20 Sep 2026 15:59:12 +0000 Subject: [PATCH 1/2] test: correct the lifecycle duplication finding, drop the 6 real duplicates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The audit claimed `execution-lifecycle.test.ts` duplicated the `execution-lifecycle/` directory, and projected retiring it for −9.8k lines. That was inferred from `describe`-level overlap — both files name all ten lifecycle entry points — without checking the cases inside. Comparing case bodies instead of names: monolith 309 cases execution-lifecycle/ 82 cases same name in both 13 same name and same body 6 Seven cases share a name but differ in setup or assertions, so they are not interchangeable, and the ~275 monolith-only cases are real coverage. True duplication is 6 cases, not 309. Deleting the monolith would have destroyed most of the lifecycle suite; the projected line saving was never available. Remove the 6 verified duplicates, each confirmed identical after whitespace normalisation, and correct finding 4 and the plan in docs/testing-strategy.md so the next reader is not misled the same way. What remains true is that the file is the largest in the repository and hard to navigate. Its 36 top-level describes group cleanly by subject, so the honest remedy is a reorganization that moves cases rather than deleting them. That is now step 2 of the plan, with no line saving claimed. Refs #183 (task group 11) Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve --- docs/testing-strategy.md | 35 +++++++-- .../src/__tests__/execution-lifecycle.test.ts | 73 ------------------- 2 files changed, 28 insertions(+), 80 deletions(-) diff --git a/docs/testing-strategy.md b/docs/testing-strategy.md index bd81ae40..bd5c7a75 100644 --- a/docs/testing-strategy.md +++ b/docs/testing-strategy.md @@ -102,12 +102,33 @@ while the neighbouring `" type accepts …"` case only echoes a literal and was deleted. Likewise `LifecycleError discriminants` calls the real factory functions, so it stays. -**4. `execution-lifecycle.test.ts` duplicates its own split.** The 10,301-line, -348-case monolith and the 82-case `execution-lifecycle/` directory both cover -all ten lifecycle entry points — `observeSession`, `startExecution`, -`resumeExecution`, `dispatchStep`, `completeStep`, `beforeTool`, -`reconcileExecution`, `handleUserInterrupt`, `validateReconciliationSource`, -`inspectExecution`. The split was started and the monolith never retired. +**4. `execution-lifecycle.test.ts` is a 9.7k-line file, but it is not a +duplicate — corrected.** The original finding claimed the monolith duplicated +the `execution-lifecycle/` directory, because both name all ten lifecycle entry +points (`observeSession`, `startExecution`, `resumeExecution`, `dispatchStep`, +`completeStep`, `beforeTool`, `reconcileExecution`, `handleUserInterrupt`, +`validateReconciliationSource`, `inspectExecution`) at `describe` level. That +inference was wrong: overlap at `describe` level says nothing about the cases +inside. + +Comparing case bodies rather than names: + +| | Cases | +| --- | --- | +| Monolith | 309 | +| `execution-lifecycle/` directory | 82 | +| Same name in both | 13 | +| **Same name _and_ same body** | **6** | + +Seven cases share a name but differ in setup or assertions, so they are not +interchangeable. **True duplication is 6 cases, not 309**, and the ~275 +monolith-only cases are real coverage. The projected "−9.8k lines" was never +available. + +What remains true is that the file is the largest in the repository and hard to +navigate. Its 36 top-level `describe` blocks group cleanly by subject and map +onto the existing directory, so the honest remedy is a reorganization with no +deletion — see step 2 in the plan. **5. Test names encode the implementation plan, not the behaviour.** 31 names across 10 files carry `Spec 22 Unit 1`, `Task 3.2`, `ADR 0004`, `Phase 1`. These @@ -190,7 +211,7 @@ Every finding maps to a step; steps are ordered by value per unit of risk. | 1 | Delete the type-echo cases | 3 | −48 cases, −604 lines, no coverage lost | **done** | | 5 | Rename spec-numbered tests to behaviour | 5 | Readable by newcomers | **done** | | 7 | Cover `packages/adapters/pi` | 9 | Its four api-extractor configs now run under `validate:declarations` | **done, reduced** | -| 2 | Retire `execution-lifecycle.test.ts` into the existing split, keeping only cases the split lacks | 4 | −9.8k lines | open | +| 2 | Split `execution-lifecycle.test.ts` by subject into `execution-lifecycle/`, moving cases rather than deleting them | 4 | Navigable files; no line saving — see the correction in finding 4 | open | | 3 | Make the 23 ambient-state tests hermetic | 2 | Suite becomes trustworthy locally | **done** — #185, #186 | | 8 | Thread an injected filesystem and environment through `run()` to every command | 10 | Prerequisite for the CLI bucket; `compose` gained a seam, `prompt` and `runtime` gained fs-backed config discovery | **done** | | 4 | Promote existing end-to-end coverage into `tests/`, starting with `claude-code/integration.test.ts` and the opencode/opencode2 translation tests | 1, 8 | Real scenarios, refactor-proof | open | diff --git a/packages/engine/src/__tests__/execution-lifecycle.test.ts b/packages/engine/src/__tests__/execution-lifecycle.test.ts index ec964656..ff61f325 100644 --- a/packages/engine/src/__tests__/execution-lifecycle.test.ts +++ b/packages/engine/src/__tests__/execution-lifecycle.test.ts @@ -321,27 +321,6 @@ describe("observeSession (Runtime Store)", () => { expect(result.error.type).toBe("validation"); }); - it("returns validation error for missing workflowInstanceId", async () => { - const store = createInMemoryRuntimeStore(); - const result = await observeSession( - { - workflowInstanceId: "" as typeof wfId, - leaseId, - harnessName: "opencode", - agentName: "loom", - sessionStatus: "active", - }, - store, - ); - - expect(result.isErr()).toBe(true); - if (!result.isErr()) return; - expect(result.error.type).toBe("validation"); - if (result.error.type === "validation") { - expect(result.error.field).toBe("workflowInstanceId"); - } - }); - it("returns validation error for missing leaseId", async () => { const store = createInMemoryRuntimeStore(); const result = await observeSession( @@ -420,26 +399,6 @@ describe("observeSession (Runtime Store)", () => { if (!fetchResult.isOk()) return; expect(fetchResult.value.metadata).toEqual({}); }); - - it("returns persistence error when store fails", async () => { - const store = createInMemoryRuntimeStore({ - failOn: { snapshotRecord: queryError("injected snapshot failure") }, - }); - const result = await observeSession( - { - workflowInstanceId: wfId, - leaseId, - harnessName: "opencode", - agentName: "loom", - sessionStatus: "active", - }, - store, - ); - - expect(result.isErr()).toBe(true); - if (!result.isErr()) return; - expect(result.error.type).toBe("persistence"); - }); }); // --------------------------------------------------------------------------- @@ -7732,38 +7691,6 @@ describe("ReconciliationAuthorizationSource type and constants", () => { // --------------------------------------------------------------------------- describe("validateReconciliationSource", () => { - it("accepts 'user' for 'user-revision-request'", () => { - const result = validateReconciliationSource( - "user-revision-request", - "user", - ); - expect(result.isOk()).toBe(true); - }); - - it("accepts 'runtime' for 'execution-mismatch'", () => { - const result = validateReconciliationSource( - "execution-mismatch", - "runtime", - ); - expect(result.isOk()).toBe(true); - }); - - it("accepts 'review-gate' for 'review-rejection'", () => { - const result = validateReconciliationSource( - "review-rejection", - "review-gate", - ); - expect(result.isOk()).toBe(true); - }); - - it("accepts 'security-gate' for 'security-rejection'", () => { - const result = validateReconciliationSource( - "security-rejection", - "security-gate", - ); - expect(result.isOk()).toBe(true); - }); - it("rejects 'user' for 'execution-mismatch' (must be 'runtime')", () => { const result = validateReconciliationSource("execution-mismatch", "user"); expect(result.isErr()).toBe(true); From 7a8a1e14992d8b1da04b0c6705c56faf80eac12c Mon Sep 17 00:00:00 2001 From: pgermishuys Date: Sun, 20 Sep 2026 16:05:39 +0000 Subject: [PATCH 2/2] docs: derive the monolith-only case count and reconcile step 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeRabbit review on #190: the "~275 monolith-only cases" figure was not derivable from the table above it, and step 2 said "no deletion" while this PR deletes six duplicates. The count is 303 — the monolith's 309 cases less the 6 exact duplicates removed here — and matches the file. Step 2 now covers moving those 303. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve --- docs/testing-strategy.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/testing-strategy.md b/docs/testing-strategy.md index bd5c7a75..0e4ff4aa 100644 --- a/docs/testing-strategy.md +++ b/docs/testing-strategy.md @@ -120,15 +120,16 @@ Comparing case bodies rather than names: | Same name in both | 13 | | **Same name _and_ same body** | **6** | -Seven cases share a name but differ in setup or assertions, so they are not -interchangeable. **True duplication is 6 cases, not 309**, and the ~275 -monolith-only cases are real coverage. The projected "−9.8k lines" was never +Seven of the 13 share a name but differ in setup or assertions, so they are not +interchangeable. **True duplication is 6 cases, not 309.** Those 6 were +removed; the remaining **303** monolith cases have no equivalent in the +directory and are real coverage. The projected "−9.8k lines" was never available. What remains true is that the file is the largest in the repository and hard to navigate. Its 36 top-level `describe` blocks group cleanly by subject and map -onto the existing directory, so the honest remedy is a reorganization with no -deletion — see step 2 in the plan. +onto the existing directory, so the remaining work is a reorganization that +moves those 303 cases rather than deleting them — see step 2 in the plan. **5. Test names encode the implementation plan, not the behaviour.** 31 names across 10 files carry `Spec 22 Unit 1`, `Task 3.2`, `ADR 0004`, `Phase 1`. These @@ -211,7 +212,7 @@ Every finding maps to a step; steps are ordered by value per unit of risk. | 1 | Delete the type-echo cases | 3 | −48 cases, −604 lines, no coverage lost | **done** | | 5 | Rename spec-numbered tests to behaviour | 5 | Readable by newcomers | **done** | | 7 | Cover `packages/adapters/pi` | 9 | Its four api-extractor configs now run under `validate:declarations` | **done, reduced** | -| 2 | Split `execution-lifecycle.test.ts` by subject into `execution-lifecycle/`, moving cases rather than deleting them | 4 | Navigable files; no line saving — see the correction in finding 4 | open | +| 2 | Split `execution-lifecycle.test.ts` by subject into `execution-lifecycle/`, moving its remaining 303 cases rather than deleting them | 4 | Navigable files; no line saving — the 6 duplicates finding 4 identified are already gone | open | | 3 | Make the 23 ambient-state tests hermetic | 2 | Suite becomes trustworthy locally | **done** — #185, #186 | | 8 | Thread an injected filesystem and environment through `run()` to every command | 10 | Prerequisite for the CLI bucket; `compose` gained a seam, `prompt` and `runtime` gained fs-backed config discovery | **done** | | 4 | Promote existing end-to-end coverage into `tests/`, starting with `claude-code/integration.test.ts` and the opencode/opencode2 translation tests | 1, 8 | Real scenarios, refactor-proof | open |