70 lines
9.0 KiB
JavaScript
70 lines
9.0 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-messages-m.mjs — offline M source/release/UI/install/state-retention and single no-tool native Messages preflight verification; no network, model or credential access.'); process.exit(0); }
|
|
assert.equal(process.argv.length, 2);
|
|
const root = path.resolve('docs/messages-m-evidence'), read = f => JSON.parse(fs.readFileSync(f, 'utf8')), hash = b => createHash('sha256').update(b).digest('hex');
|
|
const manifest = read(path.join(root, 'manifest.json')); assert.equal(manifest.version, '1.24.4');
|
|
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 content = fs.readFileSync(file); assert.equal(content.length, entry.bytes, entry.path); assert.equal(hash(content), entry.sha256, entry.path); bytes += content.length;
|
|
if (/\.(?:jpg|png)$/.test(entry.path)) {
|
|
if (entry.path.endsWith('.jpg')) assert.equal(content.subarray(0, 3).toString('hex'), 'ffd8ff', entry.path);
|
|
else assert.equal(content.subarray(0, 8).toString('hex'), '89504e470d0a1a0a', entry.path);
|
|
}
|
|
}
|
|
const proof = name => read(path.join(root, manifest.references[name]));
|
|
const freeze = proof('freeze'); assert.equal(freeze.sourceCommit, manifest.sourceCommit); assert.equal(freeze.files.length, 544); assert.equal(freeze.compiled.length, 22);
|
|
const release = proof('release'); assert.equal(release.documentation.sourceCommit, manifest.sourceCommit); assert.equal(path.basename(release.portableRoot), manifest.candidate);
|
|
for (const item of [...freeze.files, ...freeze.compiled]) assert.equal(hash(fs.readFileSync(path.join(root, 'source-bytes', item.path))), item.sha256, item.path);
|
|
for (const name of ['sourceUI', 'portableUI', 'installedUI']) {
|
|
const ui = proof(name); assert.equal(ui.success, true); assert.equal(ui.testedVersion, '1.24.4'); assert.equal(ui.checks.length, 7); assert.equal(ui.realModelRequests, 0); assert.deepEqual(ui.errors, []);
|
|
}
|
|
assert.equal(proof('regression').success, true); assert.equal(proof('regression').results.length, 4); assert.ok(proof('regression').results.every(r => r.code === 0));
|
|
const driver = proof('probeDriver'); assert.equal(driver.passed, true); assert.equal(driver.realModelRequests, 0); assert.deepEqual(driver.results.map(r => r.mode), ['match', 'mismatch', '429']);
|
|
assert.ok(driver.results.every(r => r.passed && r.requests === 1 && r.actualTools === 0 && r.inspectorClosed));
|
|
const probeBinding = proof('probeSourceBinding'); assert.equal(probeBinding.passed, true); assert.equal(probeBinding.finalSourceCommit, manifest.sourceCommit); assert.equal(probeBinding.files.length, 220);
|
|
for (const file of probeBinding.files) assert.deepEqual(freeze.files.find(f => f.path === file.path), file);
|
|
const archives = proof('archives'); assert.equal(archives.success, true); assert.equal(archives.version, '1.24.4'); assert.equal(archives.archives.length, 3); assert.ok(archives.archives.every(a => a.crcPassed && a.manifestAndDirectoryMatch));
|
|
for (const kind of ['portable', 'source', 'evidence']) { const archive = archives.archives.find(a => a.kind === kind); assert.equal(archive.path, release[kind].path); assert.equal(archive.sha256, release[kind].sha256); }
|
|
const rebuild = proof('rebuild'); assert.equal(rebuild.success, true); assert.equal(rebuild.sourceCommit, manifest.sourceCommit); assert.equal(rebuild.inputs.length, 549); assert.equal(rebuild.compiled.length, 22); assert.deepEqual(rebuild.mismatches, []);
|
|
assert.deepEqual(rebuild.sourceZip, release.source); assert.equal(proof('portable').appRoot, release.portableRoot); assert.equal(proof('portableUI').appRoot, release.portableRoot);
|
|
for (const item of freeze.compiled) { const rebuilt = rebuild.compiled.find(r => r.path === item.path); assert.ok(rebuilt); assert.equal(rebuilt.expected.sha256, item.sha256); assert.equal(rebuilt.actual.sha256, item.sha256); }
|
|
assert.equal(proof('portable').success, true); const install = proof('installation'); assert.equal(install.success, true); assert.equal(install.version, '1.24.4'); assert.equal(install.results.length, 12); assert.equal(install.realModelRequests, 0);
|
|
assert.equal(install.packagedSource, release.portableRoot);
|
|
assert.equal(install.installedUI.proofs.length, 2); assert.ok(install.installedUI.proofs.every(p => p.proof.success && p.proof.realModelRequests === 0));
|
|
const before = proof('formalbefore'); assert.equal(before.success, true); assert.equal(before.version, '1.24.3');
|
|
for (const name of ['formalinstall', 'formalfinal']) {
|
|
const p = proof(name); assert.equal(p.success, true); assert.equal(p.version, '1.24.4'); 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(proof('browser').success, true);
|
|
const live = proof('live'), attempts = proof('liveAttempts'), audit = proof('liveAudit');
|
|
assert.equal(audit.passed, true); assert.equal(audit.globalConfigAndSelectionExact, true); assert.equal(audit.noCredentialExtractionOrResave, true); assert.equal(audit.originalPidRetained, true);
|
|
assert.equal(live.requests, 1); assert.equal(live.toolDefinitions, 0); assert.equal(live.actualTools, 0); assert.equal(live.noRetry, true); assert.equal(live.noPoolSwitch, true); assert.equal(live.inspectorClosed, true);
|
|
assert.equal(live.protocol, 'anthropic-messages'); assert.equal(live.messagesAuth, 'bearer'); assert.equal(live.requestUrl, 'https://api.apikey.fan/v1/messages'); assert.equal(live.modelWeightsAuthenticated, false);
|
|
assert.equal(live.realEngineeringDeliveryTested, false); assert.equal(live.originalPurgeBenefitTested, false); assert.equal(live.defaultSelectionRetained, true); assert.equal(live.credentialRevisionRetained, true);
|
|
assert.equal(attempts.length, 1); const attempt = attempts[0]; assert.equal(attempt.sessionId, live.sessionId); assert.equal(attempt.connectionId, live.connectionId); assert.equal(attempt.poolId, null); assert.equal(attempt.ordinal, 1);
|
|
const requestCapture = live.captures.find(c => c.kind === 'request'), responseCapture = live.captures.find(c => c.kind === 'response');
|
|
assert.ok(requestCapture && responseCapture); const requestBytes = fs.readFileSync(path.join(root, 'live', requestCapture.file)), request = JSON.parse(requestBytes);
|
|
assert.equal(hash(requestBytes), requestCapture.sha256); assert.equal(hash(JSON.stringify(request)), attempt.requestSha256); assert.equal(request.model, live.requestedModel); assert.equal(request.max_tokens, 256); assert.equal(request.tools?.length ?? 0, 0);
|
|
const raw = fs.readFileSync(path.join(root, 'live', responseCapture.file)); assert.equal(hash(raw), responseCapture.sha256); assert.equal(hash(raw), attempt.responseSha256); assert.equal(attempt.responseRedacted, false);
|
|
assert.deepEqual(live.reportedModels, attempt.modelIdentity?.reportedModels ?? []); assert.equal(live.identityStatus, attempt.modelIdentity?.status ?? 'not_observed');
|
|
const reported = [];
|
|
if (responseCapture.file.endsWith('.sse')) {
|
|
for (const line of raw.toString('utf8').split(/\r?\n/)) if (line.startsWith('data: ')) { const value = line.slice(6); if (value === '[DONE]') continue; const e = JSON.parse(value); if (typeof e.model === 'string') reported.push(e.model); if (typeof e.message?.model === 'string') reported.push(e.message.model); }
|
|
} else {
|
|
let value; try { value = JSON.parse(raw); } catch { assert.deepEqual(live.reportedModels, [], 'Non-JSON response must not fabricate a model identifier.'); }
|
|
if (typeof value?.model === 'string') reported.push(value.model);
|
|
}
|
|
for (const model of live.reportedModels) assert.ok(reported.includes(typeof model === 'string' ? model : model.model), 'Reported model comes from original response bytes.');
|
|
if (live.identityPassed) { assert.equal(live.identityStatus, 'matched'); assert.equal(attempt.status, 'completed'); assert.equal(live.usageStatus, 'reported'); assert.ok(live.usage.total_tokens <= 16000); }
|
|
else assert.notEqual(live.sessionStatus, 'completed', 'Rejected/missing identities cannot be presented as completed.');
|
|
assert.equal(hash(fs.readFileSync('docs/live-model-identity-j-evidence/manifest.json')), manifest.originalJManifestSha256);
|
|
assert.equal(hash(fs.readFileSync('docs/apikey-route-l-evidence/manifest-final.json')), manifest.originalLManifestSha256);
|
|
console.log(JSON.stringify({ success: true, files: manifest.entries.length, bytes, sourceCommit: manifest.sourceCommit, manifestSha256: hash(fs.readFileSync(path.join(root, 'manifest.json'))), realModelRequests: 1,
|
|
identityPassed: live.identityPassed, requestedModel: live.requestedModel, reportedModels: live.reportedModels, scope: 'Offline original-byte acceptance and bounded preflight. No network/model call; no underlying-weight or engineering/Purge benefit assertion.' }));
|