Skip to content

refactor(architecture): extract connection routing into routing.mjs - #266

Open
AzScep wants to merge 2 commits into
tt-a1i:mainfrom
AzScep:refactor/extract-routing
Open

refactor(architecture): extract connection routing into routing.mjs#266
AzScep wants to merge 2 commits into
tt-a1i:mainfrom
AzScep:refactor/extract-routing

Conversation

@AzScep

@AzScep AzScep commented Sep 1, 2026

Copy link
Copy Markdown

Problem

renderers/architecture/render-architecture.mjs is a top-level script: it reads process.argv, awaits at module scope, and calls process.exit. The connection router lives inside it and closes over module-scope components, so the only way to route anything is to run a whole render pass over a document on disk.

That makes the router unreachable for any caller that wants to ask "what would this route look like?" about a scene it is still deciding — tooling, a targeted test, or a placement pass. The alternative is reimplementing routeVia, and a second copy of six candidate families plus the near-parallel-port special cases will drift from this one silently.

No linked issue: this changes no schema, contract, validation rule, or output, so it did not seem to warrant a planning issue. Happy to open one if you would rather discuss the seam first.

Change

Moves the routing block into renderers/architecture/routing.mjs, exporting:

createRouter(components, connections) -> { pathFor, connectionSides, connectionEndpointSide }

Each router owns its own pathCache and its own automaticPortSpread call. Function bodies are unchanged — the only edit is that components and connections arrive as arguments rather than module scope.

The region was already self-contained: 309 lines with exactly two references to outer scope (components, and arch.connections for the port spread). No symbol it defines is used elsewhere in the file, and the ten geometry.mjs imports it solely owned move with it.

Moved verbatim: routeClearsComponents, routeClearsEndpointComponents, OUTWARD_SIDE_VECTOR, outwardStub, collinearBacktrack, sideAwareBridgeCandidates, AUTOMATIC_PORT_CORNER_GUTTER, AUTOMATIC_PORT_ALIGNMENT_DELTA, portHasCornerClearance, alignFacingPorts, routeVia, connectionSides, connectionEndpointSide, pathFor.

Compatibility

No behavior change, and the give-up branch's diagnostic contract is untouched — the router still returns a knowingly-bad route so validation reports the real obstacle rather than second-guessing what it was told.

Evidence

  • npm test — 1021 tests, 994 pass, 0 fail, 27 skipped, on this branch from current main.
  • node test/golden.mjs — passes. This is the load-bearing check: it byte-compares fresh renders of every checked-in example against the committed HTML, so an identical result is exactly the property a pure move should have.
  • scripts/generate-validators.mjs --check and generate-brand-marks.mjs --check — in sync, untouched.

Regenerated files

  • archify.zip — the renderer payload gained a file, so the committed archive no longer reproduced from tracked inputs. Rebuilt with scripts/build-zip.sh on Node 22. Nothing else was regenerated.

Disclosure

I built an automatic-layout mode for architecture on a fork, which is what surfaced this: a solver has to score candidate placements against routed geometry, and an approximate router approves layouts the real one then rejects. I am not proposing that feature here — ROADMAP.md is clear that it is out of scope, and this extraction is useful on its own or not at all. Judge it as a refactor.

AzScep and others added 2 commits September 1, 2026 21:34
Moves the connection-routing block out of render-architecture.mjs into a
`createRouter(components, connections)` factory. Function bodies are
unchanged; the only edit is that `components` and `connections` arrive as
arguments instead of module scope, and each router owns its own path
cache and port spread.

Why: render-architecture.mjs is a top-level script, so the router is
reachable only by running a whole render pass. Anything that needs to ask
"what would this route look like?" for a scene it is still deciding -
tooling, a test, a future placement pass - currently cannot, and the
alternative is reimplementing routeVia and letting the copy drift.

The region was already self-contained: 309 lines with exactly two
references to outer scope (`components`, and `arch.connections` for the
port spread). Ten geometry imports it solely owned move with it, and no
symbol it defines is used elsewhere in the file.

No behavior change. test/golden.mjs byte-compares fresh renders of every
checked-in example against the committed HTML and passes unchanged, which
is the property this refactor is asserting.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The renderer payload gained renderers/architecture/routing.mjs, so the
committed archive no longer reproduces from tracked inputs. Rebuilt with
the canonical Node 22 toolchain via scripts/build-zip.sh.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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