import { describe, it, expect } from 'vitest' import { checkPrimitivePreflight } from '../preflight.js' // The fail-closed primitive preflight: a page importing a primitive that is // neither on disk nor written by this invocation must refuse — the stale-copy // hole (`ss upgrade` never re-runs scaffold-ui-primitives) is what pushed // auto-heal into improvising the stacked read+edit markup by hand. const join = (...parts: string[]) => parts.join('/') const PAGE = { path: 'src/pages/flotte/parc/vehicules/VehicleDetailPage.tsx', content: `import { PageTemplate } from '@/components/ui/PageTemplate' import { SectionCard } from '@/components/ui/SectionCard' import { useListNumberParam } from '@/components/ui/useListState' `, } describe('scaffold-component / checkPrimitivePreflight', () => { it('passes when every imported primitive exists on disk (.tsx or .ts)', () => { const onDisk = new Set([ '/web/src/components/ui/PageTemplate.tsx', '/web/src/components/ui/SectionCard.tsx', '/web/src/components/ui/useListState.ts', ]) const misses = checkPrimitivePreflight('/web', [PAGE], (p) => onDisk.has(p), join) expect(misses).toEqual([]) }) it('reports each missing primitive with its expected path (fail-closed)', () => { const onDisk = new Set(['/web/src/components/ui/PageTemplate.tsx']) const misses = checkPrimitivePreflight('/web', [PAGE], (p) => onDisk.has(p), join) expect(misses.map(m => m.primitive)).toEqual(['SectionCard', 'useListState']) expect(misses[0].expected).toBe('src/components/ui/SectionCard.tsx') }) it('a primitive written by THIS invocation never counts as missing', () => { const files = [PAGE, { path: 'src/components/ui/SectionCard.tsx', content: 'export const SectionCard = () => null' }] const onDisk = new Set(['/web/src/components/ui/PageTemplate.tsx', '/web/src/components/ui/useListState.ts']) const misses = checkPrimitivePreflight('/web', files, (p) => onDisk.has(p), join) expect(misses).toEqual([]) }) it('a page with no ui imports needs nothing', () => { const misses = checkPrimitivePreflight('/web', [{ path: 'x.tsx', content: 'export {}' }], () => false, join) expect(misses).toEqual([]) }) })