Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

5.9 KB
Raw Blame
import assert from 'node:assert/strict';import {mkdir,cp,mkdtemp,readFile,writeFile} from 'node:fs/promises';import {tmpdir} from 'node:os';import {join,resolve} from 'node:path';import {fileURLToPath,pathToFileURL} from 'node:url';
import {fixtures,revise} from './fixtures.mjs';import {exportGame} from '../template/tools/export.mjs';import {Game,simulate} from '../template/studio/engine.mjs';import {digest,canonical} from '../template/studio/project.mjs';import {browserPath} from '../toolchain/browser.mjs';import {chromium} from '../toolchain/node_modules/playwright-core/index.mjs';
const pkg=fileURLToPath(new URL('..',import.meta.url)),out=resolve(process.env.GAME_ACCEPTANCE_ROOT??'work/experience-evidence/relay-acceptance');await mkdir(out,{recursive:true});const root=await mkdtemp(join(tmpdir(),'relay-acceptance-'));await cp(join(pkg,'template'),root,{recursive:true});process.env.GAME_DSH_DIR=pkg;const browser=await chromium.launch({executablePath:await browserPath(),headless:true}),results=[];
try{for(const initial of await fixtures())for(const [stage,p] of [['before',initial],['after',revise(initial)]]){
 const folder=join(out,p.id,stage),delivery=await exportGame(root,folder,{project:p});const rules=await import('data:text/javascript;base64,'+Buffer.from(p.rules).toString('base64'));const model=new Game(p,rules,'route-proof');const context=await browser.newContext({viewport:{width:1512,height:1080},acceptDownloads:true});const page=await context.newPage(),errors=[];page.on('pageerror',e=>errors.push(e.message));await page.goto(pathToFileURL(join(folder,'game.html')).href);await page.waitForFunction(()=>document.querySelector('#turn-title').textContent.length>0);
 // Change the actual UI seed and keep the prior game. Every following move is a real button click.
 await page.locator('#seed').fill('route-proof');const keep=page.waitForEvent('download');await page.locator('#restart').click();await(await keep).saveAs(join(folder,'initial-playtest.zip'));await page.waitForFunction(()=>document.querySelector('#notice').textContent.includes('fresh playtest'));
 const click=async id=>{if(await page.locator('#curtain').isVisible())await page.locator('#reveal').click();const action=model.legal().find(a=>a.id===id);model.step(id);await page.locator('#actions button[data-move="'+id+'"]').click();await page.waitForFunction(n=>document.querySelector('#turn-count').textContent==='Turn '+n,model.actions.length);};
 if(p.id==='signal-garden'){for(let i=0;i<9&&!model.outcome();i++)while(model.state.rotations[i]&&!model.outcome())await click('rotate-'+i);assert.deepEqual(model.outcome().winners,[0]);}
 else{while(!model.outcome()){let id=model.legal()[0].id;if(p.id==='night-ferry')id=rules.bot(model.view().view,model.legal());await click(id);}}
 assert.equal(await page.locator('#turn-title').textContent(),model.outcome().title);await page.screenshot({path:join(folder,'played.png'),fullPage:true});const replayDownload=page.waitForEvent('download');await page.locator('#save-replay').click();await(await replayDownload).saveAs(join(folder,'human-input-replay.json'));const replay=JSON.parse(await readFile(join(folder,'human-input-replay.json'),'utf8'));assert.equal(replay.state,canonical(model.state));assert.deepEqual(replay.actions,model.actions);

 let lossTurns=null;
 if(p.id==='signal-garden'){
  const losing=new Game(p,rules,'route-proof'),kept=page.waitForEvent('download');await page.locator('#restart').click();await(await kept).saveAs(join(folder,'winning-playtest.zip'));await page.waitForFunction(()=>document.querySelector('#turn-count').textContent==='Turn 0');
  while(!losing.outcome()){losing.step('rotate-0');await page.locator('#actions button[data-move="rotate-0"]').click();await page.waitForFunction(n=>document.querySelector('#turn-count').textContent==='Turn '+n,losing.actions.length);}
  assert.deepEqual(losing.outcome().winners,[]);assert.equal(await page.locator('#turn-title').textContent(),losing.outcome().title);lossTurns=losing.actions.length;const saved=page.waitForEvent('download');await page.locator('#save-replay').click();await(await saved).saveAs(join(folder,'losing-path-replay.json'));await page.screenshot({path:join(folder,'losing-path.png'),fullPage:true});
 }
 // A browser revision remains authored source and can be kept without replacing the edition on the table.
 await page.locator('[data-tab=rules]').click();const body=page.locator('[data-body="0"]');await body.fill(initial.rulebook[0].body+' Playtest note: review the physical kit with new players.');await body.blur();await page.locator('[data-tab=print]').click();const save=page.waitForEvent('download');await page.locator('#export-project').click();await(await save).saveAs(join(folder,'reopened-edited.relay.json'));assert.match(JSON.parse(await readFile(join(folder,'reopened-edited.relay.json'),'utf8')).rulebook[0].body,/Playtest note/);
 const simulation=simulate(p,rules,{count:80}),repeated=simulate(p,rules,{count:80});assert.deepEqual(simulation,repeated);assert.equal(simulation.errors,0);await writeFile(join(folder,'simulation.json'),JSON.stringify(simulation,null,2));assert.deepEqual(errors,[]);
 const approved=initial.components.filter(c=>c.locked);for(const c of approved)assert.deepEqual(c,p.components.find(x=>x.id===c.id));results.push({id:p.id,stage,title:p.title,folder,revision:await digest(p),approved:await Promise.all(approved.map(async c=>({id:c.id,sha256:await digest(c)}))),humanTurns:model.actions.length,lossTurns,outcome:model.outcome(),simulation:{games:simulation.count,completed:simulation.completed,errors:simulation.errors,capped:simulation.capped,wins:simulation.wins},files:delivery.files,errors});console.log('ok  '+p.title+' '+stage+' · '+model.actions.length+' human-input turns');await context.close();
 }}finally{await browser.close();}
await writeFile(join(out,'acceptance.json'),JSON.stringify({scope:'Six authored game deliveries and targeted revisions, exercised through real browser inputs. Not a customer or installed-agent prompt trial.',results},null,2));console.log(out);