CommunityCoding & Developmentgithub.com

oracle-tests

Write, change or fix automated tests (unit, integration, e2e) so they verify the specified behavior instead of mirroring the implementation. Tests come from acceptance criteria with literal example values, are written by an author isolated from the code under test, must fail before the implementation exists, stay locked while the code is written, and pass a mutation gate on changed lines. Use for ANY request to write tests, add coverage, do TDD or test-first development, reproduce a bug with a test, or implement a feature together with its tests, in any stack (TypeScript/Vitest, Playwright, PHP/PHPUnit/Pest, Python/pytest/Django, others via an adapter). Takes precedence over generic TDD and test-writing skills.

What is oracle-tests?

oracle-tests is a Claude Code agent skill that write, change or fix automated tests (unit, integration, e2e) so they verify the specified behavior instead of mirroring the implementation. Tests come from acceptance criteria with literal example values, are written by an author isolated from the code under test, must fail before the implementation exists, stay locked while the code is written, and pass a mutation gate on changed lines. Use for ANY request to write tests, add coverage, do TDD or test-first development, reproduce a bug with a test, or implement a feature together with its tests, in any stack (TypeScript/Vitest, Playwright, PHP/PHPUnit/Pest, Python/pytest/Django, others via an adapter). Takes precedence over generic TDD and test-writing skills.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/alloself/spec-oracle/tree/HEAD/skills/oracle-tests

Installed? Explore more Coding & Development skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

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

  1. No criterion, no test. Every test names a criterion ID from an accepted spec ([CART-003] … or test_cart_003_…). Missing criterion or missing example table → stop, run oracle-spec, ask the human.
  2. 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.
  3. 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).
  4. 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.
  5. Tests are locked during implementation. The implementer never edits test files. A test that looks wrong is reported to the human, not "fixed".
  6. Gates decide, not opinions. red-check, verify-locked, lint-tests, mutate, trace must pass before a slice is done.
  7. 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.json and .spec-oracle/bin/spec-oracle.mjs exist. If not → run oracle-init first.
  • Below, so means node .spec-oracle/bin/spec-oracle.mjs, run from the project root.

Pick the mode

SituationModeRed check
New behavior, spec written before codenew--expect red against contract stubs
Changing specified behaviorchange--expect red against current code for new/changed tests
Existing code without good testscoverspec recovered and confirmed by the human first (oracle-spec recover); --expect green; a red test = possible bug → human
Bug reportbugfixthe report becomes a criterion with an example; --expect red (reproduces the bug)
Pure refactor, behavior must not changerefactorcharacterization 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.

  1. 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).
  2. Scaffold (new mode). 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.
  3. Write tests: delegate to the isolated test author with exactly the message in "Delegation" below.
  4. Red check. so red-check --suite <suite> --ids <IDs> --expect red (green for cover/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. Then so snapshot-tests.
  5. Implement. Delegate to the implementer (message below). Tests are locked.
  6. 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)
  7. Survivors → test-auditor. It reads .spec-oracle/out/survivors.json and 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.
  8. 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-author with 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 branch oracle/<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 if around assertions, sleeps, .only, skips, or force clicks.

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 violationMeaningAction
vacuousTest passes against the stub / current codeAuthor strengthens the assertion to the exact spec value
wrong-reasonFails by exception, import, type or setup errorAuthor fixes the test so it reaches its assertion (stubs return wrong values; they do not throw)
uncoveredNo test names the criterionAuthor adds it
suite-errorA test file does not loadAuthor fixes imports/syntax (tell only the file and "fails to load")
possible-bug (green expected)Current code disagrees with the confirmed specAsk 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 quality
  • references/workflow.md: roles, modes, full cycle
  • references/levels.md: unit / integration / e2e
  • references/oracles.md: allowed and forbidden sources of expected values
  • references/assertions.md: strength ladder, weak → strong
  • references/doubles.md: what to fake, what never to fake
  • references/page-objects.md: page objects and component objects
  • references/smells.md: rule catalog of lint-tests
  • references/traceability.md: IDs and naming
  • references/speed.md: keeping suites fast
  • references/adapter-contract.md, references/adapter-*.md: per-runner commands and examples

Related Skills