/** * R4.8 census (plan §B.7 R4.8, RUST.md §10.10): the PDF path runs on the core and nothing of * the TypeScript engine is left where the application or its glue could reach it. Grep facts * over the repository, so that a reintroduced import, a dependency added back or a script * repointed fails here before anything else. */ import { describe, it, expect } from 'vitest' import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs' import { dirname, join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../../../..') const read = (path: string) => readFileSync(join(ROOT, path), 'utf8') /** Every `.ts` / `.tsx` file under `dir`, relative to the repository root. */ function sources(dir: string): string[] { const out: string[] = [] const walk = (at: string) => { for (const entry of readdirSync(join(ROOT, at))) { const path = `${at}/${entry}` if (statSync(join(ROOT, path)).isDirectory()) walk(path) else if (/\.tsx?$/.test(entry)) out.push(path) } } walk(dir) return out } const importsOf = (text: string): string[] => [...text.matchAll(/from\s+'([^']+)'/g)].map((m) => m[1]!) describe('the TypeScript PDF engine is gone', () => { it('packages/pdf and the TS CLI no longer exist', () => { // The folder itself may linger with a git-ignored node_modules of a stale install. expect(existsSync(join(ROOT, 'packages/pdf/package.json'))).toBe(false) expect(existsSync(join(ROOT, 'packages/pdf/src'))).toBe(false) expect(existsSync(join(ROOT, 'apps/app/scripts'))).toBe(false) expect(existsSync(join(ROOT, 'apps/app/src/pdf/import.ts'))).toBe(false) }) it('no application or glue source imports the engine, pdf-lib, the TS domain or xmldom', () => { const banned = [ '@faunosteo/pdf', 'pdf-lib', '@faunosteo/domain', '@xmldom/xmldom', ] for (const file of [ ...sources('apps/app/src'), ...sources('packages/core-wasm/src'), ]) { const found = importsOf(read(file)).filter((spec) => banned.some((b) => spec === b || spec.startsWith(`${b}/`)), ) expect(found, file).toEqual([]) } }) it('the application and the glue package depend on none of them', () => { for (const path of [ 'apps/app/package.json', 'packages/core-wasm/package.json', ]) { const pkg = JSON.parse(read(path)) as Record< string, Record > const names = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }) for (const banned of [ '@faunosteo/pdf', 'pdf-lib', '@faunosteo/domain', 'tsx', ]) { expect(names, path).not.toContain(banned) } } }) it('the lockfile holds no pdf-lib, @pdf-lib or resvg; xmldom only under packages/anatomy', () => { const lock = read('pnpm-lock.yaml') for (const name of ['pdf-lib@', '@pdf-lib/', '@resvg/resvg-js']) { expect(lock, name).not.toContain(name) } const importers = lock.split(/^ (?=[a-z@][^\n]*:$)/m) const withXmldom = importers .filter((block) => block.includes("'@xmldom/xmldom':")) .map((block) => block.split(':')[0]!.trim()) expect(withXmldom).toEqual(['packages/anatomy']) }) }) describe('the PDF path runs on the core', () => { it('the export drives the core session', () => { const text = read('apps/app/src/pdf/export.ts') expect(text).toContain("from '@faunosteo/core-wasm'") expect(text).toContain('openExportSession(') }) it('the import goes through the worker, never a TypeScript scanner', () => { const route = read('apps/app/src/app/routes/HomeRoute.tsx') expect(route).toMatch(/from '@\/core\/worker\//) const handler = read('apps/app/src/core/worker/handler.ts') expect(handler).toContain('import_pdf_bytes(') for (const file of sources('apps/app/src')) { expect(read(file), file).not.toMatch( /readAttachedDocument|readAttachmentBytes/, ) } }) it('pnpm report:compare runs the core binary', () => { const root = JSON.parse(read('package.json')) as { scripts: Record } expect(root.scripts['report:compare']).toBe( 'bash scripts/report-compare.sh', ) const script = read('scripts/report-compare.sh') expect(script).toContain('--features cli --bin report-compare') expect( existsSync(join(ROOT, 'crates/core/src/bin/report_compare.rs')), ).toBe(true) }) it('the frozen N-1 readers and the oracle files stay', () => { for (const path of [ 'packages/core-wasm/tests/n-1/scanner/attachment/scan.ts', 'packages/core-wasm/tests/n-1/domain', 'crates/core/tests/oracles/r4/compare/compare.json', 'crates/core/tests/oracles/r3/highlight.json', 'apps/app/tests/fixtures/goldens/step6', 'apps/app/tests/fixtures/goldens/r4', 'apps/app/tests/fixtures/pdf/r3', 'apps/app/tests/fixtures/pdf/step6', 'apps/app/tests/fixtures/pdf/r4/read', 'apps/app/tests/fixtures/pdf/r4/tolerance', ]) { expect(existsSync(join(ROOT, path)), path).toBe(true) } }) })