import { describe, expect, it } from 'vitest'; import { discoverCatalogueCandidates, formatCatalogueIntegrityReport, validateCatalogueIntegrity, type CatalogueCandidate, } from '../src/modules/machines/catalogueIntegrity'; import * as blueprintModule from '../src/modules/machines/data/catalogueBlueprint'; import * as coreMachinesModule from '../src/modules/machines/data/coreMachines'; import * as dataIndexModule from '../src/modules/machines/data/index'; import * as registryModule from '../src/modules/machines/registry'; const catalogueModules: Array<{ name: string; exports: Record }> = [ { name: 'registry', exports: registryModule as unknown as Record }, { name: 'dataIndex', exports: dataIndexModule as unknown as Record }, { name: 'coreMachines', exports: coreMachinesModule as unknown as Record }, { name: 'catalogueBlueprint', exports: blueprintModule as unknown as Record }, ]; describe('machine registry data integrity', () => { it('exposes discoverable machine catalogue data from the registry modules', () => { const candidates = discoverAllCandidates(); expect(candidates.length).toBeGreaterThan(0); expect(candidates[0]?.machines.length).toBeGreaterThan(0); }); it('keeps all exported machine data free of hard registry integrity errors', () => { const failures = discoverAllCandidates() .map((candidate) => { const summary = validateCatalogueIntegrity(candidate.machines, { requireAtLeastOneMachine: true, allowPlaceholderAssets: true, warnOnMissingCameraPresets: false, warnOnMissingAnimationMetadata: false, warnOnMissingExplodedMetadata: false, }); if (summary.passed) { return undefined; } return `${candidate.name}\n${formatCatalogueIntegrityReport(summary, { includeWarnings: true, maxIssues: 20, })}`; }) .filter((failure): failure is string => Boolean(failure)); expect(failures).toEqual([]); }); it('maintains the promised 28-machine implementation blueprint at catalogue scale', () => { const blueprintCandidates = discoverCatalogueCandidates( blueprintModule as unknown as Record, 'catalogueBlueprint', { aggregateRootSiblings: true, }, ); const largestBlueprintCandidate = blueprintCandidates.toSorted( (a, b) => b.machines.length - a.machines.length, )[0]; expect(largestBlueprintCandidate?.machines.length ?? 0).toBeGreaterThanOrEqual(28); }); }); function discoverAllCandidates(): CatalogueCandidate[] { const candidates = catalogueModules.flatMap((moduleInfo) => discoverCatalogueCandidates(moduleInfo.exports, moduleInfo.name), ); const candidateByArray = new Map(); candidates.forEach((candidate) => { const existing = candidateByArray.get(candidate.machines); if (!existing || candidate.name.length < existing.name.length) { candidateByArray.set(candidate.machines, candidate); } }); return Array.from(candidateByArray.values()).sort((a, b) => { if (b.machines.length !== a.machines.length) { return b.machines.length - a.machines.length; } return a.name.localeCompare(b.name); }); }