v0.7.9.1 — the engine was right twice; the screen was not

Gitea#22: the Division map drew every westbound train in the wrong half of
its Mainline card. `regionOfTransit` counts from the end a train entered,
which is what the collision rules ask; the map wanted "which printed box,
left to right" and used the same number, so an eastbound train came out
right by luck and a westbound one came out mirrored. It cost a collision —
Train 3 was cleared to follow T5 and ran into TX17, which the picture had
drawn ahead of T5 rather than behind it. One mirror in `view.ts`, at the
boundary the map is drawn from; the collision rules are untouched.

Gitea#21: a second tank car would not come off at a refinery, and "Blocked
— why nothing is moving" answered by describing the refinery's green box.
The real answer was Train 3's printed rule — the Express works one freight
car per location — so the refusal was correct and the panel sent the player
to spend a Freight Agent action that could not have helped. No rule
changed. The panel now names the budget, asking the reducer's own
predicate so its words cannot drift from the rule.

Both were replayed from the saves attached to the issues and verified in
the exact position each report names. The map fix is proved by mutation:
reverting the mirror fails two tests, and making the renderer ignore the
region fails a third. Every existing region test ran eastbound, where the
mirror is the identity, which is why the bug survived them.

891 tests pass, up from 884.

Closes #21
Closes #22

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E3Qk7uresKCHksdZajXCLg
This commit is contained in:
Jesse.Markowitz
2026-09-07 11:41:23 -04:00
co-authored by Claude Opus 5
parent 6058f6c17e
commit 7ade60e21f
11 changed files with 412 additions and 21 deletions
+39
View File
@@ -3253,6 +3253,45 @@ describe('the Division map shows the whole route', () => {
}
}
});
/**
* GITEA#22 — and the same invariant, applied to the trains standing on a card.
*
* The mirror itself is proved on the view in `mainline-cards.test.ts`. This is the other end of
* it: that the number the view hands over actually reaches the canvas as a position, so the chip
* a player looks at is on the correct half. The report was about the PICTURE, and a view that is
* right behind a renderer that ignores it would read to a player as no fix at all.
*
* Asserted on x, the way the Heavy Grade wedge above is: east is right on this map, so a
* westbound train that has just entered belongs to the RIGHT of one that is nearly across, and
* an eastbound pair in the same state belongs the other way round.
*/
it('draws a westbound train on the half of the card it is actually standing on (Gitea#22)', () => {
const card = (trains: { label: string; region: number }[]): DivisionView =>
({
kind: 'ml', label: 'Curves', capacity: 1, modifiers: [], gradeUp: null, regions: 2,
what: 'two regions',
trains: [trains.map((t) => ({ ...t, cars: [], facing: 'w' }))],
} as unknown as DivisionView);
const xOf = (svg: string, label: string): number => {
const m = new RegExp(`<text class="bs-tlab" x="([\\d.]+)"[^>]*>${label}[^<]*<`).exec(svg);
assert.ok(m, `no chip drawn for ${label}`);
return Number(m![1]);
};
// The two regions the view now reports for the seed 550943578 card: TX17 had just entered
// westbound (the east box, index 1) and T5 was nearly across (the west box, index 0).
const svg = divisionSvg([card([{ label: 'TX17', region: 1 }, { label: 'T5', region: 0 }])]);
assert.ok(
xOf(svg, 'TX17') > xOf(svg, 'T5'),
'the train that has just entered westbound was not drawn east of the one nearly across',
);
// And the halves are genuinely distinct — a renderer that centred both would satisfy nothing
// above but would still tell a player nothing.
assert.notEqual(xOf(svg, 'TX17'), xOf(svg, 'T5'), 'both chips were drawn at the same x');
});
});
describe('every square the menu offers can actually be clicked (regression)', () => {