fix(canvas): negotiate v2 for headless AI requests
This commit is contained in:
@@ -20,7 +20,7 @@ export async function verifyFoundryAI({open,transport,rootId,imageId,assets,call
|
||||
|
||||
// A committed admission whose response was lost must be queried after reopen.
|
||||
loseAdmission();const first=await begin(input),admission=[...engine.getSnapshot().runtime.ledger.requests.values()].find(request=>request.kind==='run.start'&&request.operationIds.includes(first.operationIds[0]));
|
||||
assert.equal(admission.phase,'waiting');const admissionCount=posts('/ai/runs').length;
|
||||
assert.equal(admission.phase,'waiting');assert.equal(posts('/ai/runs').at(-1).response?.httpStatus,202,'must lose a committed admission, not a rejection');const admissionCount=posts('/ai/runs').length;
|
||||
await reopen();assert.equal(posts('/ai/runs').length,admissionCount);assert.equal(engine.getSnapshot().runtime.ledger.requests.get(admission.id).body,admission.body);
|
||||
assert.ok(calls.some(call=>call.method==='GET'&&call.path.endsWith('/ai/operations/'+admission.id)));
|
||||
const recovered=engine.getSnapshot().runtime.ledger.requests.get(admission.id);
|
||||
|
||||
@@ -3,7 +3,7 @@ import assert from 'node:assert/strict';
|
||||
import { createDocument, applyChanges, createRegistry, builtinComponents } from '../../src/lib/canvas-core/index.ts';
|
||||
import { openProjectEngine } from '../../src/lib/canvas-runtime/engine.ts';
|
||||
import { decodeRecovery } from '../../src/lib/canvas-runtime/recovery.ts';
|
||||
import { createFoundryPersistence, createFoundryRuns, mergeFoundryRunContext } from '../../src/lib/canvas-service/index.ts';
|
||||
import { createFoundryPersistence, createFoundryRuns, createFoundryTransport, mergeFoundryRunContext } from '../../src/lib/canvas-service/index.ts';
|
||||
import { createNetworkGate } from '../../src/lib/canvas-runtime/network.ts';
|
||||
|
||||
const id=n=>`10000000-0000-4000-8000-${String(n).padStart(12,'0')}`,root=id(1),child=id(2),workspace=id(3),account=id(4),target={id:'a',incarnation:1};
|
||||
@@ -293,6 +293,27 @@ test('saved successful cancel and apply receipts recover controls without sendin
|
||||
}
|
||||
});
|
||||
|
||||
test('AI admission, cancel and apply negotiate canvas v2 through the shared HTTP transport',async()=>{
|
||||
for(const action of ['start','cancel','apply']){
|
||||
const f=fixture(),engine=await f.open();
|
||||
try{
|
||||
engine.startRun(runInput);await engine.settle();const runId=[...engine.getSnapshot().runtime.runs.keys()][0];
|
||||
if(action==='cancel'){engine.cancelRun(runId);await engine.settle();}
|
||||
if(action==='apply'){f.finish('retained',true);await f.clock.advance(0);await engine.settle();engine.applyRunOutput(runId,target,id(999));await engine.settle();}
|
||||
const request=[...engine.getSnapshot().runtime.ledger.requests.values()].find(request=>request.kind==='run.'+action),receipt=f.receipts.get(request.id),calls=[];
|
||||
const transport=createFoundryTransport({accountId:account,isCurrentIdentity:()=>true,fetch:async(url,input)=>{
|
||||
calls.push({url,input});
|
||||
if(input.headers.Accept!=='application/vnd.foundry.canvas+json;version=2')return Response.json({error:'canvas_schema_upgrade_required'},{status:409});
|
||||
return Response.json(receipt,{status:action==='start'&&input.method==='POST'?202:200});
|
||||
}}),port=createFoundryRuns({workspaceId:workspace,rootId:root,registry,transport}),signal=new AbortController().signal;
|
||||
assert.equal((await port.submit(request,signal)).outcome,'applied');assert.equal((await port.query(request,signal)).outcome,'applied');
|
||||
assert.equal(calls[0].input.body,request.body);assert.equal(calls[0].input.headers['Idempotency-Key'],request.id);
|
||||
assert.equal(calls[0].input.headers['If-Match'],action==='cancel'?undefined:`"${request.expectedVersions[root]}"`);
|
||||
assert.equal(calls[1].input.method,'GET');assert.equal(calls[1].input.body,undefined);assert.equal(calls[1].input.headers['Idempotency-Key'],undefined);
|
||||
}finally{await engine.close();}
|
||||
}
|
||||
});
|
||||
|
||||
test('historical AI success proofs bind immutable request, operation, run, target, version and frozen plan',async()=>{
|
||||
for(const action of ['start','cancel','apply']){
|
||||
const f=fixture(),engine=await f.open();engine.startRun(runInput);await engine.settle();const runId=[...engine.getSnapshot().runtime.runs.keys()][0];
|
||||
|
||||
Reference in New Issue
Block a user