Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions docs/testing-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,34 @@ while the neighbouring `"<Type> 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 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 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
Expand Down Expand Up @@ -190,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 | 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 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 |
Expand Down
73 changes: 0 additions & 73 deletions packages/engine/src/__tests__/execution-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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");
});
});

// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
Expand Down
Loading