Skip to content

test(db): expand includes oracle state coverage - #1719

Merged
tannerlinsley merged 1 commit into
mainfrom
codex/includes-state-traces
Aug 12, 2026
Merged

test(db): expand includes oracle state coverage#1719
tannerlinsley merged 1 commit into
mainfrom
codex/includes-state-traces

Conversation

@KyleAMathews

@KyleAMathews KyleAMathews commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

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:

  1. A nested scalar reference redirect retains the old materialized row (landed with test(db): extract reusable trace runner #1718).
  2. Deleting and reinserting one of two parents that shared a correlation key can leave the reinserted parent subscribed to its old route.
  3. 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 position and then id, 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.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The includes property-test oracle now supports flat concat materialization 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

Layer / File(s) Summary
Depth-aware full-row batches
packages/db/tests/query/includes-oracle.property.test.ts
Full-row batch generation and execution now support every include depth. Root and child models remain synchronized across generated scenarios.
Flat materialization oracle
packages/db/tests/query/includes-oracle.property.test.ts
The oracle tests array materialization and scalar concat materialization with generated traces and recomputation projections.
Routing regression coverage
packages/db/tests/query/includes-oracle.property.test.ts
Property and deterministic tests cover child handoffs, reparenting, rekeying, and stale routing after parent reinsertion.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • TanStack/db#1669: Expands regression and property coverage for child reordering and nested includes behavior.
  • TanStack/db#1716: Introduces the recomputation oracle extended here with flat concat materialization and multi-depth batches.
  • TanStack/db#1718: Adds related full-row batch testing infrastructure and scenarios.

Suggested reviewers: kevin-dp

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: expanded database includes oracle state coverage.
Description check ✅ Passed The description explains the changes, motivation, testing, and release impact, with sufficient detail despite using custom headings instead of the full template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/includes-state-traces

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

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026

Copy link
Copy Markdown
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@1719

commit: 0e6b69f

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/db/tests/query/includes-oracle.property.test.ts (1)

1199-1247: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Tighten the flat materialization result and observed types.

FlatMaterializationResult is a union of both shapes. A recompute that returns the wrong shape for the selected materialization still typechecks. flatMaterializationProjection also declares unknown as the observed type, so assertEqual loses its type link to observe.

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 unknown or any return 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 e4940a4 and 0e6b69f.

📒 Files selected for processing (1)
  • packages/db/tests/query/includes-oracle.property.test.ts

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: 0 B

Total Size: 128 kB

ℹ️ View Unchanged
Filename Size
packages/db/dist/esm/collection/change-events.js 1.44 kB
packages/db/dist/esm/collection/changes.js 1.43 kB
packages/db/dist/esm/collection/cleanup-queue.js 810 B
packages/db/dist/esm/collection/events.js 434 B
packages/db/dist/esm/collection/index.js 3.83 kB
packages/db/dist/esm/collection/indexes.js 1.99 kB
packages/db/dist/esm/collection/lifecycle.js 1.7 kB
packages/db/dist/esm/collection/mutations.js 2.47 kB
packages/db/dist/esm/collection/state.js 5.51 kB
packages/db/dist/esm/collection/subscription.js 3.82 kB
packages/db/dist/esm/collection/sync.js 2.94 kB
packages/db/dist/esm/collection/transaction-metadata.js 144 B
packages/db/dist/esm/deferred.js 207 B
packages/db/dist/esm/errors.js 5.13 kB
packages/db/dist/esm/event-emitter.js 748 B
packages/db/dist/esm/index.js 3.21 kB
packages/db/dist/esm/indexes/auto-index.js 829 B
packages/db/dist/esm/indexes/base-index.js 784 B
packages/db/dist/esm/indexes/basic-index.js 2.17 kB
packages/db/dist/esm/indexes/btree-index.js 2.29 kB
packages/db/dist/esm/indexes/index-registry.js 820 B
packages/db/dist/esm/indexes/reverse-index.js 557 B
packages/db/dist/esm/live-query-adapter.js 318 B
packages/db/dist/esm/live-query-observer.js 2.29 kB
packages/db/dist/esm/local-only.js 916 B
packages/db/dist/esm/local-storage.js 2.12 kB
packages/db/dist/esm/optimistic-action.js 359 B
packages/db/dist/esm/paced-mutations.js 496 B
packages/db/dist/esm/proxy.js 3.75 kB
packages/db/dist/esm/query/builder/functions.js 1.47 kB
packages/db/dist/esm/query/builder/index.js 5.84 kB
packages/db/dist/esm/query/builder/ref-proxy.js 1.24 kB
packages/db/dist/esm/query/compiler/evaluators.js 1.89 kB
packages/db/dist/esm/query/compiler/expressions.js 430 B
packages/db/dist/esm/query/compiler/group-by.js 3.56 kB
packages/db/dist/esm/query/compiler/index.js 6.67 kB
packages/db/dist/esm/query/compiler/joins.js 2.5 kB
packages/db/dist/esm/query/compiler/lazy-targets.js 923 B
packages/db/dist/esm/query/compiler/order-by.js 1.74 kB
packages/db/dist/esm/query/compiler/select.js 1.53 kB
packages/db/dist/esm/query/effect.js 4.77 kB
packages/db/dist/esm/query/expression-helpers.js 1.43 kB
packages/db/dist/esm/query/ir.js 1.25 kB
packages/db/dist/esm/query/live-query-collection.js 360 B
packages/db/dist/esm/query/live/collection-config-builder.js 9.24 kB
packages/db/dist/esm/query/live/collection-registry.js 264 B
packages/db/dist/esm/query/live/collection-subscriber.js 1.93 kB
packages/db/dist/esm/query/live/internal.js 145 B
packages/db/dist/esm/query/live/utils.js 1.81 kB
packages/db/dist/esm/query/optimizer.js 2.92 kB
packages/db/dist/esm/query/predicate-utils.js 2.97 kB
packages/db/dist/esm/query/query-once.js 359 B
packages/db/dist/esm/query/subset-dedupe.js 960 B
packages/db/dist/esm/scheduler.js 1.3 kB
packages/db/dist/esm/SortedMap.js 1.3 kB
packages/db/dist/esm/strategies/debounceStrategy.js 247 B
packages/db/dist/esm/strategies/queueStrategy.js 428 B
packages/db/dist/esm/strategies/throttleStrategy.js 246 B
packages/db/dist/esm/transactions.js 3.04 kB
packages/db/dist/esm/utils.js 927 B
packages/db/dist/esm/utils/array-utils.js 273 B
packages/db/dist/esm/utils/browser-polyfills.js 304 B
packages/db/dist/esm/utils/btree.js 5.61 kB
packages/db/dist/esm/utils/comparison.js 1.15 kB
packages/db/dist/esm/utils/cursor.js 457 B
packages/db/dist/esm/utils/index-optimization.js 2.39 kB
packages/db/dist/esm/utils/type-guards.js 157 B
packages/db/dist/esm/utils/uuid.js 449 B
packages/db/dist/esm/virtual-props.js 360 B

compressed-size-action::db-package-size

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: 0 B

Total Size: 3.81 kB

ℹ️ View Unchanged
Filename Size
packages/react-db/dist/esm/index.js 249 B
packages/react-db/dist/esm/useLiveInfiniteQuery.js 1.32 kB
packages/react-db/dist/esm/useLiveQuery.js 920 B
packages/react-db/dist/esm/useLiveQueryEffect.js 355 B
packages/react-db/dist/esm/useLiveSuspenseQuery.js 567 B
packages/react-db/dist/esm/usePacedMutations.js 401 B

compressed-size-action::react-db-package-size

@tannerlinsley
tannerlinsley merged commit 9005885 into main Aug 12, 2026
17 of 19 checks passed
@tannerlinsley
tannerlinsley deleted the codex/includes-state-traces branch August 12, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants