test(db): expand includes oracle state coverage - #1719
Conversation
📝 WalkthroughWalkthroughThe includes property-test oracle now supports flat ChangesIncludes oracle coverage
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 🚥 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. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (1)
packages/db/tests/query/includes-oracle.property.test.ts
|
Size Change: 0 B Total Size: 128 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.81 kB ℹ️ View Unchanged
|
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()andconcat(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
concat(toArray(...)).The expanded suite now preserves three unfixed state-equivalence defect classes:
Key invariants
positionand thenid, including generated reorders.parentGroup.Non-goals
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:The focused oracle suite passes 18/18. TypeScript, ESLint, Prettier, the full DB suite, and
git diff --checkalso 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
Related work: RFC #1658, #1718.
Summary by CodeRabbit