← Files ProdVerityARCHIVED FILE
source/scripts/prodverity-ai-policy.test.mjs
2.56 KB · Nov 29, 2026 · 00:48 UTC
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import ts from 'typescript'
const source = await readFile(new URL('../worker/prodverity-ai/task-policy.ts', import.meta.url),'utf8')
const js = ts.transpileModule(source,{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText
const {authorizeTask,summarizeEvidence}=await import('data:text/javascript;base64,'+Buffer.from(js).toString('base64'))
const now=new Date('2026-10-02T12:00:00Z')
const grant={projectId:'alpha',approvedBy:'owner',actions:['code_patch','deploy','cache_purge_targeted'],expiresAt:'2026-10-03T12:00:00Z',allowedTargets:['https://alpha.example/a.css']}
test('read-only inspection allowed without grant',()=>assert.equal(authorizeTask({kind:'inspect',projectId:'alpha'},null,now).status,'AUTHORIZED'))
test('write blocked without grant',()=>assert.equal(authorizeTask({kind:'deploy',projectId:'alpha'},null,now).status,'BLOCKED'))
test('cross-project write blocked',()=>assert.equal(authorizeTask({kind:'deploy',projectId:'beta'},grant,now).status,'BLOCKED'))
test('expired grant blocked',()=>assert.equal(authorizeTask({kind:'deploy',projectId:'alpha'},grant,new Date('2026-10-04')).status,'BLOCKED'))
test('target restriction blocks unlisted URL',()=>assert.equal(authorizeTask({kind:'cache_purge_targeted',projectId:'alpha',target:'https://alpha.example/b.css'},grant,now).status,'BLOCKED'))
test('targeted purge permitted for exact authorized URL',()=>assert.equal(authorizeTask({kind:'cache_purge_targeted',projectId:'alpha',target:'https://alpha.example/a.css'},grant,now).status,'AUTHORIZED'))
test('global purge not implicitly permitted',()=>assert.equal(authorizeTask({kind:'cache_purge_all',projectId:'alpha'},grant,now).status,'BLOCKED'))
test('API purge acceptance alone is not visual verification',()=>assert.deepEqual(summarizeEvidence({cachePurgeApiAccepted:true}),{CODE_CORRECTED:false,DEPLOYMENT_VERIFIED:false,CACHE_PURGE_ACCEPTED:true,VISUAL_FIX_VERIFIED:false}))
test('deployment requires matching revision and public HTTP',()=>assert.equal(summarizeEvidence({codeCommit:'a',deployedRevision:'b',publicHttpVerified:true}).DEPLOYMENT_VERIFIED,false))
test('global purge remains blocked even if listed in general grant',()=>assert.equal(authorizeTask({kind:'cache_purge_all',projectId:'alpha'}, {...grant,actions:[...grant.actions,'cache_purge_all']},now).status,'BLOCKED'))
test('deployment requires explicit target even with grant',()=>assert.equal(authorizeTask({kind:'deploy',projectId:'alpha'},grant,now).status,'BLOCKED'))
SHA-256: cb9d5ddb750b120e52a6eec8e3f88860ed6b6879c2435a1d0a65ce1cd2d8a289