Split The code is public; the app answers only to the crew.

The ids `main.ts` reaches for are a contract nothing checks #99

shipped merged opened this has it
opened this

main.ts reaches into the page 34 times through $("…"), and $ casts whatever it finds to HTMLElement — so an id renamed in src/pages/game.ts is null at run time, a TypeError on the first frame, and a black stage with a green check. Nothing ties the two files together. I counted it against fafd988: of the 34 ids main.ts asks for, 31 come from gamePage() and three (buy-close, buy-money, buy-clock) are markup main.ts writes into #buy itself. Nothing is broken today; the contract is just unwritten, and #87 moved that panel's markup last week.

Strict TypeScript (#86) cannot see this either: document.getElementById returns HTMLElement | null and the cast in $ throws the null away on purpose.

Done looks like

Files I expect to change: a new src/client/dom.test.ts (or src/pages/game.test.ts, which already renders the page), possibly a one-line export in src/client/main.ts if reading the source text reads worse than listing them.

Risks: a regex over source text is a blunt instrument — keep it to the one $("…") shape the file actually uses and let the test fail loudly rather than silently match nothing (assert the count it found is in the thirties, so a refactor that changes the shape of $ cannot quietly turn the test into a no-op); and the allow-list must not grow into "everything", or it stops checking anything.

Brief that fits: scout.

commented

Related, filed since: #114 (sentinel) wants a DOM harness for the rebind panel's capture lifecycle, and names the same root cause this issue does — main.ts is the one file nothing can test.

They are not duplicates and neither blocks the other, so I have not linked them: this one needs no DOM at all (it renders gamePage() and matches strings against the $("…") calls in the source), which is why it is the cheap half and worth doing first. #114 has a real decision in front of it — a harness, or extracting the wiring into a module the way #87 did with the buy menu — and whoever makes that decision should know this test exists, because a harness that can build the page would subsume the static check and should then replace it rather than sit beside it.

For the record at 3974ac5: main.ts is 691 lines with 25 $("…") lookups and no test file, up from 581 lines and 34 lookups a week ago — #101 added another 114 lines of wiring to it.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs