Repository navigation
C2: Make structureTree single source of truth — unify dual sync paths + invariant check - #1250
Conversation
Code Review — PR #1250 (Issue #1247: C2 Hierarchy Source of Truth)Review Type: Initial Review SummaryThis PR delivers the C2 slice from the architectural audit: collapsing two divergent hierarchy sync implementations (Tauri and browser paths) into a single There are two items that need attention before merge, and a third that is minor but worth calling out. Requirements Check (Issue #1247 Acceptance Criteria)
Findings🔴 Critical: Mirror
|
malibio
left a comment
There was a problem hiding this comment.
Two blockers before merge: (1) mirror parentId writes in reactive-node-service.svelte.ts (~lines 1112, 1145, 1173, 1366) were not removed — this is the primary stated goal of C2; (2) assertInvariants call site omits virtual date node IDs from the allowlist, causing false-positive DEV throws for date-parented hierarchies. The hierarchy-sync.ts unification and order-fallback contract are solid. See full review comment for details. Recommendation: REQUEST CHANGES.
…t check - New services/hierarchy-sync.ts exports applyHasChildCreated/Updated/Deleted pure functions with the single authoritative order-fallback contract: use incoming number (typeof gate; 0/negative count) → preserve existing order → append at tail with jitter. Date.now() fallback removed from both paths. - tauri-sync-listener.ts and browser-sync-service.ts both delegate all has_child relationship:created/updated/deleted cases to the shared helpers after their respective id-normalization (Tauri strips node: prefix; browser uses bare ids). relationshipUpdated no-op stub in browser path is gone — updateChildOrder now fires in both modes. - ReactiveStructureTree class is now exported; assertInvariants() added: checks I1 (no orphan edges), I2 (single parent), I3 (sorted order) after hydration, throws in DEV, logs-only in prod, allowlists __root__ + virtual date sentinels. sharedNodeStore.doLoadChildrenTree calls assertInvariants after batchAddRelationships (skipped in test environment to avoid cross-test singleton bleed). - SharedNodeStore.getParentId() accessor delegates to structureTree.getParent. - Tests: hierarchy-sync.test.ts (8 tests) covers order=0, missing order, anti-drift regression guard (both paths produce identical state), update no-op, delete. reactive-structure-tree.test.ts extended with I1/I2/I3 invariant tests. Closes #1247 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…test
- reactive-node-service.svelte.ts: delete three mirror-only
updateNode({parentId}) writes (outdent persisted path, sibling
transfer, promoteChildren). structureTree.moveInMemoryRelationship
is now the complete optimistic hierarchy update at each site.
Creation-time write (~906) and in-flight CREATE fix-up (~1112)
survive because tauriCommands.createNode reads node.parentId from
the store for the wire payload.
- shared-node-store.svelte.ts: assertInvariants call site now adds
date-format IDs (YYYY-MM-DD) already present in structureTree to
the virtualIds allowlist, preventing false-positive I1 orphan throws
when loading a child of a date node before the date node itself is
in this.nodes.
- tauri-sync-listener.ts: remove stale `&& structureTree` null guard
from relationship:updated handler — structureTree is a module-level
const singleton and cannot be null.
- reactive-structure-tree.test.ts: add I2 dual-parent invariant test
and optimistic-then-event idempotency test (moveInMemoryRelationship
followed by authoritative addChild leaves single edge with backend order).
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
12a8543 to
c3eea2b
Compare
Review feedback addressedChanges in this pass:
Branch rebased onto latest main. Tests: 132 files, 3922 passing. |
Re-Review — PR #1250 (Issue #1247: C2 Hierarchy Source of Truth)Review Type: Re-Review (addressing prior REQUEST CHANGES) SummaryAll four recommendations from the prior review have been correctly addressed. The address-review commit is surgical and focused — it makes no unrelated changes. Each site was handled with the right rationale and documentation. This PR is ready to merge. Prior Recommendation Disposition🔴 Mirror
|
… + invariant check (#1250) * C2: Unify hierarchy sync paths behind hierarchy-sync.ts, add invariant check - New services/hierarchy-sync.ts exports applyHasChildCreated/Updated/Deleted pure functions with the single authoritative order-fallback contract: use incoming number (typeof gate; 0/negative count) → preserve existing order → append at tail with jitter. Date.now() fallback removed from both paths. - tauri-sync-listener.ts and browser-sync-service.ts both delegate all has_child relationship:created/updated/deleted cases to the shared helpers after their respective id-normalization (Tauri strips node: prefix; browser uses bare ids). relationshipUpdated no-op stub in browser path is gone — updateChildOrder now fires in both modes. - ReactiveStructureTree class is now exported; assertInvariants() added: checks I1 (no orphan edges), I2 (single parent), I3 (sorted order) after hydration, throws in DEV, logs-only in prod, allowlists __root__ + virtual date sentinels. sharedNodeStore.doLoadChildrenTree calls assertInvariants after batchAddRelationships (skipped in test environment to avoid cross-test singleton bleed). - SharedNodeStore.getParentId() accessor delegates to structureTree.getParent. - Tests: hierarchy-sync.test.ts (8 tests) covers order=0, missing order, anti-drift regression guard (both paths produce identical state), update no-op, delete. reactive-structure-tree.test.ts extended with I1/I2/I3 invariant tests. Closes #1247 Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * Address review: remove mirror parentId writes, fix date sentinel, I2 test - reactive-node-service.svelte.ts: delete three mirror-only updateNode({parentId}) writes (outdent persisted path, sibling transfer, promoteChildren). structureTree.moveInMemoryRelationship is now the complete optimistic hierarchy update at each site. Creation-time write (~906) and in-flight CREATE fix-up (~1112) survive because tauriCommands.createNode reads node.parentId from the store for the wire payload. - shared-node-store.svelte.ts: assertInvariants call site now adds date-format IDs (YYYY-MM-DD) already present in structureTree to the virtualIds allowlist, preventing false-positive I1 orphan throws when loading a child of a date node before the date node itself is in this.nodes. - tauri-sync-listener.ts: remove stale `&& structureTree` null guard from relationship:updated handler — structureTree is a module-level const singleton and cannot be null. - reactive-structure-tree.test.ts: add I2 dual-parent invariant test and optimistic-then-event idempotency test (moveInMemoryRelationship followed by authoritative addChild leaves single edge with backend order). Co-Authored-By: Claude Sonnet 4.6 <[email protected]> --------- Co-authored-by: Michael Libio <[email protected]> Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Summary
services/hierarchy-sync.tswithapplyHasChildCreated/Updated/Deleted— the single authoritative order-fallback contract.Date.now()fallback removed entirely from both paths.tauri-sync-listener.tsandbrowser-sync-service.tsnow delegate allhas_childrelationship events to the shared helpers after id-normalization.relationshipUpdatedno-op stub in browser path is gone.ReactiveStructureTree.assertInvariants()added (I1 no orphans, I2 single-parent, I3 sorted); runs after hydration, throws in DEV, logs-only in prod.SharedNodeStore.getParentId()accessor delegates tostructureTree.getParent.Test plan
hierarchy-sync.test.ts(8 new tests): order=0, missing order, anti-drift regression guard (both paths produce identical structureTree state), update no-op, deletereactive-structure-tree.test.tsextended: I1/I2/I3 invariant violations throw in devbun run checkclean (0 errors)bun run quality:fixapplied; unrelated Rust reformat revertedCloses #1247
🤖 Generated with Claude Code