import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import { createHash } from 'node:crypto'; import { fileURLToPath } from 'node:url'; import { modelRegistry, validateModelRegistry } from '../src/shared/contracts/official-model-registry.mjs'; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const fixtureRoot = path.join(root, 'tests/fixtures/official-model-registry'); const fixtures = JSON.parse(fs.readFileSync(path.join(fixtureRoot, 'SOURCE.json'), 'utf8')); validateModelRegistry(modelRegistry); assert.deepEqual(modelRegistry.sources, fixtures.sources); const sources = fixtures.sources.map(source => { const file = path.resolve(fixtureRoot, source.file); assert.ok(file.startsWith(fixtureRoot + path.sep), 'Source path must belong to the fixture'); const bytes = fs.readFileSync(file), sha256 = createHash('sha256').update(bytes).digest('hex'); assert.equal(sha256, source.sha256, source.id); return { id: source.id, file: source.file, bytes: bytes.length, sha256 }; }); const report = { checkedAt: new Date().toISOString(), registryVersion: modelRegistry.version, sources, records: modelRegistry.records.map(value => ({ provider: value.provider, model: value.model, protocol: value.protocol, apiVersion: value.apiVersion, fields: Object.keys(value.fields) })), recordsCount: modelRegistry.records.length, modelsCount: new Set(modelRegistry.records.map(value => value.model)).size, sourcesBytes: sources.reduce((sum, value) => sum + value.bytes, 0), scope: 'Pinned public specification and source bytes; no model request or live-route compatibility claim.' }; if (process.argv[2]) fs.writeFileSync(path.resolve(process.argv[2]), JSON.stringify(report, null, 2) + '\n', { flag: 'wx' }); console.log(JSON.stringify({ registryVersion: report.registryVersion, sourcesCount: sources.length, sourcesBytes: report.sourcesBytes, recordsCount: report.recordsCount, modelsCount: report.modelsCount, passed: true }));