Skip to content

refactor(core): extract the shared routing chain and canvas-axis resolution - #2517

Merged
kompiro merged 6 commits into
refactor/layout-dedupe-mechanicalfrom
refactor/layout-phase-extraction
Aug 16, 2026
Merged

kompiro merged 6 commits into
refactor/layout-dedupe-mechanicalfrom
refactor/layout-phase-extraction

Conversation

@kompiro

@kompiro kompiro commented Aug 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

PR B of the #2512 layout.ts decomposition plan. Stacked on #2516 — do not merge before it; after #2516 merges this retargets to main.

  • runRoutingChain — the 7-step routing candidate chain (ports → channel-L → gutter/mixed → trunks → gutter lanes → fan-out → channel lanes → outline seating) was duplicated between layoutInner and, per system frame, layoutMultipleSystems. This is the surface where TPL-219 parity drift already bit twice (Wire the shared routing passes into the multi-system root view (slice B) #2363: the root view ran no routing at all; feat(core): route every mode through one shared candidate chain #2367: chain-order unification). The argument mapping between the two sites is a complete injection — the multi path is the same chain with expandedFrames and ports undefined — so the shared function reproduces both byte-identically by construction. Also folds the single path's duplicate portResolver(options) call into one resolution (the resolver is a stateless closure over options).
  • canvasMembershipFor / resolveCanvasAxis — the scoped-boundary membership resolution (Ambiguous boundary contains: bare-id members silently frame multiple same-id nodes across levels #2036, diff cut boundary multi-containment: seam placement + co-membership band ordering (follow-up to #2161) #2176/ADR-1886) and the placement-axis/group-index derivation were mirrored between the two pipelines. The scope path stays a parameter (ancestors+container vs [systemId]), and the "is grouping on?" gates stay at the call sites: the single path gates on a truthy index while the multi path also requires size > 0, and that truthiness difference is live behavior.
  • Review fixes (post-review commits): resolveCanvasAxis normalizes an empty axis to undefined so both pipelines gate identically on groupBy && groupIndex (the multi path's extra size > 0 gate encoded no live behavior) and returns the bandOrder with its fallback centralized; runRoutingChain's capabilities are required-with-explicit-undefined fields and it takes the band stack itself, deriving grouped internally; portResolver's JSDoc is reattached. A cross-pipeline test was tried and dropped: probing showed the Shop-alone rendition never fires the router, so its zero assertions could not observe call-site drift — the single path's chain arguments are already fenced by the UNGROUPED_MODELS suite and the multi path by the Wire the shared routing passes into the multi-system root view (slice B) #2363 describe.

The multi call site's missing ports (no outline seating on the root view) is deliberately preserved and annotated with #2515.

Verification

No changeset: internal refactor + test-only addition.

Refs #2512. Test perspectives: TPL-219, TPL-1927 (dual metric), TPL-1954.

🤖 Generated with Claude Code

The 7-step routing candidate chain (ports -> channel-L -> gutter/mixed ->
trunks -> gutter lanes -> fan-out -> channel lanes -> outline seating) was
duplicated between layoutInner and layoutMultipleSystems — the surface where
TPL-219 parity drift already bit twice (#2363 gave the root view no routing
at all; #2367 unified the chain order). The argument mapping between the two
sites is a complete injection: the multi path is the same chain with
expandedFrames and ports undefined, so the shared function reproduces both
byte-identically by construction.

Also folds the single path's duplicate portResolver(options) call into one
resolution — the resolver is a stateless closure over options, so building
it once is behaviorally identical.

Refs #2512
The membership resolution (scoped boundary axis -> diff cut, #2036/#2176)
and the placement-axis/group-index derivation were mirrored between
layoutInner (ancestors+container scope path) and layoutMultipleSystems
(per-system [systemId] scope path). Extract both into shared helpers; the
scope path stays a parameter and the 'is grouping on?' gates stay at the
call sites — the single path gates on a truthy index while the multi path
also requires size > 0, and that truthiness difference is live behavior.

Refs #2512
…ample

TPL-219 cross-family fence for #2512: the Shop system from
multi-system-root.krs, rendered through the single-system pipeline, must
clear the same penetration/overlap contract the #2363 describe pins for the
multi-system surface. The two pipelines place the same content differently
(#2514), so router firing is pinned only where the placement provably
pierces (the multi surface); the chain contract is fenced on both.

Refs #2512
…in opts

Code-review findings on this PR's diff:

- resolveCanvasAxis: normalize an empty axis to undefined and return the
  bandOrder (with its declaredGroupOrder fallback) so both pipelines gate
  identically on 'groupBy && groupIndex' and cannot drift on the fallback.
  The multi path's extra size > 0 gate encoded no live behavior: entering
  the collapse machinery with an empty index folds nothing and the band
  assignment's own size guard blocks, so outputs were already equal.
- runRoutingChain: every capability is now a required field (explicit
  undefined at the call site that lacks it), and the helper takes the
  band stack itself (Map | null) and derives 'grouped' internally — adding
  a capability now produces a compile error at every caller, and the
  meaning of grouped lives in one place.
- Reattach portResolver's JSDoc, which the runRoutingChain insertion had
  stranded ~100 lines above its function.
- Inline the single-use membershipForSystem alias and move the
  scopePath/canvasMembership computation below the multi-system dispatch,
  which discarded it.
- Drop the new cross-pipeline describe from routing-parity.test.ts: probing
  showed the Shop-alone rendition never fires the router (0 waypoints), so
  its zero assertions could not observe any call-site drift. The single
  path's chain arguments are already fenced by the UNGROUPED_MODELS suite
  (12 models, firing pinned on PREVIOUSLY_PIERCED) and the multi path by
  the #2363 describe.

All 3691 core tests green; 168/168 example SVGs byte-identical vs main.

Refs #2512
@kompiro
kompiro merged commit 43d466f into main Aug 16, 2026
9 checks passed
@kompiro
kompiro deleted the refactor/layout-phase-extraction branch August 16, 2026 06:46

This branch was successfully deployed

1 active deployment
preview — e0e05fa2 Deployed Aug 15, 2026 by github-actions[bot]
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.

1 participant