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.
Open a coding agent in a project you know well and paste this prompt:
Show me what oracle testing with @tanstack/oracles can find in this repository.
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.
Tooling and contributor reference
For npm releases, see the release instructions.
-
packages/oracles(@tanstack/oracles): the oracle framework, its skills and docs, and theoracle-gapsCLI. The CLI lists the production behavior that a project's owning oracles leave unexercised or unjudged. A project runs it asoracle-gaps --package <dir> --source <src/x.ts,...>, with--env-prefixset to the prefix that the project passes toconfigureOracles.--config <file>, relative to--package, selects the Vitest config; without it, the run loads the config that Vitest discovers, in the package's directory or else the nearest parent directory that has one, and the baseline output names the config it loaded. Each run writes its report to a directory of its own in the OS temp directory (or to--out), and prints its path. The daemon's state and the one-file bundles of workspace dependencies are in the OS temp directory too, keyed by the package, which the OS cleans: a state that is gone is a cold start. A run leaves nothing in the repository. While it runs, its capture setup and Vitest configs are in<dir>/.oracle-gaps-<pid>/, which it removes when it ends, and its copies of the test files exist only in memory, so a Vitest run started during a check finds none of them. A run that is killed before it cleans up leaves that directory, and the next run removes it.While one copy of a test file runs for 30 s or more, the CLI prints
oracle-gaps: busy <mutant id> in <test file> for <n>severy 30 s. A run of many fast copies prints none, and a check through--daemonprints its heartbeats only when the check ends. No wall-clock limit decides an outcome. A copy is cut in one of three ways: by its call count, when it runs past its call budget (spin); by its state, when it makes no progress (no progress: none of its test's own timers is due before its backstop, and none of its test's own I/O is pending, while timers and I/O the runner keeps for itself, such as Vitest's task-update timer or a write that forwards the test's console output, do not count); or by the backstop, when it runs past--hang-limit(60 s by default) plus 3 s per second of its file's unmutated time (backstop). A spin and no progress are kills: the built-in lawbounded workorno progressfails on the route of the test that was running, so on a reproducible route the mutant iskilled, and on another route the next owner's copy still runs. The copies of one mutant share a work budget, counted in site evaluations and not in time: the larger of 100,000 and ten times their owner files' unmutated work. The copy whose work passes it failsbounded workon the routes of its tests that did that work, and no later copy runs. Only the backstop is a gap: the mutant is atimeout, with(cause: backstop)on its gap line anddetailinresults.json, and no later copy runs. A kill in an earlier owner still decides.--first-limitand--mutant-limitare retired: they are checked and noted, and change nothing.The report, on stdout and in
summary.md, leads with the baseline: each test file's result with its test counts (ordinary files too), and for a failing file its failing test, its error, the law and counterexample of a law violation, and areplay:command. A test of an oracle file that fails with no mutant active (a failing law) judges nothing: it is left out, as a nondeterministic test is, and the passing tests of its file still judge the mutants the file owns; it keeps its reach and its work. A test of adescribewhosebeforeAllorafterAllthrows is a failing law too. An owner file that fails outside its tests (it does not load, or a file-level hook throws) is broken, and judges nothing. A mutant that no deterministic passing owner test reached, held by a failing law that reached it or by an owner file that judges nothing, and that nothing kills, is ablockedgap whose directive names what it waits for. Ablockedline names each failing law by its file and test names (or a broken file by its path),results.jsonlists each failing file'slaws, and the report says it is provisional. With--only <id,...>, the baseline runs only the owners of the selected mutants. Acrashedgap is not a kill: production threw where no law judged it, and the error is on the gap's Detail line insummary.mdand in itsdetailinresults.json. Record the error in the driver, and state the law that decides that input's outcome.A survivor that changed no observation but made a test do more work is
extra-work: the mutant deleted a shortcut that exists only for speed, such as an early return or an assignment in place of a slower call. A test's work is the number of site evaluations that its instrumented production code makes (calls, comparisons,ifs, and each pass of a loop's condition), a deterministic count, never a time. Only a test on a route thatoraclePropertyregisters for production (a fixed seed, a fixed history, a case, or the random campaign) judges work, since only such a test can carry a bound. A test whose work varied between the two unmutated runs, or whose count could follow the clock, as a polling or a deadline loop's does, does not judge work, so a work-bound kill replays on an idle machine. A count can follow the clock when the test, its driver, or production makes a real timer or interval (through the globals,node:timers, ornode:timers/promises), reads a clock (Date.now(),new Date(),performance.now(),process.hrtime), or holds I/O open. A wait of one turn (setImmediate) reads no clock. Reads that the test runner, fast-check, or the oracle framework makes do not count, and neither do reads under a fake clock. The gap's directive names the first such test, its work before and after, and the bound that rejects the mutant. Declare it on the owning property, for exampleoracleProperty({ ..., work: { ratio: 1.1 } }): a mutant whose work in one of the property's tests is more thanratiotimes the unmodified code's work there is killed under lawwork bound.ratiois a finite number of at least 1, read to the hundredth and compared exactly, and 1 rejects any extra work. The bound is the property's, so it judges every test the property registers, though the directive names one of them. A plain Vitest run has no unmodified run to compare with, so there the bound judges nothing. The count does not see work without a site, such as a plain assignment, afor...ofpass, or a builtin's own work, so a call to a builtin counts once, whatever it costs. Probe code is never work: a site in probe-only code (the probe guard, a probe statement, or a probe helper) counts nothing, so a mutant that only enters probe code does no extra work. Where a shortcut's cost is in such a builtin (Object.definePropertyand the like), make that cost an explicit observation of the driver, such as a count of those calls, and let a law judge it, in place of a very tight work bound. Work is counted per test, not per history: a test that runs many histories, such as ageneratedunit, is judged by their sum, so a slowdown in a few of its histories is diluted, and a constructed or fixed history isolates it. An authored mutant's copy is not instrumented, so a work bound does not judge it.Every line the CLI writes for a check, on stdout and stderr alike, starts with
oracle-gaps:and its kind, so an agent can act on the results as they stream withgrep '^oracle-gaps: ', and filter one kind:Kind Line configoracle-gaps: config vitest.config.ts, ororacle-gaps: config none, Vitest's default discoverybaselineoracle-gaps: baseline pass tests/a.test.ts: 3 tests,oracle-gaps: baseline fail tests/b.test.ts: 1 of 2 tests failedbaseline(decisive, before any mutant)oracle-gaps: baseline all 4 oracle files pass, ororacle-gaps: baseline 1 of 4 oracle files failed (provisional)blockedoracle-gaps: blocked <file> > <test> fails with no mutant active, so it judges nothing: …, one per failing lawgaporacle-gaps: gap <kind> L<line> <id> <change>, and for atimeout(cause: <cause>)progressoracle-gaps: progress judged 25 of 120 mutants: 7 gaps so far, 18 not gapsbusyoracle-gaps: busy <mutant id or baseline> in <test file> for <n>snoteoracle-gaps: note …: the--hang-limitnote, Vite's own messages (note vite: …), ordinary files left out, the provisional count, unowned counts, the results' path, and where the tests' console output went (note test output in <path>)summaryoracle-gaps: summary <run id>: 120 mutants, 98 killed, 12 gaps, 10 unowned (warnings). …legendoracle-gaps: legend <class>: <what it means and what to do>, once for each class of gap the run foundfunctionoracle-gaps: function fn <name> (<source>) (owners: <files>), the heading over that function's gap lineserrororacle-gaps: error <message>: a bug in oracle-gaps, not in your oracle; its stack is in <path>/error.log, once, before the done line of an internal errordone(last)oracle-gaps: done completed, 12 gaps, report <path>/summary.md((provisional)after the count when an oracle file failed),oracle-gaps: done refused[, report <path>],oracle-gaps: done error, log <path>, ororacle-gaps: done stopped (SIGINT)Only these lines have no prefix: the lines indented under a failing baseline file (
failing:,law:,counterexample:,replay:), a refusal'srefused:andfix:block on stderr,--help's usage text, and lines that Node, V8, esbuild, or Vite print on the CLI's streams (a warning, V8's out-of-memory block, esbuild's error block). The CLI writes no blank line of its own. A path in a line, such as the output directory, prints a line break or another control character as its\uXXXXescape, so it cannot end the line. The done line is the last line of both stdout and stderr, once each, for every ending, and its status matches the exit code. A test's own output to the process's stdout and stderr goes totest-output.login the output directory, which a note names;summary.mdholds the report for reading. A run through the daemon prints the same lines, at the end of its check. The first line of a check, on both streams, isoracle-gaps: note log <out>/stream.log: the run writes its stderr lines to that file too, in order, so a check started in the background can be read there while it runs and after it ends. A cold run's lines reach the file as they are printed; a run through--daemonprints its lines at the end of its check, so the file fills then.--helpis not a check, so its usage text has no prefix and no done line.--stop-daemonprints nothing.For contributors: the
ORACLE_GAPS_TEST_environment variables are test-only hooks for the CLI's own oracle, not settings for users. Each is inert unless set, and none changes an outcome by itself.ORACLE_GAPS_TEST_HOLD_UNTILnames a file: after its done line the run keeps its exit, and its output claim, until the file exists, so a test can send a stop or start a second run before the run ends. A hold the CLI cannot release is marked by a<file>.unreleasedfile.ORACLE_GAPS_TEST_WARM_PROBEmakes the first config warm-up wait where a stop signal can reach it.ORACLE_GAPS_TEST_STOPnames a file whose appearance makes the CLI take a stop as a SIGINT would (the win32 stop, which has no signal to deliver).ORACLE_GAPS_TEST_STARTEDnames a file that the CLI writes as its first project statement, before any project module loads, so a test can tell a stop that came before the CLI started from one that came during its loads.ORACLE_GAPS_TEST_PAUSE_AFTER_STARTED(any value) holds the CLI right after the started file is written until the CLI has kept a stop signal (or, withORACLE_GAPS_TEST_STOP, until that file exists), so a stop sent on seeing the file lands during the CLI's loads. The stop releases the hold, not a time; a hold that sees no stop within 60 s fails the run loudly.ORACLE_GAPS_TEST_PAUSE_ATnames one point at which the CLI holds:note(after the note line is written, before the check starts), andchild(a supervised child, before it writes anything; it waits on timers, so its orphan watchdog keeps running). A hold atnoteblocks synchronously. At either point the CLI writes the fileORACLE_GAPS_TEST_PAUSE_MARKER(when set) and waits until the fileORACLE_GAPS_TEST_PAUSE_UNTILexists.ORACLE_GAPS_TEST_PAUSE_MARKandORACLE_GAPS_TEST_PAUSE_ARM(daemon points):ORACLE_GAPS_TEST_PAUSE_ATalso namesdaemon-reply(holds a daemon's reply after the check) anddaemon-read(holds its first connection unread, onceORACLE_GAPS_TEST_PAUSE_ARMnames an existing file;daemon-replytoo, whenORACLE_GAPS_TEST_PAUSE_ARMis set) anddaemon-check(holds a daemon's first armed check before it runs, until the fileORACLE_GAPS_TEST_PAUSE_RELEASEnames exists). The blocked process writes its pid toORACLE_GAPS_TEST_PAUSE_MARK, whole (a temp file, then a rename), and the test parses the pid as a positive integer before it sends any signal, so no signal is needed to pause on win32.ORACLE_GAPS_TEST_WAIT_MARKnames a file a check's request writes when its daemon has sent nothing forORACLE_GAPS_TEST_WAIT_MS, the point at which the CLI would run the check cold. With the mark set, the request writes it there and keeps waiting, so the test acts on the CLI's wait, not on the clock.ORACLE_GAPS_TEST_WAIT_MS(milliseconds, default 60000) is the CLI's wait for a daemon to start or to close, and for a daemon that holds its check to send anything; a test shortens it to outlast a paused daemon. It is a test-only knob, not a setting for users.ORACLE_GAPS_TEST_SERVED_MARKnames a file the daemon writes its pid to after it answers a check, so a test can tell which daemon served an earlier check (the warm daemon that a later check's pause must match).ORACLE_GAPS_TEST_UNSUPERVISEDruns a POSIX check unsupervised, the path win32 takes (no supervisor writes the run's--out), so the daemon request of a run that names no directory is reached on every platform.ORACLE_GAPS_INTERNAL_SUPERVISEDis set by a supervisor for the child it starts (its own pid). It is internal, not a user setting: the child kills its own process group only when the supervisor that started it has gone and the child leads that group.ORACLE_GAPS_TEST_TORN_ROWSnames a directory where each batch's watchdog counts its polls, and a batch's closing row is held half written until the watchdog has polled twice. The directory holds a.begunmarker per batch and a.reachedor.unreachedmarker per hold (.unreachedafter 60 s with no two polls).ORACLE_GAPS_TEST_SAMPLESnames a directory where each worker's idle sampler writes, to<pid>-<threadId>, how many times it has judged the running test. A witness holds its own I/O open until that count rises, so the hold is a count and not a time.ORACLE_GAPS_TEST_RUNNER_WRITEnames a directory. Through each test, the runner itself holds one write pending on a local pipe whose reader never reads, as a write that forwards a test's output can stay pending on win32. A copy that goes idle while that write is pending writes anidle-<pid>-<threadId>marker there.ORACLE_GAPS_TEST_RUNNER_TIMERnames a directory. Through each test, the runner itself keeps one 100 ms interval running, made through the globalsetIntervalas Vitest's task-update timer is. A copy that goes idle while it runs writes anidle-<pid>-<threadId>marker there.
A few endings print no done line, or one more line: a SIGKILL of the CLI, or a signal that comes while Node is still starting the CLI, before its first line runs (a few tens of milliseconds), ends it with no done line. When the run's own process ends without its ending, by a signal sent to it rather than the CLI or by a crash (a V8 out-of-memory abort is a SIGABRT), the CLI writes
oracle-gaps: done error, the run's process exited with <signal or code>and exits 3; after an out-of-memory crash the line says to give Node more memory (NODE_OPTIONS=--max-old-space-size=<MB>) or to run fewer--contexts. An internal error prints oneoracle-gaps: errorline with its message, its line breaks escaped, and its stack goes toerror.log. A config's syntax error is refused with its first error; a syntax error in a module the config imports lets esbuild print its own error block before the refusal.Exit codes: 0 the check completed, whatever its gaps (its last line is
oracle-gaps: done completed, …); 2 the run was refused, withrefused:andfix:on stderr; 3 an internal error of the CLI; 130 or 143 stopped by SIGINT or SIGTERM.The check runs in a process group of its own, with every Vitest worker and every process that a test starts, except one started detached in a session of its own (as some browser drivers are). On SIGINT or SIGTERM the CLI signals the whole group, kills what is left 2 s later, and exits 130 or 143. A check through the daemon (
--daemon) runs in the daemon's process; stop it withoracle-gaps --stop-daemon --package <dir>. While a check waits or runs there, the daemon tells the CLI whenever a running copy is polled. A daemon that sends nothing for 60 s has stopped answering: the CLI printsoracle-gaps: note the package's daemon sent nothing for 60 s; this check runs coldand runs the check in its own process, which reports what the daemon would have. The daemon keeps running: it drops the abandoned check before it runs, or at its next phase, so it writes nothing more into that run's output directory, and serves the next check. On Windows, which has no process groups, the run is not supervised.A check through the daemon reuses a run while its inputs are unchanged: the modules the run loaded, and the files in the package that its tests read through
fs(readFileSync,readFile,existsSync,statSync, andfs/promisesreadFileandstat), each by the content that the run read. A run that an edit overlapped, because a file changed after the run read it, is not reused. A directory that a test stats or tests for is an input as a directory, not by its content.Two kinds of input are not tracked yet. A Vite plugin whose output depends on anything but a module's text, such as a sidecar file that it reads, can make the daemon serve a run that read the plugin's old output. And the daemon's environment is fixed when it starts, so an environment variable that a later check sets does not reach the daemon's runs. After such a change, run the check cold (without
--daemon), or stop the daemon withoracle-gaps --stop-daemon --package <dir>. The maintainer decided on 2026-11-13 that the daemon tracks both and restarts when they change; a later release does that.These reads are no input, so an edit to the file alone does not rerun the tests that read it: a read outside the package or under
node_modules; a read from a worker thread or child process that the test starts; and a read through anyfsorfs/promisesfunction other than the six above, or through one of those six given a file descriptor. That catch-all includes, for example,readdir,opendir,glob,globSync,createReadStream,realpath,lstat,access,open,read,readSync,readv,fstat,fstatSync,copyFile,copyFileSync,cp,cpSync,openAsBlob,statfs,readlink, the callbackstat,exists,watch, andwatchFile, and thefs/promisesreaddir,opendir,glob,lstat,realpath,readlink,access,open,copyFile,cp,statfs, andwatch. Run the check cold (without--daemon) after an edit to a file read that way. A later release records all of them exceptwatchandwatchFile, which wait for future changes and stay no input (maintainer decision, 2026-11-13, withwatchFilein the family ofwatch).
A calibration's history selects an existing input directly:
calibrations: [
{
name: 'drops the committed row',
law: 'durable publication',
history: { constructed: 'a committed write' },
corrupt: dropCommittedRow,
},
]Generated sources accept { constructed: name } and { fixed: name }.
Enumerated sources accept { enumerated: index } (zero-based) or
{ enumerated: name }, using label or the framework's default data label.
Unknown or duplicate names, invalid indices, and incompatible source kinds fail
registration before a driver runs.
The selected clean run must pass and actually enter every state the history declares. When the property declares states, every state the clean run enters must also be declared. The mutation must apply, and the check must reject it under exactly the named law. A failed clean run, missing reach, inapplicable corruption, passing mutant, wrong-law rejection, or driver setup error fails the calibration directly. It never searches another history.
Mutant drivers use the same verdict rules as ordinary histories. A violation at
a recorded checkpoint decides before a later driver error. A controlled clock
that exceeds its timer bound reports bounded clock, unless an earlier recorded
violation already decides.
An optional difference: string | RegExp also requires the violation's
difference to contain the text or match the pattern. The law is checked first.
A bound mismatch fails directly. An unbound mutant driver can still try a later
candidate, as it can for a wrong law.
A selected construction uses one deterministic seed derived from the property
id and calibration name. Inserting or reordering other calibrations leaves this
seed unchanged. Each driver execution builds from that seed afresh and resolves
its plan once. This preserves builder-created metadata, including WeakMap
associations, and avoids reusing consumed plans. Fixed and enumerated selectors
preserve the existing history's identity and semantics. Use resolve to create a
fresh mutable execution plan from those histories for each driver run. Each
calibration remains on the calibration route, so a failed self-check is a
framework error in the gap report. Campaign units now support UNIT replay.
Bound calibrations still use their stable name-derived seed; fresh-seed
calibrations and their replay support remain follow-up work.
For automatic forced-probe controls, opt a state into direct selection:
probeHistories: {
'committed write': {
notEntered: { fixed: 'no writes' },
// Optional: entered: { constructed: 'a committed write' }
},
}The clean-entered history detects the probe forced not entered. If entered
is omitted, exactly one construction must declare the state in enters.
The clean-not-entered history detects the probe forced entered and always needs
an explicit selection. Neither control may silently disappear.
During consumer migration, an unbound authored calibration or entirely unbound
probe state retains candidate search. Registration warns once per property per
process, naming its unbound calibrations. Collect-only runs (ORACLE_MANIFEST)
stay silent and do not consume that warning. Bind both probe controls together with
probeHistories. Search will be removed after consumers migrate, before the
first npm release.