Files
Agent-Workbench/scripts/verify-model-selection-k.mjs
T
2026-11-03 15:37:04 +08:00

22 lines
3.1 KiB
JavaScript

import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
if(process.argv.includes('--help')){console.log('node scripts/verify-model-selection-k.mjs — offline original-byte evidence, routing/UI, archive/rebuild/install/formal-retention and J identity preservation; no network or model calls.');process.exit(0);}
assert.equal(process.argv.length,2);
const root=path.resolve('docs/model-selection-k-evidence'),read=file=>JSON.parse(fs.readFileSync(file,'utf8')),hash=bytes=>createHash('sha256').update(bytes).digest('hex');
const manifest=read(path.join(root,'manifest.json'));assert.equal(manifest.version,'1.24.3');
const names=new Set();let bytes=0;
for(const entry of manifest.entries){assert.ok(!names.has(entry.path),entry.path);names.add(entry.path);const file=path.resolve(root,entry.path);assert.ok(file.startsWith(root+path.sep));const contents=fs.readFileSync(file);assert.equal(contents.length,entry.bytes,entry.path);assert.equal(hash(contents),entry.sha256,entry.path);bytes+=contents.length;}
const proof=name=>read(path.join(root,manifest.references[name]));
for(const name of ['sourceUI','portableUI','installedUI']){const ui=proof(name);assert.equal(ui.success,true);assert.equal(ui.testedVersion,'1.24.3');assert.equal(ui.checks.length,7);assert.equal(ui.realModelRequests,0);assert.deepEqual(ui.errors,[]);assert.equal(ui.requests.length,2);assert.ok(ui.requests.every(item=>item.path==='/selected/v1/chat/completions'&&item.model==='owned-claude'));}
assert.equal(proof('regression').success,true);assert.ok(proof('regression').results.every(item=>item.code===0));
assert.equal(proof('archives').success,true);assert.equal(proof('archives').archives.length,3);assert.ok(proof('archives').archives.every(item=>item.crcPassed&&item.manifestAndDirectoryMatch));
const rebuild=proof('rebuild');assert.equal(rebuild.success,true);assert.equal(rebuild.sourceCommit,manifest.sourceCommit);assert.equal(rebuild.compiled.length,22);assert.deepEqual(rebuild.mismatches,[]);
assert.equal(proof('portable').success,true);assert.equal(proof('installation').success,true);
const before=proof('formalbefore');assert.equal(before.success,true);assert.equal(before.version,'1.24.2');
for(const name of ['formalinstall','formalfinal']){const p=proof(name);assert.equal(p.success,true);assert.equal(p.version,'1.24.3');assert.equal(p.pid,before.pid);assert.equal(p.hasKey,true);assert.equal(p.realModelRequests,0);assert.deepEqual(p.retention,{originalRows:'exact',originalExports:'exact',originalArtifactBytes:'exact',originalModelCenter:'exact'});}
assert.equal(proof('native').success,true);
assert.equal(hash(fs.readFileSync('docs/live-model-identity-j-evidence/manifest.json')),manifest.originalJManifestSha256);
console.log(JSON.stringify({success:true,files:manifest.entries.length,bytes,sourceCommit:manifest.sourceCommit,manifestSha256:hash(fs.readFileSync(path.join(root,'manifest.json'))),realModelRequests:0,scope:'Offline verification of preserved original bytes and acceptance receipts. No inference of underlying model weights or Purge benefit.'}));