v0.8.3 — the engine half of the audit, and the deal 0.8.2 silently changed

Seven rules faults and one dealing fault, from a four-way code audit (engine, server,
client, tests) read against the code before anything was acted on. Each is pinned by a
test that failed first. CHANGELOG has the reasoning; this is the list.

THE DEAL. 0.8.2 put the Second Section card into the deck after its save check had run
and without a line in its notes. A deck one card larger shuffles differently from the same
seed, so every save on the test server refused at move 3 — the boot log shows thirteen of
thirteen — while the release notes said three would resume. `withSavedDeal` (was
`withSavedOpening`) now sets `secondSectionCard: false` for a config that predates the
setting, and the thirteen replay exactly as 0.8.2 described: three resume, ten refuse, the
same ten at the same moves.

THE RULES. `check` never tested that a switching tray was in the actor's own district, so
a rival's train could be shunted and the rival charged the Moves. Occupancy matched on
coordinates alone, so a rival's crew blocked your track. A Department draw that emptied the
deck duplicated the drawn card and destroyed the refill card. The unjam cleared the first
load rather than the one named. The collision floor could not fire in Stage 12. The
Expedite fault was charged once per clearance question rather than once per phase. A train
held at the Limits was only ever released by another arrival, never by a departure.

Docs: rules.md describes each as built (and no longer says an Expedited train departs at
Shift Change — that was v0.4.8's reading, corrected in v0.4.9's code and never in the
document); game-state.md's collision-floor note now matches the code.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FrCWubm9GAftYCm2hWdKwK
This commit is contained in:
Jesse.Markowitz
2026-09-29 17:02:31 -04:00
co-authored by Claude Fable 5.1
parent 6f2a8dff09
commit 4d222a7eba
22 changed files with 627 additions and 83 deletions
+71
View File
@@ -1704,3 +1704,74 @@ describe('a train sorted to the nose is judged by §8.2, not by where the engine
assert.match(why, /caboose must be at the rear/, `the hold did not say why: ${why}`);
});
});
// ---------------------------------------------------------------------------
// v0.8.3 — audit findings (2026-09-29)
// ---------------------------------------------------------------------------
describe('the collision floor at the end of a Day (v0.8.3)', () => {
it('fires on a breach reached in Stage 12, before the Day rolls over', () => {
/**
* `shiftChange` reset `collisionsToday` at the Day rollover and only THEN asked whether the Day
* had breached the limit — so a third wreck in Stage 12 was read as zero, and the one Stage of
* the Day in which the floor could not fire was the last one. The tests above all set `stage`
* to 1, which never crosses the rollover.
*/
const s = game(1, { mode: 'competitive', maxCollisionsPerDay: 2 });
s.collisionsToday = 2;
s.clock.stage = STAGES_PER_DAY;
s.clock.phase = 'shiftChange';
advance(s);
assert.equal(s.status, 'finished', 'a breach in the last Stage of the Day went unpunished');
assert.equal(s.outcome!.result, 'loss');
assert.equal(s.outcome!.reason, 'collisionFloor');
});
});
describe('the Expedite fault is charged once per Mainline Phase (v0.8.3)', () => {
it('does not charge again when the phase resumes after a clearance ruling', () => {
/**
* The Q3 fault loop ran unguarded at the top of `mainlinePhase`, and the phase is re-entered
* from the top after every clearance, Yard Office or Red Flag question — so an Expedited train
* left on a siding was fined once per QUESTION rather than once per Phase.
*/
const s = game(7, { days: 5 });
for (const n of s.division.nodes) if (n.kind === 'mainline') n.card = 'plains';
const area = areaOf(s, 0);
// The Expedited train, parked off the station: one fault is due.
s.trays.set('expedited', {
id: 'expedited', trainNumber: 6, trainIsExtra: false, engineAt: 0, consist: [],
direction: 'east', facing: 'e',
position: { at: 'grid', seat: 0, coord: { row: area.officeCoord.row, col: area.officeCoord.col + 1 } }, movesUsed: 0,
});
// A departing train that will put a clearance question to the Superintendent mid-phase.
s.trays.set('leaving', {
id: 'leaving', trainNumber: 12, trainIsExtra: false, engineAt: 0, consist: [],
direction: 'east', facing: 'e', position: { at: 'grid', seat: 0, coord: area.officeCoord }, movesUsed: 0,
});
area.adOccupancy.push('leaving');
const office = s.division.nodes.findIndex((n) => n.kind === 'office' && n.seat === 0);
const ahead = s.division.nodes.findIndex((n, i) => i > office && n.kind === 'mainline');
const node = s.division.nodes[ahead];
assert.equal(node?.kind, 'mainline');
s.trays.set('ahead', {
id: 'ahead', trainNumber: 9, trainIsExtra: false, engineAt: 0, consist: [],
direction: 'east', facing: 'e', position: { at: 'mainline', index: ahead }, movesUsed: 0,
});
if (node?.kind === 'mainline') node.transits.push({ tray: 'ahead', stagesRemaining: 2, stagesTotal: 2, direction: 'east' });
s.clock.phase = 'mainline';
const before = s.players[0]!.revenue;
const first = advance(s);
assert.ok(first.needsInput, 'no clearance question was put, so the phase never resumed');
assert.equal(first.events.filter((e) => e.type === 'expediteFault').length, 1);
// Hold the departing train, so the only Revenue that can move is the fault's.
const ruling = legalActions(s, s.clock.superintendent).find((i) => i.type === 'mainline.clearance' && !i.allow);
assert.ok(ruling, 'no clearance ruling on offer');
assert.ok(applyIntent(s, s.clock.superintendent, ruling).ok);
const resumed = advance(s);
assert.ok(!resumed.events.some((e) => e.type === 'expediteFault'), 'the fault was charged a second time');
assert.equal(s.players[0]!.revenue, before - EXPEDITE_FAULT_PENALTY, 'more than one fault was charged');
});
});