31 lines
3.4 KiB
JavaScript
31 lines
3.4 KiB
JavaScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import assert from 'node:assert/strict';
|
|
import {spawnSync} from 'node:child_process';
|
|
import {createHash} from 'node:crypto';
|
|
const root=path.resolve('.qa/live-retest-h/identity-fixtures');assert.equal(fs.existsSync(root),false);fs.mkdirSync(root);
|
|
const hash=b=>createHash('sha256').update(b).digest('hex'),script=path.resolve('scripts/verify-upstream-model-identity.mjs');
|
|
const cases=[['chat-json','{"model":"expected"}',0,'matched'],['chat-sse','data: {"model":"expected"}\n\ndata: [DONE]\n',0,'matched'],
|
|
['responses-sse','data: {"type":"response.completed","response":{"model":"expected"}}\n\n',0,'matched'],
|
|
['mismatch','{"model":"other"}',2,'mismatch'],['missing','{"choices":[]}',2,'missing'],
|
|
['mixed','data: {"model":"expected"}\n\ndata: {"model":"other"}\n\n',2,'mismatch'],['tampered','{"model":"expected"}',1,null]];
|
|
const results=[];
|
|
for(const [name,response,status,identity]of cases){const dir=path.join(root,name);fs.mkdirSync(dir);fs.mkdirSync(path.join(dir,'blobs'));fs.mkdirSync(path.join(dir,'receipts'));
|
|
const entries=[],artifacts=[];const put=(file,value)=>{const raw=Buffer.from(value);fs.writeFileSync(path.join(dir,file),raw);entries.push({path:file,bytes:raw.length,sha256:hash(raw)});return hash(raw);};
|
|
const requestSha=put('blobs/request.blob','{"model":"expected"}'),responseSha=put('blobs/response.blob',response);
|
|
artifacts.push({id:'request',file:'blobs/request.blob',sha256:requestSha},{id:'response',file:'blobs/response.blob',sha256:responseSha});
|
|
put('receipts/all-model-attempts.json',JSON.stringify([{id:name,model:'expected',sessionId:'owned-fixture',requestArtifactId:'request',responseArtifactId:'response',responseSha256:responseSha}]));
|
|
fs.writeFileSync(path.join(dir,'manifest.json'),JSON.stringify({requests:1,entries,artifacts}));
|
|
if(name==='tampered')fs.appendFileSync(path.join(dir,'blobs/response.blob'),' ');
|
|
const output=path.join(dir,'result.json'),run=spawnSync(process.execPath,[script,'--evidence',dir,'--output',output],{encoding:'utf8',windowsHide:true});
|
|
fs.writeFileSync(path.join(dir,'stdout.txt'),run.stdout??'');fs.writeFileSync(path.join(dir,'stderr.txt'),run.stderr??'');
|
|
assert.equal(run.status,status,name);if(identity){const result=JSON.parse(fs.readFileSync(output));assert.equal(result.status,identity);assert.equal(result.passed,status===0);}
|
|
else assert.equal(fs.existsSync(output),false);
|
|
results.push({name,passed:true,exitCode:run.status,expectedIdentity:identity});
|
|
}
|
|
const actual=spawnSync(process.execPath,[script,'--evidence','docs/live-original-purge-h-evidence','--output',path.resolve('.qa/live-retest-h/identity-repeat.json')],{encoding:'utf8',windowsHide:true});
|
|
assert.equal(actual.status,2);assert.deepEqual(fs.readFileSync('.qa/live-retest-h/identity-repeat.json'),fs.readFileSync('docs/live-retest-h-model-identity.json'));
|
|
const receipt={passed:true,checks:results.length+1,cases:results,actualH:{exitCode:2,requests:52,mismatched:52,identicalOriginalAudit:true},scriptSha256:hash(fs.readFileSync(script)),realModelRequests:0,
|
|
scope:'Offline identity parser and source integrity only: matching JSON/Chat SSE/Responses SSE, mismatched/missing/mixed identifiers, tampered artifact refusal and exact original-H repeat. No product runtime identity gate claimed.'};
|
|
fs.writeFileSync('docs/live-retest-h-identity-validation.json',JSON.stringify(receipt,null,2)+'\n',{flag:'wx'});console.log(JSON.stringify(receipt));
|