# @tanstack/bug-search (private) A benchmark for oracles: which of a library's known bugs does an `@tanstack/oracles` oracle catch? Each bench repo is a library at a cutoff commit, with a private answer key of bugs that were fixed after the cutoff. This package is not published. The answer keys are not in this repository. ## Commands Run from this directory with `node src/bin.ts ` (Node 22.18 or later runs the TypeScript directly), or `pnpm bug-search `. | Command | What it does | | ------------------------------------ | --------------------------------------------------------------------------------------------- | | `snapshot NAME... [--force]` | Clones the manifest URL, archives the cutoff into `snap/`, runs the setup commands, seals it. | | `verify NAME...` | Checks a key: each repro exits 1 on the snapshot and on `^`, and 0 on ``. | | `prefix NAME --oracle DIR [options]` | Which of NAME's known bugs the oracle files under DIR catch (below). | | `help`, `-h`, `--help` | The usage. | Every command takes `--bench DIR` (the manifests; default `bench/`), `--cache DIR` and `--keys DIR`. Each command accepts only its own options; any other option, a missing argument or a bad value names the problem and exits 1 before anything runs. An unknown command, or none, exits 2. `snapshot` prints `: created`, or `: up-to-date` when the snapshot already matches its manifest. A snapshot made from another url, cutoff or setup, or one whose setup never finished, is refused until `--force` rebuilds it. `verify` prints one line per bug, `OK` or `FAIL` with the reason, and exits 1 when any bug fails. With several repos, each repo's lines start with `# `. `prefix` options: | Option | Meaning | | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | | `--oracle DIR` | The oracle files: every `*.oracle.property.test.{ts,js,mjs,…}` under DIR, outside `node_modules`. | | `--seed N` | The exploration's campaign seed (1). | | `--judge claude\|cache-only\|none` | Who confirms a flip (claude: Haiku). `cache-only` answers only from earlier verdicts; `none` counts every stable flip. | | `--placebo` | Also apply the rules to each (fix^^, fix^) pair, a pair without the fix. | | `--quiet` | Counts and bug ids only, no key text; refused for a repo outside `train`. | | `--timeout-s S` | Seconds one oracle test may run (60). | Environment: `BUG_SEARCH_CACHE` and `BUG_SEARCH_KEYS` (used when the flag is not given), `BUG_SEARCH_REPRO_PROCS` (a cap on repro processes; no cap when unset) and `AR_JUDGE_PARALLEL` (judge batches at once, 6). ## Repos The repos come from `bench//manifest.json`. Any field not listed here is an error. | Field | Meaning | | ---------------------- | ------------------------------------------------------------------------------------------------------ | | `name` | The directory name. | | `url` | The git URL that `snapshot` clones. | | `cutoff` | The full sha of the snapshot. | | `split` | `train` or `test`. | | `kind`, `area`, `hint` | What the library is, what to search, how to load it. | | `tsx` | Run repros with the snapshot's tsx loader. | | `setup` | Shell commands run inside `snap/` after the archive. | | `weak`, `contaminated` | Optional: bug ids to report apart. | | `treeSetup` | Optional: shell commands run in each fix-commit tree (`$SNAP` and `$TREE` set). | | `live` | Optional: fixes for bugs still present upstream (`{"base", "fixes"}`; see docs/adding-a-benchmark.md). | | `setupTimeoutSec` | Optional: seconds one `setup` or `treeSetup` command may run (900). | `treeSetup` is for files the repo ignores in git but its code needs, which a `git archive` tree lacks. z-schema's generated metaschemas are one: without `mkdir -p src/schemas && cp -n "$SNAP"/node_modules/.zs-schemas/*.json src/schemas/` repros crash on the fix trees. ## Answer keys A repo's key is `//key/ANSWER-KEY.md`, with its repros at `//key/repro/.mjs`. `` is `--keys`, else `BUG_SEARCH_KEYS`, else `~/.local/share/bug-search/keys`. A bug line starts with its id (a capital letter and digits) and a bar: `B1 | behavior | example | | date`. Its fixes are the 7-to-40 character hex words after the first bar that start a commit of the clone. A line may end with `| weak` or `| contaminated`, bare or with a reason in parentheses. An indented or bulleted line that looks like a bug line is reported, not read. A repeated id is an error. A bug is unusable, and is listed apart and left out of the total, when no fix sha names a commit of the clone, or when its only fix is a root commit. ## Runtime state Everything the runner writes goes under the cache: `--cache`, else `BUG_SEARCH_CACHE`, else `$XDG_CACHE_HOME/bug-search`, else `~/.cache/bug-search`. ``` /repos//full full clone (history for fix commits and HEAD) /repos//snap the cutoff, with setup run, sealed /repos//snap.done.json written only after setup succeeds: the setup inputs and the sealed digest /trees/-/ git archive of a commit, node_modules linked from the snapshot (the hash covers the snapshot's path, its seal and treeSetup) /prefix//runs/.json one oracle run's record /prefix/judge// the judge's request files and verdicts /prefix/scratch/ each batch's scratch folders, removed when it ends /tmp/repro/ each repro's TMPDIR ``` ### Sealed snapshots and trees A snapshot is sealed when its setup finishes. The seal (`src/seal.ts`) hashes every file and symlink under `snap/` except `node_modules` directories, records each file's sha256 in `snap.done.json`, and then removes the write bits (execute bits stay). `verify` and `prefix` recompute the digest first; on a mismatch they stop and name the changed, added and removed files. A tree is built only from a finished snapshot. It is a `git archive` of the commit with the snapshot's `node_modules` linked in, read-only once built. ## prefix For each usable bug, `prefix` explores the commit before each of its fixes (fix^) with the oracle files: one campaign at `--seed`, with each oracle's run budget multiplied by 50. Each failure it finds (a law, its shrunk history, the expected and actual values) is replayed exactly, by its property, unit, seed and path, on the snapshot and on the fix. - **Stable flip**: a found failure whose replay fails on the snapshot and passes on the fix, with none of those runs unable to run. - **Caught**: with a judge, the judge confirms one of the bug's stable flips (at most 5, one per law before any law gets a second), shown its law, history, expected and actual values, with the bug's key line as the only candidate. With `--judge none`, any stable flip counts. The report has one line per bug (`CAUGHT` or `missed`, its flips, how many the judge confirmed of those it was shown, failures not on the snapshot and failures that still fail on the fix), then `oracle catches N/M bugs (…)`, `caught `, the placebo line with `--placebo`, and `unusable : `. A request the judge did not answer is counted as unanswered. **Placebo.** With `--placebo` the same rules run on (fix^^, fix^), a pair without the fix. A pair is skipped and counted when its fix^ is a fix the key names (that pair holds a fix), or when fix^ is a root commit (no fix^^). A bug that flips here flips without its fix: noise. **The run cache.** Each oracle run's record is kept under a key of the oracle files and their contents, the runner's settings, the tree's version and the run (the exploration seed, or the replayed failure). The same command again runs nothing; a changed oracle file, setting or seed runs again. A run stopped by the time limit, or whose vitest crashed, is not kept; a snapshot built again runs everything again. The judge keeps its own verdicts, so the same flips are not asked twice. **Time limit.** One oracle test may run `--timeout-s`; a batch of runs ends at its limit, and its own workers are stopped. A run that hit the limit, or whose files failed to load, is reported as unable to run. ## Laws Each module's design is captured as laws, enforced by its oracle files in `tests/oracle/`: the bench inputs (`bench-manifest`, `bench-key`), the snapshot and its trees (`bench-snapshot`, `bench-seal`, `bench-trees`, `bench-live`), processes and repros (`proc`, `repro`, `verify`), the judge (`judge`), the prefix plan, runner and scorer (`prefix-plan`, `prefix-run`, `prefix-runner`, `prefix-score`), and the commands end to end (`cli`, `cli-cache`). Run them with `pnpm test`. The gap check judges whether the laws notice a change to the code they own, with one config per area (`tests/oracle/vitest.*.gaps.config.ts`). From the repository root, after `pnpm --filter @tanstack/oracles build`: ``` node packages/oracles/oracle-gaps/index.mjs --package packages/bug-search \ --source src/cli.ts,src/prefix/command.ts \ --config tests/oracle/vitest.cli.gaps.config.ts --pool forks ``` `--source` takes one comma-separated list. The CLI and prefix-runner oracles change the working directory, so they need `--pool forks`. ## Setup time limits Each `setup` and `treeSetup` command may run for the manifest's `setupTimeoutSec`, else `BUG_SEARCH_SETUP_TIMEOUT_SEC`, else 900 seconds. On a timeout the command's whole process group is killed, and the snapshot or tree fails with a message that names the command and its limit. pnpm sometimes finishes an install and never exits: a `pnpm install` that times out after it wrote `node_modules/.modules.yaml` counts as a success, with a warning that pnpm did not exit.