The TS pipeline, domain, upload script and legacy scripts leave; xmldom out of the lockfile, Dockerfile copies trimmed. LEDGER.tsv (407 cases) and FILES.tsv (112 files) record each disposition; r4 and r5 census tests guard the tree, lockfile and production imports.
158 lines
5.7 KiB
TypeScript
158 lines
5.7 KiB
TypeScript
/**
|
|
* 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. Since R5.7 xmldom, the TypeScript domain and the
|
|
* pipeline package are gone too (`r5.census.test.ts` holds the rest of that census).
|
|
*/
|
|
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',
|
|
'@faunosteo/anatomy',
|
|
'@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<string, string>
|
|
>
|
|
const names = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies })
|
|
for (const banned of [
|
|
'@faunosteo/pdf',
|
|
'pdf-lib',
|
|
'@faunosteo/domain',
|
|
'@faunosteo/anatomy',
|
|
'@xmldom/xmldom',
|
|
'tsx',
|
|
]) {
|
|
expect(names, path).not.toContain(banned)
|
|
}
|
|
}
|
|
})
|
|
|
|
it('the lockfile holds no pdf-lib, @pdf-lib, resvg or xmldom (R5.7: the pipeline left with its xmldom)', () => {
|
|
const lock = read('pnpm-lock.yaml')
|
|
for (const name of ['pdf-lib@', '@pdf-lib/', '@resvg/resvg-js']) {
|
|
expect(lock, name).not.toContain(name)
|
|
}
|
|
const section = lock.slice(
|
|
lock.indexOf('\nimporters:\n'),
|
|
lock.indexOf('\npackages:\n'),
|
|
)
|
|
const importers = section
|
|
.split(/\n(?= [^ \n][^\n]*:\n)/)
|
|
.slice(1)
|
|
.map((block) => block.slice(2, block.indexOf(':\n')))
|
|
// Non-vacuity: the split finds the importers a dependency would sit under.
|
|
expect(importers).toEqual(
|
|
expect.arrayContaining(['.', 'apps/app', 'packages/core-wasm']),
|
|
)
|
|
expect(importers).not.toContain('packages/anatomy')
|
|
expect(importers).not.toContain('packages/domain')
|
|
expect(lock).toContain("'@faunosteo/core-wasm':")
|
|
expect(lock).not.toContain('@xmldom/xmldom')
|
|
})
|
|
})
|
|
|
|
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<string, string>
|
|
}
|
|
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)
|
|
}
|
|
})
|
|
})
|