import test from "node:test"; import assert from "node:assert/strict"; import { deriveLaneState, LANE_WORD } from "./laneState"; // THE FOUR STATES, AS LITERALS, and the precedence between them. // // It used to pin a second function beside this one — `sweepLaneNote`, the // sentence a sweep lane gave for not working. That retired with the sweeps in // slice 1.3: every lane is dispatched by a runner now, so the reason a lane is // not working is the runner's own `idleReason`, which the console and the // Active Jobs strip both map through `idleReasonText` / `autoIdleNote`. What is // left here is the state itself, which all four lanes still share. test("the gate decides before anything else", () => { // A running lane behind a shut gate is HOLDING, not running and not stopped: // its limit() returns 0 and the pool idle-waits, which looks exactly like // wedged unless something says otherwise. That state is the reason this is // four strings rather than a boolean. assert.equal(deriveLaneState({ gateHeld: true }), "holding"); assert.equal(deriveLaneState({ gateHeld: true, activeCount: 3 }), "holding"); }); test("unavailable beats the gate", () => { // With no operation switched on there is nothing to hold, and "Holding" would // send an operator to the wrong control. assert.equal(deriveLaneState({ available: false, gateHeld: true }), "unavailable"); assert.equal( deriveLaneState({ available: false, gateHeld: false, activeCount: 2 }), "unavailable", ); }); test("work in flight is the only thing that reads as running", () => { assert.equal(deriveLaneState({ gateHeld: false, activeCount: 1 }), "running"); assert.equal(deriveLaneState({ gateHeld: false, activeCount: 0 }), "idle"); assert.equal(deriveLaneState({ gateHeld: false }), "idle"); }); test("every state has a word, and Off is not Idle", () => { // The word beside the dot is what assistive tech reads, so it has to stand on // its own — and "Off" must never be spelled "Idle": an idle-looking lane // claims "all caught up" where the truth is "nothing would run this". assert.equal(LANE_WORD[deriveLaneState({ available: false, gateHeld: false })], "Off"); assert.equal(LANE_WORD[deriveLaneState({ gateHeld: true })], "Holding"); assert.equal(LANE_WORD[deriveLaneState({ gateHeld: false })], "Idle"); assert.equal( LANE_WORD[deriveLaneState({ gateHeld: false, activeCount: 1 })], "Running", ); });