Back to Limb Race
SOURCE / PINNED RELEASE

Made of little things.

Limb Race

Release
6a8ae4fc626e…
Author-recorded commit
008c01ee6454…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-c2869f12ad8

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

tests/sharing.test.mjs
import assert from 'node:assert/strict';
import test from 'node:test';
import ts from 'typescript';
import {readFile} from 'node:fs/promises';
const urls=new Map();
async function moduleUrl(name){
  if(urls.has(name))return urls.get(name);
  let source=await readFile(new URL(`../src/${name}.ts`,import.meta.url),'utf8');
  for(const match of source.matchAll(/from ['"]\.\/([^'"]+)\.js['"]/g))source=source.replace(match[0],`from '${await moduleUrl(match[1])}'`);
  const code=ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.ES2022,target:ts.ScriptTarget.ES2022}}).outputText;
  const url=`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`;urls.set(name,url);return url;
}
const {encodeDrawing,decodeDrawing}=await import(await moduleUrl('race-data'));
const {starterLevel,validateLevel,levelTrack,validateSnapshot}=await import(await moduleUrl('level-model'));
const {Race,presetDesign,PHYSICS_VERSION}=await import(await moduleUrl('physics'));
test('complete drawings round-trip within half a normalized millipoint and fit the service budget',()=>{
  const drawing=Array.from({length:8},(_,j)=>Array.from({length:30},(_,i)=>({x:Math.cos(i+j),y:Math.sin(i+j)})));
  const data=encodeDrawing(drawing),decoded=decodeDrawing(data);
  assert.ok(Buffer.byteLength(JSON.stringify(data))<8192);
  for(let s=0;s<8;s++)for(let p=0;p<30;p++)for(const axis of ['x','y'])assert.ok(Math.abs(drawing[s][p][axis]-decoded[s][p][axis])<=.000501);
});
for(const [name,data]of Object.entries({empty:{version:1,physics:2,limbs:[]},wrongPhysics:{version:1,physics:1,limbs:[[[0,0],[1,1]]]},oversized:{version:1,physics:2,limbs:[Array(241).fill([0,0])]},badCoordinate:{version:1,physics:2,limbs:[[[0,0],[1001,0]]]},fraction:{version:1,physics:2,limbs:[[[0,0],[.5,0]]]},badTuple:{version:1,physics:2,limbs:[[[0,0],[1,2,3]]]},null:null}))test(`reject shared drawing: ${name}`,()=>assert.throws(()=>decodeDrawing(data)));
test('board schemas require drawings and use the supported bounded schema subset',async()=>{
  const text=await readFile(new URL('../napplet.json',import.meta.url),'utf8'),config=JSON.parse(text);
  assert.ok(Buffer.byteLength(text)<=16384);
  for(const board of config.backend.boards){assert.deepEqual(board.dataSchema.required,['version','physics','limbs']);assert.equal(board.dataSchema.properties.limbs.maxItems,8);assert.ok(Buffer.byteLength(JSON.stringify(board.dataSchema))<8192);}
});
test('all editor pieces produce finite continuous terrain, including real vertical walls',()=>{
  const snapshot={key:'draft:test:1',title:'Terrain tour',data:{physics:PHYSICS_VERSION,pieces:[{kind:'step',width:90,height:95},{kind:'drop',width:90,height:95},{kind:'trench',width:90,height:100},...starterLevel().pieces]}};
  const track=levelTrack(snapshot);assert.ok(track.ground.some((p,i)=>i&&p.x===track.ground[i-1].x&&p.y!==track.ground[i-1].y));
  for(let i=1;i<track.ground.length;i++){const p=track.ground[i],prev=track.ground[i-1];assert.ok(p.x>=prev.x);assert.ok(p.x!==prev.x||p.y!==prev.y);assert.ok(Number.isFinite(p.x)&&Number.isFinite(p.y));}
  assert.ok(track.ground.at(-1).x>track.length);
});
for(const material of ['rigid','bendy'])test(`starter custom level is finishable with ${material} Runner`,()=>{
  const race=new Race(levelTrack({key:'draft:starter:1',title:'Starter',data:starterLevel()}),presetDesign('runner'),material);
  for(let i=0;i<180*120&&!race.finished&&!race.failed;i++)race.step();assert.ok(race.finished,`stuck at ${race.x}`);
});
for(const [name,pieces]of Object.entries({empty:[],tooMany:Array(25).fill({kind:'flat',width:100,height:0}),tooLong:Array(24).fill({kind:'flat',width:600,height:0}),high:Array(3).fill({kind:'step',width:90,height:130}),deep:[{kind:'trench',width:90,height:130},{kind:'drop',width:90,height:100},{kind:'trench',width:90,height:100}],unknown:[{kind:'teleport',width:90,height:10}],fraction:[{kind:'flat',width:50.5,height:0}],nan:[{kind:'step',width:90,height:NaN}]}))test(`reject unsafe custom terrain: ${name}`,()=>assert.throws(()=>validateLevel({physics:PHYSICS_VERSION,pieces})));
test('custom history retains a detached geometry snapshot and public titles',()=>{
  const original={key:`custom:${'a'.repeat(64)}`,title:'A'.repeat(160),data:starterLevel()},saved=validateSnapshot(original);
  original.data.pieces[0].width=500;assert.equal(saved.data.pieces[0].width,300);
  assert.throws(()=>validateSnapshot({...saved,key:'meadow'}));assert.throws(()=>validateSnapshot({...saved,title:'bad\u202ename'}));
});