Repository navigation
refactor(core): extract the shared routing chain and canvas-axis resolution - #2517
Merged
kompiro merged 6 commits intoAug 16, 2026
Merged
Conversation
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
This was referenced Aug 15, 2026
Merged
…-phase-extraction
…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
4 tasks
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 betweenlayoutInnerand, 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 withexpandedFramesandportsundefined — so the shared function reproduces both byte-identically by construction. Also folds the single path's duplicateportResolver(options)call into one resolution (the resolver is a stateless closure overoptions).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 requiressize > 0, and that truthiness difference is live behavior.resolveCanvasAxisnormalizes an empty axis toundefinedso both pipelines gate identically ongroupBy && groupIndex(the multi path's extrasize > 0gate encoded no live behavior) and returns thebandOrderwith its fallback centralized;runRoutingChain's capabilities are required-with-explicit-undefinedfields and it takes the band stack itself, derivinggroupedinternally;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
pnpm --filter @karasu-tools/core test— 3691 tests green.pnpm typecheck/pnpm check:cycles/pnpm knip/pnpm lint/ format — all green.examples/**/*.krsin shape + icon modes — 168/168 SVGs byte-identical againstmain.No changeset: internal refactor + test-only addition.
Refs #2512. Test perspectives: TPL-219, TPL-1927 (dual metric), TPL-1954.
🤖 Generated with Claude Code