test(db): expand includes oracle state coverage #1719
main fromrefs/pull/1719/head·merged by tannerlinsley Expand the includes recompute oracle across depths 1–4, generated full-row batches, reorders, child relationship changes, and flat array/concat materialization. This is test-only: it records two newly isolated runtime defect classes as assertion-specific expected failures but does not change query behavior.
Reviewer guidance#
Coverage gap#
The reusable trace runner from #1718 had only a short depth-1 full-row trace. It did not guarantee that generated histories reached the selected include depth, exercise full-row multi-change batches, preserve reorder coverage while isolating relationship changes, or compare flat materialize() and concat(toArray(...)) outputs with independent recomputation.
Without those cases, the oracle could miss routing failures that depend on shared correlation keys, delete/reinsert lifetimes, or several child changes arriving in one batch.
Approach#
- Generalize the full-row batch driver to depths 1–4.
- Generate bounded multi-change histories and prepend a connected path whose reserved IDs cannot be overwritten by generated rows. This makes every selected depth observable at every checkpoint.
- Keep root reorder changes in the green corpus while excluding the known delete/reinsert failure class.
- Exercise child reparenting and rekeying one row at a time. Multi-row relationship changes remain represented by a reduced expected-failure trace.
- Add independent flat projections for array materialization and
concat(toArray(...)). - Reduce each discovered mismatch to a deterministic trace and accept only the oracle's equality assertion as the expected failure.
The expanded suite now preserves three unfixed state-equivalence defect classes:
- A nested scalar reference redirect retains the old materialized row (landed with #1718).
- Deleting and reinserting one of two parents that shared a correlation key can leave the reinserted parent subscribed to its old route.
- Reparenting two children in one batch can leave aggregate membership stale. The array and concat traces are two projections of this same defect, not separate bugs.
Key invariants#
- The incremental result equals a fresh recomputation after startup and every batch.
- Every generated depth has a live, connected result path.
- Row ordering follows
positionand thenid, including generated reorders. - A child belongs only to parents whose current group matches its current
parentGroup. - Array and concat materializations derive from the same current child membership and order.
- Known failures pass only for an oracle assertion mismatch; setup, runtime, and cleanup errors still fail the test.
Non-goals#
- No production fix for any recorded defect.
- No readiness, progressive-sync timing, publication, adapter, or ownership driver.
- No claim that array and concat expose distinct underlying bugs.
- No unbounded fuzzing or replay framework.
Trade-offs#
The generated runs are deterministic and bounded to keep CI fast and reproducible. The green generators avoid state transitions already proven broken; those transitions live as small expected-failure traces until the routing refactor makes them green. Single-row child relationship changes keep reparent/rekey coverage active without masking the separate intra-batch hand-off defect.
Verification#
From packages/db:
pnpm exec vitest run tests/query/includes-oracle.property.test.ts
pnpm test
The focused oracle suite passes 18/18. TypeScript, ESLint, Prettier, the full DB suite, and git diff --check also pass.
Files changed#
packages/db/tests/query/includes-oracle.property.test.ts: expands the full-row generators and depth coverage, adds flat materialization projections, and records the shared-route and intra-batch hand-off failures.
Release impact#
- Tests only; no changeset or release is needed.
Related work: RFC #1658, #1718.
Summary by CodeRabbit#
- Tests
- Expanded coverage for nested data updates across multiple relationship levels.
- Added scenarios for inserts, deletes, updates, reparenting, and key changes.
- Added deterministic tests for shared routing and child handoffs within a batch.
- Added validation for flat and array-based result materialization.
- 1
More templates
@tanstack/angular-db
npm i https://pkg.pr.new/@tanstack/angular-db@1719@tanstack/browser-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@1719@tanstack/capacitor-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@1719@tanstack/cloudflare-durable-objects-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@1719@tanstack/db
npm i https://pkg.pr.new/@tanstack/db@1719@tanstack/db-ivm
npm i https://pkg.pr.new/@tanstack/db-ivm@1719@tanstack/db-sqlite-persistence-core
npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@1719@tanstack/electric-db-collection
npm i https://pkg.pr.new/@tanstack/electric-db-collection@1719@tanstack/electron-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@1719@tanstack/expo-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@1719@tanstack/node-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@1719@tanstack/offline-transactions
npm i https://pkg.pr.new/@tanstack/offline-transactions@1719@tanstack/powersync-db-collection
npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1719@tanstack/query-db-collection
npm i https://pkg.pr.new/@tanstack/query-db-collection@1719@tanstack/react-db
npm i https://pkg.pr.new/@tanstack/react-db@1719@tanstack/react-native-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@1719@tanstack/rxdb-db-collection
npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1719@tanstack/solid-db
npm i https://pkg.pr.new/@tanstack/solid-db@1719@tanstack/svelte-db
npm i https://pkg.pr.new/@tanstack/svelte-db@1719@tanstack/tauri-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@1719@tanstack/trailbase-db-collection
npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1719@tanstack/vue-db
npm i https://pkg.pr.new/@tanstack/vue-db@1719commit:
0e6b69f🧹 Nitpick comments (1)
packages/db/tests/query/includes-oracle.property.test.ts (1)
1199-1247: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueTighten the flat materialization result and observed types.
FlatMaterializationResultis a union of both shapes. A recompute that returns the wrong shape for the selected materialization still typechecks.flatMaterializationProjectionalso declaresunknownas the observed type, soassertEqualloses its type link toobserve.Discriminate the result type by materialization and use the precise observed type.
♻️ Proposed typing refactor
-type FlatMaterializationResult = Array< - | { - id: number - group: number - children: Array<{ id: number; value: number }> - } - | { id: number; group: number; content: string } -> +type FlatMaterializationRow<TMaterialization extends FlatMaterialization> = + TMaterialization extends `array` + ? { id: number; group: number; children: Array<{ id: number; value: number }> } + : { id: number; group: number; content: string } + +type FlatMaterializationResult< + TMaterialization extends FlatMaterialization = FlatMaterialization, +> = Array<FlatMaterializationRow<TMaterialization>>-function flatMaterializationProjection( - materialization: FlatMaterialization, -): TraceProjection< - FlatMaterializationContext, - unknown, - FlatMaterializationResult -> { +function flatMaterializationProjection( + materialization: FlatMaterialization, +): TraceProjection< + FlatMaterializationContext, + FlatMaterializationResult, + FlatMaterializationResult +> {As per coding guidelines: "Always provide the most precise return type annotation; avoid
unknownoranyreturn types unless truly necessary".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/db/tests/query/includes-oracle.property.test.ts` around lines 1199 - 1247, Make FlatMaterializationResult generic over the materialization mode so `recomputeFlatMaterialization` can only return the corresponding array or concatenated-content shape, and update its callers accordingly. In `flatMaterializationProjection`, replace the `unknown` observed type with the precise type produced by `stripVirtualProperties(incremental.toArray)`, preserving the type relationship between `observe` and `assertEqual`.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Nitpick comments: In `@packages/db/tests/query/includes-oracle.property.test.ts`: - Around line 1199-1247: Make FlatMaterializationResult generic over the materialization mode so `recomputeFlatMaterialization` can only return the corresponding array or concatenated-content shape, and update its callers accordingly. In `flatMaterializationProjection`, replace the `unknown` observed type with the precise type produced by `stripVirtualProperties(incremental.toArray)`, preserving the type relationship between `observe` and `assertEqual`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID:
d0c71f19-ae74-4527-b94e-3c6a012d486f📥 Commits
Reviewing files that changed from the base of the PR and between e4940a4756d8118e9a35a506c05ce6622b2e964e and 0e6b69fa76df5b319573563d4621e899ad9cac07.
📒 Files selected for processing (1)
packages/db/tests/query/includes-oracle.property.test.ts
Size Change: 0 B
Total Size: 128 kB
compressed-size-action::db-package-sizeℹ️ View Unchanged
Filename Size packages/db/dist/esm/collection/change-events.js1.44 kB packages/db/dist/esm/collection/changes.js1.43 kB packages/db/dist/esm/collection/cleanup-queue.js810 B packages/db/dist/esm/collection/events.js434 B packages/db/dist/esm/collection/index.js3.83 kB packages/db/dist/esm/collection/indexes.js1.99 kB packages/db/dist/esm/collection/lifecycle.js1.7 kB packages/db/dist/esm/collection/mutations.js2.47 kB packages/db/dist/esm/collection/state.js5.51 kB packages/db/dist/esm/collection/subscription.js3.82 kB packages/db/dist/esm/collection/sync.js2.94 kB packages/db/dist/esm/collection/transaction-metadata.js144 B packages/db/dist/esm/deferred.js207 B packages/db/dist/esm/errors.js5.13 kB packages/db/dist/esm/event-emitter.js748 B packages/db/dist/esm/index.js3.21 kB packages/db/dist/esm/indexes/auto-index.js829 B packages/db/dist/esm/indexes/base-index.js784 B packages/db/dist/esm/indexes/basic-index.js2.17 kB packages/db/dist/esm/indexes/btree-index.js2.29 kB packages/db/dist/esm/indexes/index-registry.js820 B packages/db/dist/esm/indexes/reverse-index.js557 B packages/db/dist/esm/live-query-adapter.js318 B packages/db/dist/esm/live-query-observer.js2.29 kB packages/db/dist/esm/local-only.js916 B packages/db/dist/esm/local-storage.js2.12 kB packages/db/dist/esm/optimistic-action.js359 B packages/db/dist/esm/paced-mutations.js496 B packages/db/dist/esm/proxy.js3.75 kB packages/db/dist/esm/query/builder/functions.js1.47 kB packages/db/dist/esm/query/builder/index.js5.84 kB packages/db/dist/esm/query/builder/ref-proxy.js1.24 kB packages/db/dist/esm/query/compiler/evaluators.js1.89 kB packages/db/dist/esm/query/compiler/expressions.js430 B packages/db/dist/esm/query/compiler/group-by.js3.56 kB packages/db/dist/esm/query/compiler/index.js6.67 kB packages/db/dist/esm/query/compiler/joins.js2.5 kB packages/db/dist/esm/query/compiler/lazy-targets.js923 B packages/db/dist/esm/query/compiler/order-by.js1.74 kB packages/db/dist/esm/query/compiler/select.js1.53 kB packages/db/dist/esm/query/effect.js4.77 kB packages/db/dist/esm/query/expression-helpers.js1.43 kB packages/db/dist/esm/query/ir.js1.25 kB packages/db/dist/esm/query/live-query-collection.js360 B packages/db/dist/esm/query/live/collection-config-builder.js9.24 kB packages/db/dist/esm/query/live/collection-registry.js264 B packages/db/dist/esm/query/live/collection-subscriber.js1.93 kB packages/db/dist/esm/query/live/internal.js145 B packages/db/dist/esm/query/live/utils.js1.81 kB packages/db/dist/esm/query/optimizer.js2.92 kB packages/db/dist/esm/query/predicate-utils.js2.97 kB packages/db/dist/esm/query/query-once.js359 B packages/db/dist/esm/query/subset-dedupe.js960 B packages/db/dist/esm/scheduler.js1.3 kB packages/db/dist/esm/SortedMap.js1.3 kB packages/db/dist/esm/strategies/debounceStrategy.js247 B packages/db/dist/esm/strategies/queueStrategy.js428 B packages/db/dist/esm/strategies/throttleStrategy.js246 B packages/db/dist/esm/transactions.js3.04 kB packages/db/dist/esm/utils.js927 B packages/db/dist/esm/utils/array-utils.js273 B packages/db/dist/esm/utils/browser-polyfills.js304 B packages/db/dist/esm/utils/btree.js5.61 kB packages/db/dist/esm/utils/comparison.js1.15 kB packages/db/dist/esm/utils/cursor.js457 B packages/db/dist/esm/utils/index-optimization.js2.39 kB packages/db/dist/esm/utils/type-guards.js157 B packages/db/dist/esm/utils/uuid.js449 B packages/db/dist/esm/virtual-props.js360 B Size Change: 0 B
Total Size: 3.81 kB
compressed-size-action::react-db-package-sizeℹ️ View Unchanged
Filename Size packages/react-db/dist/esm/index.js249 B packages/react-db/dist/esm/useLiveInfiniteQuery.js1.32 kB packages/react-db/dist/esm/useLiveQuery.js920 B packages/react-db/dist/esm/useLiveQueryEffect.js355 B packages/react-db/dist/esm/useLiveSuspenseQuery.js567 B packages/react-db/dist/esm/usePacedMutations.js401 B tannerlinsley merged this9005885
tannerlinsley closed this
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
The includes property-test oracle now supports flat
concatmaterialization and depth-aware full-row batches. New generated and deterministic scenarios cover nested updates, reparenting, rekeying, child handoffs, and routing regressions.Changes#
Includes oracle coverage
packages/db/tests/query/includes-oracle.property.test.tspackages/db/tests/query/includes-oracle.property.test.tsconcatmaterialization with generated traces and recomputation projections.packages/db/tests/query/includes-oracle.property.test.tsEstimated code review effort: 4 (Complex) | ~45 minutes
Possibly related PRs
includesbehavior.Suggested reviewers:
kevin-dp🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share