/** * docs-* registry inclusion — a scoped `--modules` run must NEVER drop a * `docs-Registry.ts` emitted by /documentation (scaffold-doc). * * ba-develop re-runs the aggregator with `--modules `; before * this guard that run silently removed the doc registries' imports from * componentRegistry.generated.ts → the doc pages lost their route + i18n * namespace with zero signal. */ import { describe, it, expect, beforeEach, afterEach } from 'vitest' import fs from 'node:fs' import os from 'node:os' import path from 'node:path' import { generate } from '../generate.js' let web: string beforeEach(() => { web = fs.mkdtempSync(path.join(os.tmpdir(), 'agg-docs-')) }) afterEach(() => { fs.rmSync(web, { recursive: true, force: true }) }) function write(rel: string, content: string): void { const abs = path.join(web, rel) fs.mkdirSync(path.dirname(abs), { recursive: true }) fs.writeFileSync(abs, content) } function registry(key: string, importPath: string, ident: string): string { return `import { PageRegistry, lazyWithRetry } from '@atlashub/smartstack';\nconst ${ident} = lazyWithRetry(() => import('${importPath}'));\nPageRegistry.register('${key}', ${ident});\n` } beforeEach(() => { // A business module registry + a doc registry, both with resolvable pages. write('src/extensions/crmRegistry.ts', registry('app.crm.clients', '@/pages/crm/ClientsListPage', 'ClientsListPage')) write('src/pages/crm/ClientsListPage.tsx', 'export default () => null\n') write( 'src/extensions/docs-gaf-affairesRegistry.ts', registry('docs.gaf.affaires', '@/pages/docs/business/gaf/affaires', 'GafAffairesDocPage'), ) write('src/pages/docs/business/gaf/affaires/index.tsx', 'export default () => null\n') }) describe('aggregate-component-registry — docs-* inclusion', () => { it('a --modules run scoped to business modules still includes docs-* registries', () => { const res = generate({ projectPath: web, modules: ['crm'], exclude: [] }) expect(res.errors).toEqual([]) const content = res.files.find((f) => f.path.endsWith('componentRegistry.generated.ts'))?.content expect(content).toContain(`import './crmRegistry';`) expect(content).toContain(`import './docs-gaf-affairesRegistry';`) expect(res.warnings.join('\n')).toContain('always aggregated') }) it('docs-* files are never reported as orphans; real orphans still are', () => { write('src/extensions/legacyRegistry.ts', registry('app.legacy.x', '@/pages/crm/ClientsListPage', 'LegacyPage')) const res = generate({ projectPath: web, modules: ['crm'], exclude: [] }) const warnings = res.warnings.join('\n') expect(warnings).toContain('legacyRegistry.ts') expect(warnings).toContain('likely orphan') expect(warnings).not.toMatch(/docs-gaf-affairesRegistry\.ts.*likely orphan/) }) it('an unscoped run keeps aggregating everything (unchanged)', () => { const res = generate({ projectPath: web, exclude: [] }) const content = res.files.find((f) => f.path.endsWith('componentRegistry.generated.ts'))?.content expect(content).toContain(`import './crmRegistry';`) expect(content).toContain(`import './docs-gaf-affairesRegistry';`) }) })