← Files ProdVerityARCHIVED FILE

source/scripts/prodverity-ai-runtime.test.mjs

1.99 KB · Nov 11, 2026 · 12:42 UTC

↓ Download file

See the change to this file →

import test from 'node:test'
import assert from 'node:assert/strict'
import {readFile} from 'node:fs/promises'
import ts from 'typescript'
const compile=async file=>ts.transpileModule(await readFile(new URL(file,import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText
const data=js=>'data:text/javascript;base64,'+Buffer.from(js).toString('base64')
const policy=data(await compile('../worker/prodverity-ai/task-policy.ts'))
const planner=data(await compile('../worker/prodverity-ai/ai-planner.ts'))
const orchestrator=data((await compile('../worker/prodverity-ai/orchestrator.ts')).replace("from './task-policy.ts'","from '"+policy+"'"))
const runtime=data((await compile('../worker/prodverity-ai/agent-runtime.ts')).replace("from './orchestrator'","from '"+orchestrator+"'").replace("from './ai-planner'","from '"+planner+"'"))
const {runReadOnlyAgent}=await import(runtime)
const model=tasks=>({run:async()=>({response:JSON.stringify({tasks})})})
test('AI plan executes via authorized adapter',async()=>{
 let calls=0
 const result=await runReadOnlyAgent({objective:'Inspect site',projectId:'alpha',model:model([{kind:'inspect',target:'https://example.org/'}]),allowedOrigin:'https://example.org',adapters:{inspect:{run:async()=>{calls++;return {ok:true,detail:'inspected'}}}}})
 assert.equal(result.ok,true);assert.equal(calls,1)
})
test('cross-origin AI plan is rejected before adapter invocation',async()=>{
 let calls=0
 const result=await runReadOnlyAgent({objective:'Inspect',projectId:'alpha',model:model([{kind:'inspect',target:'https://other.example/'}]),allowedOrigin:'https://example.org',adapters:{inspect:{run:async()=>{calls++;return {ok:true,detail:'bad'}}}}})
 assert.equal(result.ok,false);assert.equal(calls,0)
})
test('missing adapter stops execution',async()=>{
 const result=await runReadOnlyAgent({objective:'Inspect',projectId:'alpha',model:model([{kind:'vision'}]),allowedOrigin:'https://example.org',adapters:{}})
 assert.equal(result.ok,false)
})

SHA-256: bb809b947be150de4cd1573c12c547741bf40140a8e96f45e6b742cb41d76b10