import assert from 'node:assert/strict'; import { resolve, join } from 'node:path'; import { Database } from 'bun:sqlite'; import { SqliteReferenceRepository } from '../src/lib/server/reference/repository'; const directory = resolve(process.env.REFERENCE_DIR ?? 'data/reference-live'); const manifest = await Bun.file(join(directory, 'manifest.json')).json(); assert.equal(manifest.active?.profile, 'production', 'live catalog must have a production profile'); const repository = new SqliteReferenceRepository(directory, 'production'); const db = new Database(repository.databasePath, { readonly: true, strict: true }); try { const names = new Map((await repository.types([34, 587])).map(type => [type.id, type.name])); assert.equal(names.get(34), 'Tritanium'); assert.equal(names.get(587), 'Rifter'); const counts: Record = {}; for (const table of ['types', 'blueprints', 'systems', 'gates', 'unresolved_references']) { const row = db.query<{ n: number }, []>(`SELECT COUNT(*) AS n FROM ${table}`).get(); counts[table] = Number(row?.n); assert.equal(counts[table], manifest.active.counts[table], `${table} must match the published manifest`); } assert(counts.types > 50_000); assert(counts.systems > 5_000); assert(counts.blueprints > 0); assert(counts.gates > 0); const integrity = db.query<{ integrity_check: string }, []>('PRAGMA integrity_check').all(); assert.deepEqual(integrity.map(row => row.integrity_check), ['ok']); assert.deepEqual(db.query('PRAGMA foreign_key_check').all(), []); console.log(JSON.stringify({ productionReference: 'passed', directory, version: await repository.version(), counts })); } finally { db.close(); repository.close(); }