Skip to content

C4: Deduplicate the sync-boundary normalizeNodeData (one shared normalizer for both sync paths) - #1267

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1266-c4-shared-node-normalize
May 30, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1266-c4-shared-node-normalize

Conversation

@malibio

@malibio malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator

Closes #1266

closes #1266)

Both sync paths (Tauri domain events and browser SSE) had byte-identical
normalizeNodeData implementations that would drift the moment a new type
branch was added to one and missed in the other. Extract to a single
authoritative function in services/node-normalize.ts; both callers import
it. Adds a parity test that guards against future divergence.

Note: the three chat message shapes (protocol/view-model/persisted) and
nodeToTaskNode are deliberate layering and are left untouched per the issue spec.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review Summary

This is a clean, well-scoped extraction. The change is unambiguously net-positive: a byte-identical duplicated function is replaced by a single canonical implementation, both callers are updated, all unused imports are pruned, and a test suite is added. No architectural regressions, no security surface changes, no any introduced beyond the pre-existing cast. The acceptance criteria from issue #1266 are all met.


Findings

Critical Issues

None.

Suggested Improvements

packages/desktop-app/src/tests/services/node-normalize.test.ts — Parity test is structurally tautological

The "Tauri path and browser path produce identical output" test calls normalizeNodeData(taskNode) twice on the same object and asserts the two results are equal. Because both invocations call the same function, equality is guaranteed by construction — the test would pass even if the function produced random output, so long as both calls agreed. This passes today and will continue to pass as the function evolves, but it cannot catch the class of bug it is intended to guard against (one path being wired to a diverged copy).

The true anti-drift protection is structural: there is now only one definition of normalizeNodeData. The parity test should be re-framed to reflect that reality. Its value lies in asserting specific output properties, not in comparing two identical calls. Consider removing the duplicate-invocation pattern and instead asserting the concrete transformation contract (e.g., status, priority, dueDate are correctly surfaced), and adding a comment explaining that structural singularity — not test-level comparison — is what prevents sync-path drift. The existing three unit tests already cover this more effectively.

Nitpicks

Nit: packages/desktop-app/src/lib/services/node-normalize.ts line 15 — The comment // Add other type-specific conversions here as needed (e.g., SchemaNode) was carried over verbatim from both originals. It is useful directional guidance; no change required, just noting it is present in the shared file as intended.

Nit: packages/desktop-app/src/tests/services/node-normalize.test.ts lines 31, 33, 40, 62, 64 — The (result as any) casts are the only path to assert on TaskNode-specific fields without importing TaskNode. This is acceptable for a test file (the project standard exempts test files from the createLogger rule; the same pragmatism applies here). The eslint-disable-next-line comments are correctly scoped.


Checklist Against Acceptance Criteria

  • One shared normalizeNodeData function in services/node-normalize.ts; both tauri-sync-listener.ts and browser-sync-service.ts import and call it.
  • Both local normalizeNodeData copies deleted in full (function body, JSDoc, and the Node/nodeToTaskNode imports that were only needed for them).
  • A future type branch is now a single-place change applied uniformly — structural guarantee confirmed.
  • Chat message shapes (chat/types.ts, DisplayMessage) and nodeToTaskNode definition are untouched.
  • as unknown as Node cast exists exactly once (in node-normalize.ts); no net-new any in production code.
  • bun run check clean (no new type errors based on diff structure); createLogger is used in both callers (not in node-normalize.ts itself, which has no logging — correct).
  • All 4 tests pass (bun run test).
  • Parity test exists (see improvement note above on its structural framing).

Decision: APPROVE — the improvement note on the parity test's structural framing is advisory. It does not affect correctness or the drift-prevention guarantee (which is already delivered by the single-definition architecture). Safe to merge as-is.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Clean extraction with correct structural guarantee. One advisory note on the parity test framing (calling the same function twice is tautological — the drift-prevention is architectural, not test-level), but this does not affect correctness or safety. LGTM.

…tion contract test

The dual-invocation pattern (calling normalizeNodeData twice and comparing)
was logically guaranteed to pass by construction. The real anti-drift protection
is structural — one function definition. Replace with a single test that asserts
the complete transformation contract (status, priority, dueDate, id, content),
with a comment explaining the architectural guarantee.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented May 30, 2026

Copy link
Copy Markdown
Collaborator Author

Address-Review Summary

Addressed: 1 recommendation
Skipped: 0

🟢 Parity test refactored (advisory suggestion)

Replaced the tautological dual-invocation pattern (calling normalizeNodeData twice and asserting equality — always passes by construction) with a concrete transformation contract test that asserts all five output fields (nodeType, status, priority, dueDate, id, content). Added a comment explaining that the true anti-drift guarantee is structural (one function definition), which both runtime modes share.

No re-review needed — this is a pure test-quality improvement with no logic changes.

@malibio
malibio merged commit 11a65e5 into main May 30, 2026
@malibio
malibio deleted the worktree-issue-1266-c4-shared-node-normalize branch May 30, 2026 14:00
malibio added a commit that referenced this pull request Jun 22, 2026
…lizer for both sync paths) (#1267)

* C4: Extract duplicated normalizeNodeData into shared node-normalize.ts (closes #1266)

Both sync paths (Tauri domain events and browser SSE) had byte-identical
normalizeNodeData implementations that would drift the moment a new type
branch was added to one and missed in the other. Extract to a single
authoritative function in services/node-normalize.ts; both callers import
it. Adds a parity test that guards against future divergence.

Note: the three chat message shapes (protocol/view-model/persisted) and
nodeToTaskNode are deliberate layering and are left untouched per the issue spec.

Co-Authored-By: Claude <[email protected]>

* Address review: replace tautological parity test with full transformation contract test

The dual-invocation pattern (calling normalizeNodeData twice and comparing)
was logically guaranteed to pass by construction. The real anti-drift protection
is structural — one function definition. Replace with a single test that asserts
the complete transformation contract (status, priority, dueDate, id, content),
with a comment explaining the architectural guarantee.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Michael Libio <[email protected]>
Co-authored-by: Claude <[email protected]>
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.

C4: Deduplicate the sync-boundary normalizeNodeData (one shared normalizer for both sync paths)

1 participant