test(canvas): drive real HTTP run polling with controlled timers

This commit is contained in:
2026-11-11 15:50:08 +08:00
parent 96fc37c319
commit c07f8fbd82
3 changed files with 24 additions and 5 deletions
+4 -3
View File
@@ -2,13 +2,13 @@
import assert from 'node:assert/strict';
import {randomUUID,createHash} from 'node:crypto';
export async function verifyFoundryAI({open,transport,rootId,imageId,assets,calls,advance,loseAdmission,loseAction}){
export async function verifyFoundryAI({open,transport,rootId,imageId,assets,calls,tick,advance,loseAdmission,loseAction}){
const path=`workspaces/${process.env.FOUNDRY_TEST_WORKSPACE}/materials/${rootId}/canvas/ai`;
const control=async action=>{const response=await transport({method:'POST',path:path+'/fixture/'+action,signal:AbortSignal.timeout(15_000)});assert.equal(response.status,200,action+': '+JSON.stringify(response.body));return response.body;};
const posts=suffix=>calls.filter(call=>call.method==='POST'&&call.path.endsWith(suffix));
let engine=await open();const signal=new AbortController().signal;
const reopen=async()=>{await engine.close();advance();engine=await open();await engine.settle();};
const poll=async()=>{await engine.retry();await engine.settle();};
const poll=async()=>{await engine.retry();for(let turns=0;turns<100;turns++){if(!tick())return;await engine.settle();}assert.fail('AI timer drain exceeded its bound');};
try{
const catalog=await engine.models(rootId,signal);assert.ok(catalog.models.some(model=>model.id==='fixture-text'));assert.ok(catalog.models.some(model=>model.id==='fixture-image'));
const target={id:randomUUID(),incarnation:1};
@@ -28,7 +28,8 @@ export async function verifyFoundryAI({open,transport,rootId,imageId,assets,call
const firstRun=byOperation(first.operationIds[0]);assert.ok(firstRun,'resolved admission must publish a RunRecord');assert.equal(firstRun.status,'queued');
assert.equal(engine.editor.dispatch({type:'element.geometry',target,patch:{x:77}}).status,'applied');await engine.settle();
await control('execute');await poll();
assert.equal(engine.getSnapshot().runtime.runs.get(firstRun.id).status,'succeeded');
const generatedText=engine.getSnapshot().runtime.runs.get(firstRun.id);
assert.equal(generatedText.status,'succeeded',JSON.stringify({status:generatedText.status,error:generatedText.error,blocked:generatedText.blocked,cursor:generatedText.cursor}));
assert.equal(engine.getSnapshot().document.elements.get(target.id).data.text,'headless fixture output');assert.equal(engine.getSnapshot().document.elements.get(target.id).geometry.x,77);
assert.deepEqual(engine.getSnapshot().document.elements.get(target.id).data.extension,{keep:true});