What does oracle-tests do?
A test is only as good as its oracle: where its expected value came from. This skill runs the slice cycle that keeps the oracle in the spec, not in the code.
Hard rules
- No criterion, no test. Every test names a criterion ID from an accepted spec (
[CART-003] …ortest_cart_003_…). Missing criterion or missing example table → stop, run oracle-spec, ask the human. - Expected values are literals from the spec's example tables. Never computed with production code, helpers of the code under test, or a re-implementation of the rule.
- The test author never sees the code under test. If you can see the implementation (you wrote it, or it is in your context), you must not write the tests yourself: delegate to an isolated test author (below). Exception: refactor mode (
[CHAR]tests). - Red before green. New tests must fail with an assertion failure against stubs or current code. A pass or an import/setup error is a violation.
- Tests are locked during implementation. The implementer never edits test files. A test that looks wrong is reported to the human, not "fixed".
- Gates decide, not opinions.
red-check,verify-locked,lint-tests,mutate,tracemust pass before a slice is done. - Survivors and reports never go to the test author. Mutation survivors and failure output contain code and actual values. Only the test-auditor reads them and turns them into behavioral gaps.
Preconditions
.spec-oracle/config.jsonand.spec-oracle/bin/spec-oracle.mjsexist. If not → run oracle-init first.- Below,
someansnode .spec-oracle/bin/spec-oracle.mjs, run from the project root.
Pick the mode
| Situation | Mode | Red check |
|---|---|---|
| New behavior, spec written before code | new | --expect red against contract stubs |
| Changing specified behavior | change | --expect red against current code for new/changed tests |
| Existing code without good tests | cover | spec recovered and confirmed by the human first (oracle-spec recover); --expect green; a red test = possible bug → human |
| Bug report | bugfix | the report becomes a criterion with an example; --expect red (reproduces the bug) |
| Pure refactor, behavior must not change | refactor | characterization tests tagged [CHAR], code visible, --expect green |
The slice cycle
A slice = one user story or spec section, 3–7 criteria. Read references/workflow.md once per session for the full version.
- Criteria and contract. List the slice's criterion IDs, their level (unit / integration / e2e, see
references/levels.md) and example tables. Fix the contract: signatures and types, endpoints and payloads, page-object interface (references/page-objects.md). Contract lives in files the test author may read (types, interfaces, DTOs, OpenAPI, PO interfaces). - Scaffold (
newmode). Implementer creates stubs that compile and return type-correct wrong values (0, empty list, empty string, dummy object), never throw. UI: routes render an empty page, page objects exist with contract locators. - Write tests: delegate to the isolated test author with exactly the message in "Delegation" below.
- Red check.
so red-check --suite <suite> --ids <IDs> --expect red(green forcover/refactor). Each violation goes back to the test author as printed under "What to tell the test author": kind + test name, nothing else. Repeat until it passes. Thenso snapshot-tests. - Implement. Delegate to the implementer (message below). Tests are locked.
- Gates.
so verify-locked- run the related suites (all green)
so lint-tests --changed(no error-severity findings)so mutate(score on changed production lines ≥ threshold)
- Survivors → test-auditor. It reads
.spec-oracle/out/survivors.jsonand the code, and returns behavioral gaps ("no example asserts the total when the subtotal is exactly 100.00"). Spec covers the gap → back to step 3 with that criterion ID and the gap sentence. Spec silent → ask the human, update the spec (oracle-spec), then step 3. Equivalent mutant → auditor records the reason. - Slice audit.
so trace --ids <IDs> --strict, plus the auditor's review of semantic smells (references/smells.md). Commit. Next slice.
Delegation
To the test author
Pass exactly this. Do not describe how anything is computed; do not paste code; do not mention constants from the implementation.
Mode: <new|change|cover|bugfix>
Slice: <name>
Criteria: <ID list>
Spec files: <paths>
Level per criterion: <ID: unit|integration|e2e>
Contract: <paths to types/interfaces/DTOs/OpenAPI/page objects>
Suite and adapter: <suite> / <adapter>
Test location: <directory or naming convention>
Existing test support: <fixture/factory/page-object paths>
Gaps to cover (from the auditor, optional): <behavioral sentences>
How to run it isolated:
- Claude Code: spawn the subagent
spec-oracle:test-authorwith that message. Plugin hooks deny it the implementation and every report. - Other agents:
so isolate --name <slice>creates a sparse worktree with only spec, contract and tests. Start a new session in that folder, load this skill, and give it the message plus "You are the test author." Commit there; merge branchoracle/<slice>back;so isolate --name <slice> --clean. - No subagents and no second session possible: tell the human that isolation cannot be enforced, and ask whether to proceed. If yes, write the tests before opening any implementation file, from the spec and contract only.
To the implementer
Make these tests green without modifying them: <test files>
Criteria: <IDs> in <spec files>
Contract: <paths>; do not change public signatures.
If a test contradicts the spec or looks wrong: stop and report the criterion ID, input, expected per spec, actual, and why. Do not edit the test.
Claude Code: subagent spec-oracle:implementer (hooks block test edits). Others: same message; so verify-locked catches edits.
If you are the test author
Work only from the delegation message. Read, in this order: the spec files; the contract files; existing test support; then references/oracles.md, references/assertions.md, references/levels.md, references/doubles.md, and the adapter for your suite (references/adapter-<name>.md). For e2e also references/page-objects.md.
- One behavior per test; name = ID + behavior in domain words.
- Expected values: copy them from the example table. Every row of the table becomes a case (parametrize).
- Assert the observable outcome at the level's boundary: return value, response body and persisted state, rendered text, emitted event, message sent to a faked third party. Status codes, "is visible", "was called" and "is defined" are never the only assertion.
- Fake only unmanaged boundaries (third-party HTTP, email, payment, clock). Never mock your own modules, DB or store at integration level.
- Page objects: use their intent methods and locators; never put business assertions into them.
- If the contract does not tell you how to observe a criterion, or an example is missing: stop and report what is missing. Do not guess, do not look for the code.
- Never write
ifaround assertions, sleeps,.only, skips, orforceclicks.
If you are the implementer
- Make the tests pass by implementing the spec, not by special-casing test inputs.
- Never edit, rename, skip or delete a locked test; never change fixtures to make a test pass if that changes what the test checks.
- Page-object bodies and locators are yours to fill; their public contract is not.
Reading gate output
red-check violation | Meaning | Action |
|---|---|---|
vacuous | Test passes against the stub / current code | Author strengthens the assertion to the exact spec value |
wrong-reason | Fails by exception, import, type or setup error | Author fixes the test so it reaches its assertion (stubs return wrong values; they do not throw) |
uncovered | No test names the criterion | Author adds it |
suite-error | A test file does not load | Author fixes imports/syntax (tell only the file and "fails to load") |
possible-bug (green expected) | Current code disagrees with the confirmed spec | Ask the human: bug or spec error? Never adjust the test to the code |
verify-locked fails → revert the implementer's test changes, then discuss the test with the human if needed. lint-tests error → the author fixes the named smell. mutate below threshold → step 7.
References
references/principles.md: why, two axes of test qualityreferences/workflow.md: roles, modes, full cyclereferences/levels.md: unit / integration / e2ereferences/oracles.md: allowed and forbidden sources of expected valuesreferences/assertions.md: strength ladder, weak → strongreferences/doubles.md: what to fake, what never to fakereferences/page-objects.md: page objects and component objectsreferences/smells.md: rule catalog oflint-testsreferences/traceability.md: IDs and namingreferences/speed.md: keeping suites fastreferences/adapter-contract.md,references/adapter-*.md: per-runner commands and examples