fix(canvas): sortParentsBeforeChildren — root nodes before orphans (#315) #364

Closed
fullstack-engineer wants to merge 1 commits from fix/canvas-topology-sort-orphan into main

1 Commits

Author SHA1 Message Date
dee01af2c2 fix(canvas): sortParentsBeforeChildren — root-before-orphan ordering
All checks were successful
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 12s
sop-tier-check / tier-check (pull_request) Successful in 12s
audit-force-merge / audit (pull_request) Has been skipped
Algorithm did a single DFS pass over all nodes in input order, which
placed orphan nodes (parentId → missing node) before roots when the
orphan appeared earlier in the input array.  Tests: sortParentsBeforeChildren
"does not crash when parentId references a missing node" was failing.

Fix: two-pass approach — visit all root nodes first, then remaining
unvisited nodes (orphans).  Preserves existing correct behaviour for
valid parent→child chains.

Also:
- canvas/vitest.config.ts: add clarifying comment that Node environment
  is intentional (socket.url.test.ts runs in Node, DOM tests use the
  per-file // @vitest-environment jsdom directive).
- canvas/src/store/__tests__/socket.url.test.ts: simplify — drop the
  importWsUrl helper (no longer needed since env handling is direct and
  Node's lack of window.globalThis correctly triggers the localhost:8080
  fallback in deriveWsBaseUrl).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-11 03:18:35 +00:00