← Files ProdVerityARCHIVED FILE

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

2.53 KB · Nov 29, 2026 · 00:48 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 load=async(file,replace=[])=>{
 let js=ts.transpileModule(await readFile(new URL(file,import.meta.url),'utf8'),{compilerOptions:{module:ts.ModuleKind.ESNext,target:ts.ScriptTarget.ES2022}}).outputText
 for(const [from,to] of replace) js=js.replace(from,to)
 return 'data:text/javascript;base64,'+Buffer.from(js).toString('base64')
}
const resourceUrl=await load('../worker/prodverity-ai/resource-policy.ts')
const {evaluateResource,assessCourseDraft}=await import(resourceUrl)
const videoUrl=await load('../worker/prodverity-ai/video-policy.ts',[["from './resource-policy'","from '"+resourceUrl+"'"]])
const {assessVideoDraft}=await import(videoUrl)
const {validatePurgePlan}=await import(await load('../worker/prodverity-ai/cache-policy.ts'))
const resource={url:'https://example.org/lesson',title:'Lesson',license:'CC-BY-4.0',licenseUrl:'https://creativecommons.org/licenses/by/4.0/',publishedAt:'2026-01-01',retrievedAt:'2026-10-02',author:'Author',commercialUse:true,derivativeAllowed:true}
test('open licensed material can be used with provenance',()=>assert.equal(evaluateResource(resource).reusable,true))
test('free to read is not automatically reusable',()=>assert.equal(evaluateResource({...resource,license:'UNKNOWN'}).reusable,false))
test('noncommercial material excluded from commercial course',()=>assert.equal(evaluateResource({...resource,license:'CC-BY-NC-4.0'}).reusable,false))
test('draft requires human review before publication',()=>assert.equal(assessCourseDraft({title:'Course',learningObjectives:['Learn'],lessonOutlines:['Unit'],sources:[resource],reviewedByHuman:false}).publishable,false))
test('video voice consent is required for impersonation',()=>assert.equal(assessVideoDraft({title:'Video',scenes:[{sourceUrl:resource.url,narration:'Hello',visualDescription:'Scene',durationSeconds:15}],resources:[resource],voice:{engine:'local',licenseVerified:true,impersonatesRealPerson:true},captions:true,reviewedByHuman:true}).readyForRender,false))
test('targeted cache purge rejects foreign origin',()=>assert.equal(validatePurgePlan({projectId:'p',zoneId:'z',urls:['https://other.example/a'],purgeEverything:false,expectedRevision:'a'.repeat(40)},'https://example.org').valid,false))
test('global purge requires separate approval',()=>assert.equal(validatePurgePlan({projectId:'p',zoneId:'z',urls:['https://example.org/a'],purgeEverything:true,expectedRevision:'a'.repeat(40)},'https://example.org').valid,false))

SHA-256: 42d55b033623eefca6c5218b7735940cd0ca4a0f39566d975931b6f2a42c0f4c