52 lines
4.1 KiB
JavaScript
52 lines
4.1 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { officialSnapshot, verifyOfficialContracts, contractDifference, sourceInventory, SOURCE_MANIFESTS, sha256 } from '../scripts/official-contract-check.mjs';
|
|
|
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
|
|
test('complete pinned official sources, every registry fact and named regressions match the reviewed snapshot',()=>{
|
|
const result=verifyOfficialContracts(root); assert.equal(result.passed,true); assert.equal(result.recordsCount,26);
|
|
assert.equal(result.sourceInventory.length,4); assert.ok(result.testFiles.includes('tests/native-cache-state.test.mjs'));
|
|
for(const manifest of result.sourceInventory) for(const source of manifest.sources) assert.match(source.sha256,/^[a-f0-9]{64}$/);
|
|
});
|
|
|
|
test('an official field, retired alias, API version or original byte update cannot disappear behind an unchanged version',()=>{
|
|
const previous=officialSnapshot(root),changed=structuredClone(previous);
|
|
const alias=changed.registry.records.find(record=>record.fields.lifecycle?.value==='deprecated');
|
|
alias.fields.lifecycle.value='active';
|
|
const newVersion=structuredClone(changed.registry.records.find(record=>record.provider==='anthropic')); newVersion.apiVersion='future-official-version'; changed.registry.records.push(newVersion);
|
|
changed.registry.records[0].fields.maxOutputTokens.value+=1;
|
|
changed.sourceInventory[0].sources[0].sha256='f'.repeat(64);
|
|
const result=contractDifference(previous,changed);
|
|
assert.equal(result.equal,false); assert.equal(result.reviewRequired,true); assert.equal(result.missingRegistryVersionBump,true);
|
|
for(const category of ['deprecation','model-protocol-api-version','model-field','original-source-bytes']) assert.ok(result.changes.some(change=>change.category===category),category);
|
|
changed.registry.version+='-reviewed-next'; assert.equal(contractDifference(previous,changed).missingRegistryVersionBump,false);
|
|
assert.equal(contractDifference(previous,changed).reviewRequired,true,'A version label alone does not prove a reviewed change');
|
|
assert.equal(previous.registry.records.find(record=>record.fields.lifecycle?.value==='deprecated').fields.lifecycle.value,'deprecated');
|
|
});
|
|
|
|
test('request defaults and authentication changes require an explicit new request-contract version, independently of model facts',()=>{
|
|
const previous=officialSnapshot(root),changed=structuredClone(previous);
|
|
changed.requestContract.defaults['anthropic:new'].anthropicVersion='future-version';
|
|
let result=contractDifference(previous,changed); assert.equal(result.missingRequestVersionBump,true); assert.equal(result.missingRegistryVersionBump,false);
|
|
changed.requestContract.defaultsVersion+='-next'; result=contractDifference(previous,changed); assert.equal(result.missingRequestVersionBump,false);
|
|
assert.ok(result.changes.some(change=>change.category==='request-version-auth-defaults'));
|
|
});
|
|
|
|
test('source SHA failure remains failure even when a source was marked rejected rather than used as an official fact',t=>{
|
|
const temporary=fs.mkdtempSync(path.join(os.tmpdir(),'awb-ci-source-'));
|
|
t.after(()=>{assert.equal(path.dirname(path.resolve(temporary)),path.resolve(os.tmpdir()));assert.ok(path.basename(temporary).startsWith('awb-ci-source-'));fs.rmSync(temporary,{recursive:true,force:true});});
|
|
for(const relative of SOURCE_MANIFESTS){
|
|
const folder=path.dirname(path.join(temporary,relative));fs.mkdirSync(folder,{recursive:true});
|
|
const bytes=Buffer.from('owned-original-failure-body'); fs.writeFileSync(path.join(folder,'body.txt'),bytes);
|
|
fs.writeFileSync(path.join(temporary,relative),JSON.stringify({sources:[{id:'owned-source',file:'body.txt',sha256:sha256(bytes),accepted:false,url:'https://example.invalid/pinned'}]}));
|
|
}
|
|
assert.equal(sourceInventory(temporary)[0].sources[0].accepted,false);
|
|
fs.appendFileSync(path.join(path.dirname(path.join(temporary,SOURCE_MANIFESTS[0])),'body.txt'),'changed');
|
|
assert.throws(()=>sourceInventory(temporary),/original source SHA changed/);
|
|
});
|