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
5 changes: 5 additions & 0 deletions .changeset/oracles-release-docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/oracles': patch
---

Add initial documentation outlines and agent-first onboarding with npm releases. Update the READMEs with a shared exploration prompt.
348 changes: 32 additions & 316 deletions README.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/eslint-plugin-oracles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ shortcuts that make an oracle pass without enforcing its law, wherever a
syntactic check can see them. They need no type information, so an agent's
post-edit hook can run them on one file quickly.

Install it at the same pkg.pr.new commit as `@tanstack/oracles`. The
`oracles-setup` skill in that package configures it.
Install `@tanstack/eslint-plugin-oracles@latest` alongside
`@tanstack/oracles@latest` from npm. The `oracles-setup` skill in that package
configures it.

## Configs

Expand Down
38 changes: 29 additions & 9 deletions packages/oracles/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
# @tanstack/oracles

Oracle testing for TypeScript: an agent states what your code promises, then
checks your real code against an independent model of those promises.
TanStack Oracles helps you define how software should behave and check real
implementations against those requirements. Use it with a coding agent to find
bugs, tackle difficult changes and build more ambitious software.

It combines property-based testing, model-based testing, fuzzing and mutation
testing. You decide the rules; the agent builds checks that explore generated
inputs and sequences of operations. Independent models judge the behavior, and
deliberately introduced faults test whether the checks notice failures. The
decisions you capture become executable memory for the next agent.

Start with one function, feature or troublesome interaction. Keep the oracle
alongside your existing tests, or ask the agent to port the tests into your
unit-test suite.

## Try it

Open a coding agent in a project you know well and paste this prompt:

```text
Show me what oracle testing with @tanstack/oracles can find in this repository.

1. Find the current commit of TanStack/oracles. Run
`git ls-remote https://github.com/TanStack/oracles refs/heads/main`, and use
the first 7 characters of the hash as <sha>.
2. Install https://pkg.pr.new/TanStack/oracles/@tanstack/oracles@<sha> as a dev
dependency, with this repository's package manager.
3. Read node_modules/@tanstack/oracles/skills/oracles-explore/SKILL.md in full,
and follow it. Use <sha> wherever a skill asks for the commit to pin.
Download https://raw.githubusercontent.com/TanStack/oracles/main/packages/oracles/skills/oracles-explore/SKILL.md

Read it in full and follow it to explore this repository with Oracles.
```

The skill installs the latest npm release of `@tanstack/oracles`. JavaScript
and TypeScript have the strongest integration today. Oracles can already be
used with other languages, and porting the full toolkit to them is a top priority.

<details>
<summary>Tooling and contributor reference</summary>

## Time limits

A mutant copy runs under a wall-clock backstop: `--hang-limit` (60 s by default)
Expand Down Expand Up @@ -71,3 +89,5 @@ The rest of the hooks are older, and each is inert unless its variable is set:
- `ORACLE_GAPS_TEST_UNSUPERVISED` (any value): runs a check without its supervisor, the path that a run took on win32 before the supervisor covered it.
- `ORACLE_GAPS_TEST_HOLD_UNTIL` (a file path): after its done line, the process keeps its exit until the file exists. The hold fails loudly after 60 s and leaves `<path>.unreleased` behind.
- `ORACLE_GAPS_TEST_WARM_PROBE` (a file path): the first config warm-up stands still on a service in the run's process group, which a stop signal ends, and holds the process 200 ms after the signal, as Vitest's handler does. The probe writes the service's pid to the path, so a test can stop the service by name (#139).

</details>
84 changes: 84 additions & 0 deletions packages/oracles/docs/concepts/understanding-oracles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
title: Understanding Oracles
description: Independent models, generated histories and executable design knowledge for coding agents.
---

Oracles brings powerful and sophisticated testing and specification ideas into the everyday work of developing software with coding agents.

> [!NOTE]
> Outline draft for review. One conceptual overview will connect the ideas; deeper sources remain linked rather than becoming a prerequisite course.

## Start with one rule

> The header must never cover the page content.

- Start with Headroom: change the header’s content and size, then check that its wrapper reserves enough space.
- Show the historical bug: the header grew while its wrapper kept the old height.
- Some laws need only a simple constraint. Others need a reference calculation or a small simulation. Start with the simplest model that captures the behavior you want to check.

![Before and after a Headroom fix: the wrapper grows with the header so the header does not cover the page content.](https://raw.githubusercontent.com/KyleAMathews/tanstack-oracles-talk-assets/main/assets/02-header-height-2db4612fefea.gif)

_A historical Headroom bug, reproduced against an earlier version._

## Decide what you want, then check it

- The design loop works out what the software should do: behavior, priorities, performance budgets and tradeoffs.
- The enforcement loop checks whether the implementation does that, and whether the oracle notices when it does not.
- Agents help explore alternatives and their consequences. You make the design decisions, such as how tasks with equal priority should be ordered.

## From examples to promises

- An example test records an answer for one case.
- A property states a rule over a domain; generated inputs explore it.
- A test oracle supplies a judgment about correct behavior.
- Introduce the running example: maintaining the highest-priority open tasks as records change.

## Simulate the behavior simply

- Keep tasks in a plain collection, apply each batch of edits, then filter, sort and take the top ten.
- Production may use indexes, caches and incremental updates. The independent model can recompute the result after each batch.
- Compare exactly the promised result: an empty answer can satisfy filtering, ordering and size constraints without satisfying the query.
- Explain why an independent model can still be mistaken and needs scrutiny.

## Observe behavior where the promise applies

- Law, history, model, driver, observation and check, connected through one example.
- Include intermediate publications or messages when final state alone can hide a defect.
- A disagreement can reveal a bug, a model mistake or an unresolved design question.

## Challenge the oracle too

- Constructed histories ask whether execution reached the important situation. Deliberately create a tie at the tenth slot: add nine higher-priority tasks, then equal-priority B followed by A. Check that A takes the slot, completing A admits B and reopening A restores A.
- Calibrations ask whether the check would recognize a failure. In a separate history where both tied tasks fit, replace `[A, B]` with `[B, A]` and require the ordering check to reject it. A check that compares only length would miss the swap.
- Gap investigations change copies of production code and check whether the oracle notices. An unnoticed fault starts an investigation: improve the histories, model, observations or comparison and run again. Enforcement gaps are not waived.
- Generated exploration, shrinking and replay; what finite testing does and does not establish.

## Make the next change easier

- Follow an optimization that accidentally changes the order of equal-priority tasks. Show the failure and the design decision it points back to.
- Explain how a later human or agent can use that decision when it becomes relevant to their work.
- When a bug slips through, improve the part of the oracle that missed it. More random inputs will not repair a comparison that ignores the relevant result.
- Use the subscriber-message story from Kyle’s DB post: checking message semantics exposed bugs that comparing final maps had hidden.

## Where these ideas come from

- Property-based testing: [QuickCheck](https://www.cs.tufts.edu/~nr/cs257/archive/john-hughes/quick.pdf) and generators.
- Model-based testing: [fast-check’s conceptual overview](https://fast-check.dev/docs/advanced/model-based-testing/) and independent state/behavior judgments.
- Mutation testing: [Stryker’s introduction](https://stryker-mutator.io/docs/) and testing whether tests notice changes.
- Formal methods: [TLA+](https://lamport.azurewebsites.net/tla/tla.html) and specifying designs as models with properties to verify.
- These ideas apply across languages. The current JavaScript/TypeScript tooling is one integration of the method.

## Connect formal verification to production code

- Formal verification establishes properties of a model; an implementation oracle checks those same properties against production code across generated histories.
- Explain how Lean proofs and TLA+/TLC model checking can strengthen the models used to judge production behavior.
- Show the shared model connecting the two: **formal verification ↔ model ↔ production code**.

## Why coding agents change the economics

- Agents make demanding model, generator and investigation work more practical.
- Better checks make it practical to attempt more ambitious algorithms, richer behavior and larger changes.
- Preserve what each investigation teaches, so later work starts with better feedback and a clearer design.
- Read [Kyle’s DB/Oracles post](https://tanstack.com/blog/tanstack-db-1.0-rc1-going-all-in-on-oracles) and the existing [introduction](../intro.md).

<!-- Sources: intro, glossary, model styles, Kyle’s DB post and release-blog draft, and the conceptual sources inspected in the survey. -->
73 changes: 73 additions & 0 deletions packages/oracles/docs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"$schema": "https://raw.githubusercontent.com/TanStack/tanstack.com/main/tanstack-docs-config.schema.json",
"sections": [
{
"label": "Oracles",
"tab": "home",
"children": [
{
"label": "Overview",
"to": "overview"
}
]
},
{
"label": "Get Started",
"tab": "get-started",
"children": [
{
"label": "Try Oracles",
"to": "try-oracles"
}
]
},
{
"label": "Guides",
"tab": "guides",
"children": [
{
"label": "Adopt Oracles in your codebase",
"to": "guides/adopt-oracles"
}
]
},
{
"label": "Concepts",
"tab": "guides",
"children": [
{
"label": "Understanding Oracles",
"to": "concepts/understanding-oracles"
}
]
},
{
"label": "Reference",
"tab": "api",
"children": [
{
"label": "Writing an oracle",
"to": "reference/writing-an-oracle"
},
{
"label": "Gap check and replay",
"to": "reference/gap-check-and-replay"
}
]
},
{
"label": "Project",
"tab": "home",
"children": [
{
"label": "Roadmap",
"to": "project/roadmap"
},
{
"label": "Contribute and participate",
"to": "project/contribute"
}
]
}
]
}
66 changes: 66 additions & 0 deletions packages/oracles/docs/guides/adopt-oracles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Adopt Oracles in your codebase
description: Keep what you learn from one investigation and make future changes easier to check.
---

Start with one important behavior and keep what you learn. An oracle can sit alongside your existing tests, help the next agent understand the design and check a refactor or optimization against the rules you agreed on.

The decisions you capture become executable memory. When a change violates one, the oracle brings the relevant rule and a failing case back into view.

> [!NOTE]
> Outline draft for review. The concrete package, runner and lint integration currently targets JavaScript/TypeScript; identify adaptations for other languages explicitly.

## Choose what to keep

- Begin with [Try Oracles](../try-oracles.md). Oracles is especially useful for thoroughly testing a specific area of your codebase.
- You can ask the agent to port the tests into your existing unit-test suite afterward. Check that each regression fails before the fix and passes afterward.
- To continue using Oracles, keep the oracle and follow the setup below. Preserve the rules it checks, its test cases and the evidence that it catches bugs.

## Finish repository setup

- Pin compatible toolkit packages; configure the test runner and the gap check.
- Add lint presets and agent instructions that point to the installed skills.
- Fit oracle files around the existing suite and workspace structure.
- Connect the validated workflow to CI, with replayable failures and clear ownership.

## Expand by behavior

- Choose another function, feature or interaction that matters to the people using your software.
- Reuse the test machinery while keeping each model independent of the production implementation.
- Track which code each oracle owns, the promises it checks and the remaining limits.

## Make the next change easier

- Use the oracle when asking an agent to refactor, optimize or replace the implementation.
- Keep the design decisions beside the checks, so a later agent can understand why a result matters.
- When review finds a missed bug, investigate why the oracle missed it: the generated cases, simulation, observations or comparison may need to improve.
- If the investigation exposes an undecided behavior, settle that design question before making it a new rule.

## Evolve the design for a new feature

- Use a request for pinned tasks as an example of a new design decision: do pinned tasks count toward the ten-task limit, and where should they appear?
- Let the agent explore the consequences of different choices. Decide which behavior you want before changing the rules.
- Update the law, model and checks together so later implementations preserve the new decision.

## Migrate existing tests

- Identify the obligation behind an existing example or group of tests.
- Express that obligation in an approved law with suitable histories and observations.
- Demonstrate that the oracle detects the original defect or another meaningful violation.
- Remove redundant tests only after their obligations remain covered.
- Keep a concrete before/after conversion example here.

## Add a ratchet

- The shipped preset enforces discipline inside oracle files, including how tests register.
- A broader policy against new ordinary unit tests is a separate repository decision and enforcement setup.
- Describe the chosen scope, treatment of existing tests and gradual conversion process.
- Add a verified configuration/CI recipe before claiming repository-wide enforcement is available.

## Keep improving the checks

- Diagnose disagreements before changing expected behavior.
- Keep fixes, refactors and law changes tied to the evidence appropriate to them.
- Link [Writing an oracle](../reference/writing-an-oracle.md) and [Gap check and replay](../reference/gap-check-and-replay.md).

<!-- Sources: setup, design and review skills; checklist; executed lint-scope probe; Kyle’s release-blog draft. -->
50 changes: 50 additions & 0 deletions packages/oracles/docs/overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Overview
description: Find bugs, tackle difficult changes and build more ambitious software with coding agents.
---

Oracles helps you and your coding agent find bugs, tackle difficult changes and build more ambitious software. Use it with applications, services, tools and libraries.

Define how your software should behave, then check real implementations against those requirements. Your coding agent helps find violations and strengthen the checks as you learn more about the code.

> [!NOTE]
> Outline draft for review. The sections below define the initial page’s coverage.

## Build what you’ve been putting off

Fix bugs you’ve learned to live with. Revisit designs you’ve been afraid to change. Try a more ambitious algorithm. Better verification gives us room to attempt more.

- Coding agents make it cheaper to try different implementations. Oracles helps you check that they do what you intended.
- You decide how the software should behave. The agent builds an oracle to check that behavior across generated inputs and sequences of operations.
- Choose a simple independent model for the behavior: a constraint, a reference calculation or a small simulation. Test whether the oracle notices deliberately introduced faults.

## Start with your own code

- [Try Oracles](./try-oracles.md): paste a prompt into your coding agent. Start with one function, feature or troublesome interaction in a project you know.
- When the agent finds a problem, see the actions that produced it, what should have happened and what the code actually did.
- Optional narrated recording of the same flow; the prompt remains available as text.

## Make the next change easier

- Keep the rules you agreed on and the oracle that checks them, so the next agent can use what you learned.
- Refactor or optimize the implementation while checking that the behavior people rely on still holds.
- When a bug gets through, improve the oracle so later changes are checked for that kind of mistake too.

## Start small

- Use an oracle to thoroughly test one area of your code, then port the tests into your existing unit-test suite.
- Keep an oracle alongside the tests you already have, then [adopt the workflow](./guides/adopt-oracles.md) one behavior at a time.

## Languages and tooling

- The strongest current integration is JavaScript/TypeScript: framework, gap check, lint rules and agent skills.
- Oracles can already be used elsewhere; porting the full toolkit to other languages is a top priority.
- Concrete setup and reference instructions identify the language and tooling they apply to.

## Explore the ideas and the project

- [Understanding Oracles](./concepts/understanding-oracles.md): the testing ideas and their relevance to coding agents.
- [Roadmap](./project/roadmap.md): what better verification could let us build, and what we’re working on next.
- [Contribute and participate](./project/contribute.md): bring difficult code, build the toolkit or join an investigation.

<!-- Sources: package README, intro.md, Kyle’s DB post and release-blog draft, and his audience/language clarification. -->
Loading
Loading