Skip to content

Commit babf94e

Browse files
KyleAMathewsTestIsaac
authored
test(db): move two oracles onto oracleProperty with constructed histories (#2383)
* test(db): move the grouped result key oracle onto oracleProperty with constructed histories The campaign combined a raw fc.assert with a reach floor of 5, so whether each state was entered depended on the seed. Each of the three states now has a constructed history that splices its steps at the front of a generated history, and the rest of each history stays random. The campaign runs on oracleProperty: resolve turns index-named moves and deletes into row ids, the model replays the plan independently, the driver observes the published rows and size at each checkpoint, reach is a predicate of the model's groups, and the check compares groups, key count, and key stability. Evidence - Law: unchanged. A grouped result publishes one key per group, a string or number, shared by no two groups, and a surviving group keeps its key. Authority: the TKey constraint and InvalidKeyError; maintainer decision (2026-10-27) that grouped keys match the declared key type. - Reach: three declared states, each named by one constructed history. Counts printed by the framework, including constructed histories: fixed seed 92604118 gives 50 nullish, 37 lookalike, 61 kept; random seed -1510560228 gives 53, 23, 63. - RED: none observed. Five seeds (1 to 5) on the unconverted file all passed the reach check, so no seed-dependent failure was seen. The old file is at HEAD~1; this commit does not claim a RED result. - GREEN: default run 6 of 6 pass. Seeds 1 to 5, 6 of 6 each. A temporary runs: 1 edit (reverted before commit) also passes 6 of 6 at seeds 1 to 5. - Mutant (production): createPublicGroupKey encodes a non-string primitive as String(value) instead of the reserved namespace. Five of six tests fail, but as driver errors (CollectionOperationError "key null already exists", "changed by 2 rows in one flush"), not as a law verdict. The kill is real; the verdict is not yet a named law. - Mutant (builder): the lookalike builder replaced by identity. The framework rejects it: "constructed history ... did not enter lookalike-groups-published". - Limits: reach counts above are campaign totals, so random-only counts are not separated. Dates, -0, objects, multi-field groups are outside this owner (unchanged). The mutant kill comes through a driver error, so the check does not yet name the law for that defect. Co-authored-by: Isaac <no-reply@databricks.com> * test(db): name the law that a production publication error breaks in the grouped key oracle The driver let a production error escape the campaign, so the framework reported it as a setup error and the mutant that makes two groups share a key was caught only as a crash. The driver now records the error at the checkpoint where it was raised, as { error: { name, message } }, and the check returns a violation of "publishing a valid grouped change raises no error". Collection ids carry a per-process serial, so the message is stripped of it, which keeps two runs of one history identical for the determinism test. Evidence - Law: unchanged in substance. Authority: the one-result-row-per-key invariant in the grouped result key oracle's opening prose; the same key-type and uniqueness laws as before. The new law names the error case only. - Reach: unchanged (three constructed histories, one per state; default run printed the same counts in the previous commit's evidence). - RED: production mutant on the parent of this commit (group-by.ts, createPublicGroupKey encodes null as String(value)): four tests failed as driver errors, reported as setup errors. - GREEN: default run 6 of 6; seeds 1 to 5, 6 of 6 each. - Mutant after the change: same production mutant; four tests now fail with the named verdict "production raised CollectionOperationError ..." and "production raised Error: Live query result key null changed by 2 rows in one flush", law "publishing a valid grouped change raises no error". Production file restored and verified identical afterward. - Limits: a surviving mutant that produces a wrong grouped result without raising still goes through the key and count checks, which are unchanged. Co-authored-by: Isaac <no-reply@databricks.com> * style(db): format the grouped result key oracle with prettier Formatting only, after the error-observation change: prettier reflows the Step union, the try block, and a long check line. No behavior change. Co-authored-by: Isaac <no-reply@databricks.com> * test(db): move the proxy array callback campaign onto oracleProperty with a split model and driver The callback campaign was one raw fc.assert whose campaign body computed the native expected row, the draft's actual row, and the reach state together, so the model and the driver were fused in observeArrayCallbacks. The campaign now has three separate parts with the same law and comparisons: - driveArrayCallbacks runs the draft one step at a time and observes what the draft exposes (the call record, the row rebuilt from its recorded changes, the change records, and the baseline). A production error is recorded as an observation and the check names it. - modelArrayCallbacks replays the same steps on a plain row. It decides the expected views and does not touch the draft. - judgeCallbacks compares each observed view with the model's view, in the same order as before: call, row, changes, baseline. The zero-sign write reach is a predicate of the model's views, and one constructed history splices a forEach with a zero delta at the front of a generated history, so the state is entered in every campaign. The three calibrations (lost write, extra visit, wrong peer) move to the framework's calibrations. The fixed and baseline tests keep their unit form and run the same driver, model, and comparison through observeArrayCallbacks and assertArrayCallbacks. Evidence - Law: unchanged in content, now stated as the oracle law. Authority: packages/db/src/proxy.ts; the maintainer decision (2026-10-29) that -0 and 0 are distinct row values. - Reach: zero-sign-write entered by 129 histories in the fixed-seed campaign and 128 in the random campaign (framework counts, constructed history included). - RED: none observed. On the unconverted file, seeds 1 to 5 all passed, so no seed-dependent failure was seen. - GREEN: default run 48 of 48; seeds 1 to 5, 48 of 48 each. - Builder mutant (constructed history replaced by identity): framework rejects with "constructed history ... did not enter zero-sign-write". - Production mutant (src/proxy.ts getChanges returns {} unconditionally, restored and verified): 27 of 48 tests fail with the named verdict `proxy.callback-history violated at checkpoint "step 0" (law: the row rebuilt from the draft's recorded changes is the native row)` on a shrunk history {"values":[-0],"steps":[...]}. - Limits: the baseline and fixed-delta tests remain unit-style in this file (pre-existing; they call the shared helpers); the proxy driver's error branch has no mutant that exercises it yet; the coverage map has no reach statement for this owner, so none changed. Co-authored-by: Isaac <no-reply@databricks.com> * test(db): fix the grouped result key oracle's review findings (D3-1 to D3-7, D3-10) Replay manifest (D3-1): group-result-key.groups now matches the framework's random-seed test name, "group-result-key.groups > random seed". oracle-replay.test.ts passes 116 of 116. Lint (D3-2): the import members are sorted; eslint is clean on both files. Distinct keys (D3-3): the distinct-key count and the live size are compared with the model's group count, not with the rows of the same snapshot. A calibration shares one key between two groups and the check rejects it. Every checkpoint observed (D3-4): the check compares the observation count with the model's checkpoint count, so an empty or truncated trace fails under "every checkpoint of a history is observed". A calibration drops the last checkpoint. Production errors (D3-5, D3-6): the driver catches only the production calls (preload, each write and commit, each snapshot read). The error is observed as its normalized Error, which keeps the stack and cause; the check returns a violation of "publishing a valid grouped change raises no error" with the original Error as the verdict's cause. Cleanup runs outside these catches, so a teardown failure is a setup error. The error helpers are shared with the proxy oracle in tests/oracle-error-observation.ts. Calibrations (D3-7): one per verdict branch (unsupported key type, shared key, surviving group changes its key, publication raises, last checkpoint dropped), each checked by the framework to be rejected by its named law. Check name (D3-10): the grouped-key comparison is named judgeGroups and is the declared check. The driver has no declareOracle slot (check, model, grammar only), so it is declared through oracleProperty's driver field. Evidence - Law: unchanged in substance; the new law names the checkpoint count and the error case. Authority: as before (TKey, InvalidKeyError, maintainer decision 2026-10-27), and the opening prose of this file. - Reach: unchanged. Fixed seed 92604118: nullish 50, lookalike 37, kept 61. Random seed: nullish 50, lookalike 25, kept 59 (framework counts, constructed histories included). - RED on this oracle's previous state: the distinct-key check compared the collection with itself, so a shared key was never rejected. The new "two groups share a key" calibration is that RED: it is rejected now and was never rejected before. - GREEN: default 11 of 11; seeds 1 to 5, 11 of 11 each. - Production mutant (createPublicGroupKey encodes null as String(value)): four tests fail with the named verdict "publishing a valid grouped change raises no error" and the production error text as the difference. - Calibrations: five, each rejected by its named law. - Replay: oracle-replay.test.ts 116 of 116. eslint clean; lint:changed clean. - Limits: the reach counts mix constructed and random histories. The shared error module is also used by the proxy oracle in the next commit. Co-authored-by: Isaac <no-reply@databricks.com> * test(db): fix the proxy callback oracle's review findings (D3-4, D3-5, D3-8, D3-9) Observation count (D3-4): the check compares the number of observed steps with the model's, so a truncated or empty trace fails under "every step of a history is observed". A calibration drops the last step. Errors (D3-5): the draft's error is observed as the shared normalized Error and gets its own law, "a draft's callback raises no error", with the Error as the verdict's cause. The local error helpers are gone; the shared module is tests/oracle-error-observation.ts. Driver (S3-style): only the draft calls (the callback and getChanges) are inside the catch. Building the row from the recorded changes is outside it. Constructed history (D3-8): the builder keeps the generated step's method and pins only its target and delta to 0 over a leading -0, so every callback method can enter zero-sign-write. Fixed histories (D3-9): the baseline case (two steps must leave the input row unchanged) and the per-method fixed deltas (8 methods, 3 targets, 3 delta pairs) are histories.fixed, run through the same driver, model, and check. The hand-written baseline test and its helpers observeArrayCallbacks and assertArrayCallbacks are deleted. Smaller fixes: the lost-write calibration tests the difference directly, the reach comment states that the state describes the history, and the calibrations include a dropped last step. Evidence - Law: unchanged in content. Authority: packages/db/src/proxy.ts; the maintainer decision (2026-10-29) that -0 and 0 are distinct row values. - Reach: zero-sign-write, 129 histories in the fixed-seed campaign and 127 in the random campaign (framework counts, constructed history included). - RED: for D3-4, the old check never compared counts, so a truncated trace passed. The "last step dropped" calibration is that RED: it is rejected now. - GREEN: default 113 of 113; seeds 1 to 5, 113 of 113 each. - Production mutant (getChanges returns {} unconditionally): 67 of 113 tests fail with the named law "the row rebuilt from the draft's recorded changes is the native row". - Builder mutant (constructed history replaced by identity): rejected by the framework's generability check ("built a history the arbitrary cannot generate"), not by the reach check. - Known limit: a builder that keeps the -0 prefix but omits the zero-sign step passed the default campaign, because random tail steps can still enter the state. The reach check is therefore not deterministic for this builder design. Recorded here; a stronger builder (pin the -0 change in the generated history itself) is a follow-up, not part of this commit. - Replay and eslint: clean. lint:changed clean. Co-authored-by: Isaac <no-reply@databricks.com> --------- Co-authored-by: Test <test@test.com> Co-authored-by: Isaac <no-reply@databricks.com>
1 parent a86aa43 commit babf94e

5 files changed

Lines changed: 718 additions & 330 deletions

File tree

‎docs/contributing/oracle-coverage.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ that test identifiers must copy production's private data structures.
581581
| Indexed predicate filtering | Complete for bounded dotted-path collision | An independent row filter checks direct predicates and public callback predicates for a dotted scalar field beside a nested path, with and without an index. Selected-field ordering checks the same distinction through `$selected`. |
582582
| WHERE predicate publication | Complete for bounded predicate and sync-transaction grammar | The contract, Kleene reference evaluator, snapshot and change-history grammar, three subscriber consumers plus direct snapshot, and per-commit key-set refinement check are literate. A fixed same-key update checks live-row and direct-subscriber payloads; a focused descriptor boundary checks stored-row prefilter safety. Generated cleanup and restart histories for filtered subscribers remain open. |
583583
| Joined result keys | Complete for bounded two-source key and whole-source receiving grammars | The nested-loop pair model retains delimiter-, typed, infinite and `NaN` keys. The November 5 extension crosses whole-source selection and spreads, direct/QueryRef receivers, all four join kinds, either selected side and authored collisions. Each of 192 finite histories and fixed/random 80-history campaigns compares root Collections, include facades, toArray and materialize at six cuts. Published `$key` equals the actual default pair or explicit custom key; the other three fields retain source attribution. Inline authored fields and multiplicity remain unchanged. Value-only updates and rejoining preserve key sets. The 4,608 declared receiving states must each reach once. More than two sources, arbitrary nested projection/QueryRef depth, custom-key functions outside the generated key grammar, arbitrary optimistic overlap, frameworks and real providers remain outside this owner. |
584-
| Grouped result keys | [Grouped result key oracle](https://github.com/TanStack/db/blob/main/packages/db/tests/query/group-result-key-oracle.property.test.ts) | A grouped live-query Collection gives each group one key of the Collection key type, a string or a number, whatever the group value. Maintainer decision (2026-10-27): grouped keys match the declared key type rather than widening it to nullish keys. Group values come from strings, numbers, `NaN`, `null`, `undefined`, booleans, a bigint, strings that print like those values, and strings in the reserved `\u0000tanstack-db:` namespace; histories move, delete, and insert rows. After preload and each synced change, the (group value, count) pairs equal an independent partition by type and value, every key is a string or number, no two groups share a key, and a group that survives a change keeps its key. Reach (minimum 5, per campaign of 80): a nullish group published (32 to 38), a group value published beside a string that prints like it (18 to 21), and a key kept across a change (49 to 53). RED on the parent commit: keys `undefined`, `null`, `false`, and `10n`. Mutants that encode with `String(value)` (lookalike keys collide) or that encode only nullish values (boolean keys) fail. Encoding only the internal D2 key is equivalent in this domain, because the Collection keys rows by the public group key. A focused witness in `collection.test.ts` checks that `sync.write` rejects `undefined`, `null`, boolean, and bigint keys before staging them, and that a later valid write commits alone. A sync adapter that writes such a key breaks its contract, so this is a fail-fast invariant witness under AGENTS.md ("Separate Valid Edge Cases from Contract Contradictions"), not a generated owner; SortedMap never receives these keys. Not covered: Dates, `-0`, objects, and multi-field groups, whose values the aggregate select oracle owns; real sync adapters, since the source is a controlled mock. |
584+
| Grouped result keys | [Grouped result key oracle](https://github.com/TanStack/db/blob/main/packages/db/tests/query/group-result-key-oracle.property.test.ts) | A grouped live-query Collection gives each group one key of the Collection key type, a string or a number, whatever the group value. Maintainer decision (2026-10-27): grouped keys match the declared key type rather than widening it to nullish keys. Group values come from strings, numbers, `NaN`, `null`, `undefined`, booleans, a bigint, strings that print like those values, and strings in the reserved `\u0000tanstack-db:` namespace; histories move, delete, and insert rows. After preload and each synced change, the (group value, count) pairs equal an independent partition by type and value, every key is a string or number, no two groups share a key, and a group that survives a change keeps its key. Reach: each of the three states (a nullish group published, a group value published beside a string that prints like it, and a key kept across a change) is named by a constructed history that splices its steps at the front of a generated history, so every campaign enters each state; a builder that omits its steps fails the framework's reach check. Random histories also reach them (campaign counts including the constructed histories, 48 to 53, 23 to 30, and 61 to 65 across seeds 1 to 5 and the fixed seed). RED on the parent commit: keys `undefined`, `null`, `false`, and `10n`. Mutants that encode with `String(value)` (lookalike keys collide) or that encode only nullish values (boolean keys) fail. Encoding only the internal D2 key is equivalent in this domain, because the Collection keys rows by the public group key. A focused witness in `collection.test.ts` checks that `sync.write` rejects `undefined`, `null`, boolean, and bigint keys before staging them, and that a later valid write commits alone. A sync adapter that writes such a key breaks its contract, so this is a fail-fast invariant witness under AGENTS.md ("Separate Valid Edge Cases from Contract Contradictions"), not a generated owner; SortedMap never receives these keys. Not covered: Dates, `-0`, objects, and multi-field groups, whose values the aggregate select oracle owns; real sync adapters, since the source is a controlled mock. |
585585
| D2 Index storage | Complete for bounded prefix grammar | The contract, plain-`Map` multiset model, prefixed and unprefixed value grammar, `Index` driver, and per-addition `get`/`has` check are literate. Compaction, presence tracking, and structural payloads remain outside this owner. |
586586
| Pooled live queries | Complete for bounded eq-filter grammar | The contract, independent `eq` model, live-query Collection second formulation, sync/optimistic/mount/cleanup-restart grammar, observer driver, and per-step refinement check are literate. On-demand and persisted sources, `DbClient`, Suspense, and every clause beyond `eq` conjuncts keep the live-query Collection. |
587587
| Live-query deferred acquisition | Complete for bounded synchronous grammar | The law, independent model, history grammar over source states, shapes, and depth, real-Collection driver, and per-step refinement check are literate. Pooled views and DbClient stream preloads have their own blocks. The grammar also adds a peer consumer starting the source and a source truncate before the first subscriber; fixed blocks cover a subscriber that outlives cleanup, reads that wait for readiness, and release of two independent descriptor sources when one start fails. Asynchronous sources, several live-query consumers, and general failure histories stay open. |
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// A production error that a driver observes at the checkpoint where it was
2+
// raised. The driver records the error itself: the framework compares an
3+
// Error's name, message, and cause as data and never its stack, so the
4+
// stack survives for the report. The check turns the observation into a
5+
// violation of the law that the publication or the mutation breaks, and it
6+
// keeps the Error as the verdict's cause, outside the compared values.
7+
import type { Verdict } from './oracle-property.js'
8+
9+
// A thrown value as an Error, so every observation is data the framework
10+
// compares, whatever production threw.
11+
export function asProductionError(error: unknown): Error {
12+
return error instanceof Error ? error : new Error(String(error))
13+
}
14+
15+
export function isErrorObservation(value: unknown): value is Error {
16+
return value instanceof Error
17+
}
18+
19+
// The verdict for an observed production error: a violation of `law` at
20+
// `checkpoint`, with the Error as its cause. `expected` says what the law owes
21+
// in place of the error.
22+
export function errorViolation(
23+
checkpoint: string,
24+
law: string,
25+
error: Error,
26+
expected: string,
27+
): Verdict {
28+
return {
29+
kind: `violation`,
30+
checkpoint,
31+
difference: `production raised ${error.name}: ${error.message}`,
32+
law,
33+
values: { actual: error.name, expected },
34+
cause: error,
35+
}
36+
}

‎packages/db/tests/oracle-replay-manifest.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,10 +1142,7 @@ const replayTestNames = new Map([
11421142
`index-update.custom-comparator`,
11431143
`matches an independent custom-comparator model \\(seed undefined\\)`,
11441144
],
1145-
[
1146-
`group-result-key.groups`,
1147-
`publishes one key of the key type per group \\(seed undefined\\)`,
1148-
],
1145+
[`group-result-key.groups`, `group-result-key\\.groups > random seed`],
11491146
])
11501147

11511148
// Properties whose own seeded generator replaces fast-check, so they have no

0 commit comments

Comments
 (0)