Back to Big Rig Rush
SOURCE / PINNED RELEASE

Made of little things.

Big Rig Rush

Release
ec9b6549f752…
Author-recorded commit
74b729258b1a…
License
LICENSE
Author’s source reference
nostr://npub1sj2vketepqw9v6fmge5fdzuj7atj9sv6qv2jss05n2z6rl64lcfqumdsnt/wss%3A%2F%2Fgit.napplet.soy%2F/n-0a99f0cae40

Archive hash verified: 900e22810340ccb1…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

tests/dispatch.test.mjs
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import ts from 'typescript';
const source=readFileSync(new URL('../src/game/dispatch.ts',import.meta.url),'utf8');
const js=ts.transpileModule(source,{compilerOptions:{target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.ES2022}}).outputText;
const { Dispatcher }=await import(`data:text/javascript;base64,${Buffer.from(js).toString('base64')}`);
function fixture() {
  const state={mess:[{x:0,y:0,n:5}],wrecks:[],fires:[],injured:[],trapped:[],cleanups:[],roadcrew:0,covered:false,bins:[{x:0,y:0,kind:'bin'}],carcasses:[],fixes:0};
  const world={
    traffic:{wrecks:state.wrecks,all:()=>state.wrecks,burningNear:()=>[]},
    peds:{injured:()=>state.injured,injuredNear:(x,y,r)=>state.injured.filter(p=>Math.hypot(p.x-x,p.y-y)<r)},
    effects:{allFires:()=>state.fires,messSpots:()=>state.mess,firesNear:(x,y,r)=>state.fires.filter(p=>Math.hypot(p.x-x,p.y-y)<r),cleanup:(x,y)=>state.cleanups.push({x,y}),roadDamage:()=>[{x:0,y:0}],structureDamage:()=>[{x:0,y:0}]},
    services:{vehicles:[],available:()=>state.roadcrew,covering:()=>state.covered},
    street:{broken:()=>[],fullBins:()=>state.bins,items:state.bins,fix:()=>state.fixes++},
    wildlife:{carcasses:state.carcasses,removeCarcass:(a)=>state.carcasses.splice(state.carcasses.indexOf(a),1)},
    sound:()=>{},hour:()=>8,truck:{x:0,y:0},brokenProps:()=>[],burning:()=>[],rescueSites:()=>state.trapped,
  };
  return {state,dispatch:new Dispatcher(world)};
}
const incident=(stage='respond',x=0)=>({x,y:0,r:60,layer:0,stage,born:0,stageAt:0});
function settle(dispatch) { dispatch.sweep(); dispatch.time+=13; }
test('stray debris waits for quiet, new debris restarts wait, and unrelated routine cleanup remains available',()=>{
  const {dispatch,state}=fixture(); assert.equal(dispatch.sweep().length,0);
  settle(dispatch); assert.equal(dispatch.sweep().length,1);
  state.mess[0].n+=1; assert.equal(dispatch.sweep().length,0);
  dispatch.time+=13; assert.equal(dispatch.sweep().length,1);
});
test('sweepers wait through response and towing, then back up the final cleanup crew',()=>{
  const {dispatch,state}=fixture(); const scene=incident();dispatch.incidents.push(scene);
  settle(dispatch); assert.equal(dispatch.sweep().length,0);
  scene.stage='tow';assert.equal(dispatch.sweep().length,0);
  scene.stage='clean';assert.equal(dispatch.sweep().length,1);
  state.roadcrew=1;assert.equal(dispatch.sweep().length,0);
  state.roadcrew=0;state.covered=true;assert.equal(dispatch.sweep().length,0);
});
test('scene margins and nearby victims, fires, wrecks and trapped people block cleanup',()=>{
  for(const kind of ['fires','injured','wrecks','trapped']) {
    const {dispatch,state}=fixture();settle(dispatch);
    state[kind].push({x:20,y:0,layer:0,trapped:1});
    assert.equal(dispatch.sweep().length,0,kind);
    assert.equal(dispatch.repairs().length,0,kind);
    assert.equal(dispatch.roads().length,0,kind);
  }
  const {dispatch}=fixture();settle(dispatch);
  dispatch.incidents.push(incident('respond',110));
  assert.equal(dispatch.sweep().length,0,'debris outside scene circle remains in emergency access margin');
});
test('an assigned sweeper stops work if an emergency develops; new work points cannot draw it into danger',()=>{
  const {dispatch,state}=fixture();settle(dispatch);const job=dispatch.sweep()[0];
  assert.equal(job.task.valid(),true);assert.equal(job.task.points().length,1);
  state.mess.push({x:70,y:0,n:5});
  assert.equal(job.task.points().length,1,'new unsettled debris excluded');
  state.fires.push({x:10,y:0});
  assert.equal(job.task.valid(),false);
  job.task.onWorking({x:0,y:0});job.task.onPointDone({x:0,y:0});
  assert.equal(state.cleanups.length,0);
});
test('repair crews wait for final recovery and cleanup assignments invalidate when a scene regresses',()=>{
  const {dispatch}=fixture();const scene=incident('respond');dispatch.incidents.push(scene);
  assert.equal(dispatch.repairs().length,0);assert.equal(dispatch.roads().length,0);
  scene.stage='tow';assert.equal(dispatch.repairs().length,0);assert.equal(dispatch.roads().length,0);
  scene.stage='clean';const repair=dispatch.repairs()[0];const road=dispatch.roads()[0];
  assert.ok(repair);assert.ok(road);assert.equal(road.task.valid(),true);
  scene.stage='respond';assert.equal(repair.task.valid(),false);assert.equal(road.task.valid(),false);
});

test('a new wreck during cleanup sends the incident back to towing',()=>{
  const {dispatch,state}=fixture();const scene=incident('clean');dispatch.incidents.push(scene);
  state.wrecks.push({x:0,y:0,layer:0});dispatch.monitor();
  assert.equal(scene.stage,'tow');assert.equal(dispatch.sweep().length,0);
  state.wrecks.length=0;dispatch.monitor();assert.equal(scene.stage,'clean');
});

test('garbage collection waits through response, towing and cleanup, then resumes after reopening',()=>{
  const {dispatch}=fixture();assert.equal(dispatch.garbage().length,1);
  const scene=incident();dispatch.incidents.push(scene);
  for(const stage of ['respond','tow','clean']) {
    scene.stage=stage;assert.equal(dispatch.garbage().length,0,stage);
  }
  dispatch.incidents.length=0;assert.equal(dispatch.garbage().length,1);
});
test('garbage assignments and work points respect new emergencies and scene margins',()=>{
  const {dispatch,state}=fixture();const job=dispatch.garbage()[0];
  assert.equal(job.task.valid(),true);
  dispatch.incidents.push(incident('respond',110));
  assert.equal(dispatch.garbage().length,0);
  assert.equal(job.task.valid(),false);assert.equal(job.task.points().length,0);
  job.task.onPointDone({x:0,y:0});assert.equal(state.fixes,0);assert.equal(state.cleanups.length,0);
  dispatch.incidents.length=0;
  state.fires.push({x:20,y:0});assert.equal(dispatch.garbage().length,0);
});
test('safe trash pickup continues elsewhere and roadkill/broken bins cannot bypass scene gating',()=>{
  const {dispatch,state}=fixture();dispatch.incidents.push(incident('clean'));
  state.bins.push({x:500,y:0,kind:'bin'});
  state.carcasses.push({x:10,y:0});
  const jobs=dispatch.garbage();assert.equal(jobs.length,1);assert.equal(jobs[0].x,500);
  jobs[0].task.onPointDone({x:500,y:0});assert.equal(state.fixes,1);
  assert.equal(state.carcasses.length,1);
});