Skip to content

Extract the arithmetic into wiring/engine.js, pinned by recordings of the tool - #17

Open
nicobrinkkemper wants to merge 1 commit into
ShamojiSMM:mainfrom
nicobrinkkemper:engine-and-golden-tests
Open

Extract the arithmetic into wiring/engine.js, pinned by recordings of the tool#17
nicobrinkkemper wants to merge 1 commit into
ShamojiSMM:mainfrom
nicobrinkkemper:engine-and-golden-tests

Conversation

@nicobrinkkemper

@nicobrinkkemper nicobrinkkemper commented Aug 26, 2026

Copy link
Copy Markdown

Goal

Make it safe to change TrackConductor without breaking the numbers. This PR adds no feature. It does two things:

  1. Tests that pin the current behaviour. Before any code was touched, the output of the live tool was recorded for 472 inputs (160 Collecting Generator runs across every type, loading type and landing pattern; 312 Wiring Generator lookups). npm test checks that the calculation still produces exactly those results. Any future change that alters a delay, a height or a grade fails the test, and an intended change shows up as a small diff in test/fixtures.
  2. The arithmetic in one place. The calculations move out of the page's event handlers into wiring/engine.js, plain functions with no DOM. script.js keeps the page behaviour and calls the engine. This is what makes the tests possible, and it is groundwork for the translation and UI work discussed with Nico: those can then touch the page without touching the maths.

The page looks and behaves the same. The one exception is a bug fix described below.

目的: 計算結果を変えずにツールを改修できるようにすることです。機能追加はありません。(1) 元ツールの出力を472ケース記録し、npm test で同一であることを検証します。(2) 計算部分を wiring/engine.js にまとめ、ページ側(script.js)はそれを呼ぶだけにしました。見た目と挙動は同じです。例外は下記のバグ修正1点のみです。

Bug fix (the only behaviour change)

findWiringResults decided the water/ground search rule from the Collecting Generator's type selector (typeKeys) rather than the Wiring Generator's own. With Collecting on "Winged, Ground" and Wiring on "Winged, Underwater", the search ran with the ground rule. The engine now derives the rule from the Wiring Generator's type. npm run test:page (Playwright, drives the real page) checks this against the recorded underwater results; it fails on the previous script.js and passes now.

配線生成の水中/地上判定が、配線側ではなく集音側のタイプ選択を参照していました。配線側の選択を参照するように修正しています。

Details

  • wiring/engine.js: noteFrames, columnTimes, landingColumnDelays, scrollColumnDelays, collect (the Collecting Generator), grade / findWirings (one search instead of the two copies isWirable and findWiringResults), wiringTiles (the rail diagram).
  • wiring/data.js and wiring/script.js are ES modules. No build step, no bundler; package.json exists only for the test scripts. old/ is untouched.
  • test/README.md explains npm test, npm run test:page and npm run record (re-record fixtures after an intentional change). Fixtures are one case per line so diffs stay readable.
  • Line endings follow the existing files (CRLF).

… the tool

The Collecting and Wiring generators computed everything inside DOM event
handlers, with the rail search written twice (isWirable and
findWiringResults). engine.js now holds the whole calculation as plain
functions; script.js reads the page, calls the engine, and writes the
result back. data.js and script.js are ES modules; the site still has no
build step.

Before extracting, test/record-goldens.mjs recorded the original tool's
output for 160 collecting runs and 312 wiring lookups (test/fixtures).
`npm test` replays them through the engine and passes; re-recording from
the refactored page yields byte-identical fixtures.

One behaviour change, covered by test/page.test.mjs: the Wiring Generator
took its water/ground rule from the Collecting Generator's type selector
(typeKeys) instead of its own, so with Collecting on ground and Wiring on
water it searched with the ground rule. It now uses its own selector.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@nicobrinkkemper

Copy link
Copy Markdown
Author

I had my ai test the system and do some translations. Also found one bug. Feel free to ignore, use this code or request changes, i pr'd it for visibility

@ShamojiSMM

Copy link
Copy Markdown
Owner

@nicobrinkkemper

Thank you for your PR - that's amazing!
Actually I'm quite busy right now, so I'll rewrite my code at a later date.

Thanks again!

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.

2 participants