r4-import.mjs runs the 226 baseline files and the hostile classes through a disposable module worker calling SheetHandle.import_pdf in Chromium 156, Firefox 157 and WebKit 27.2 under the RSS watchdog (not a guaranteed limit); compare-imports.mjs prints TS vs Rust; serve.mjs gains opt-in mounts (/r4/, /pkg/). Results 2026-10-18-r4-import.json: 666/678 agreements, the 12 others are the 4 declared files; W4 met (max 68 MiB linear); the 1 GiB ceiling traps in every engine.
93 lines
3.0 KiB
JavaScript
93 lines
3.0 KiB
JavaScript
import {
|
|
existsSync,
|
|
mkdtempSync,
|
|
readFileSync,
|
|
rmdirSync,
|
|
unlinkSync,
|
|
writeFileSync,
|
|
} from 'node:fs'
|
|
import { basename, join } from 'node:path'
|
|
import { expandGenerator, filesUnder, isGenerator } from './inputs.mjs'
|
|
import { FIXTURES_DIR, ORACLES_R4_DIR, relativeToRepo } from './paths.mjs'
|
|
|
|
/**
|
|
* The import file set of import-baseline.mjs (groups base, r3, step6,
|
|
* tolerance, read), listed the same way, so the R4 import measures the
|
|
* TypeScript baseline's perimeter file for file.
|
|
*
|
|
* shortcut: a copy of import-baseline.mjs's listing (R4.2e leaves the
|
|
* baseline script untouched); compare-imports.mjs checks that both runs
|
|
* hold the same files. Upgrade path: import-baseline.mjs imports this
|
|
* module.
|
|
*/
|
|
|
|
const READ_DIR = join(FIXTURES_DIR, 'pdf/r4/read')
|
|
const BASE_FILES = [
|
|
'report-v2.full.pdf',
|
|
'report-v2.minimal.pdf',
|
|
'report-v3.bare.pdf',
|
|
]
|
|
|
|
const isPdf = (path) => path.endsWith('.pdf')
|
|
|
|
function pdfsIn(group, dir, recursive = false) {
|
|
const paths = filesUnder(join(FIXTURES_DIR, dir), recursive).filter(isPdf)
|
|
return paths.map((path) => ({ group, path }))
|
|
}
|
|
|
|
function fixedGroups() {
|
|
return [
|
|
...BASE_FILES.map((f) => ({ group: 'base', path: join(FIXTURES_DIR, f) })),
|
|
...pdfsIn('r3', 'pdf/r3', true),
|
|
...pdfsIn('step6', 'pdf/step6'),
|
|
...pdfsIn('tolerance', 'pdf/r4/tolerance'),
|
|
]
|
|
}
|
|
|
|
/** The hostile set as read.json (O7) lists it; absent listed files reported. */
|
|
function hostileGroup() {
|
|
const oraclePath = join(ORACLES_R4_DIR, 'read.json')
|
|
if (!existsSync(READ_DIR)) {
|
|
return { inputs: [], missing: ['pdf/r4/read/'], listedBy: null }
|
|
}
|
|
const listed = existsSync(oraclePath)
|
|
? JSON.parse(readFileSync(oraclePath, 'utf8')).inputs
|
|
: filesUnder(READ_DIR).map((path) => ({ file: basename(path), kind: null }))
|
|
const present = listed.filter((i) => existsSync(join(READ_DIR, i.file)))
|
|
const missing = listed.filter((i) => !present.includes(i)).map((i) => i.file)
|
|
const inputs = present.map((i) => ({
|
|
group: 'read',
|
|
kind: i.kind,
|
|
path: join(READ_DIR, i.file),
|
|
}))
|
|
return {
|
|
inputs,
|
|
missing,
|
|
listedBy: existsSync(oraclePath) ? relativeToRepo(oraclePath) : 'directory',
|
|
}
|
|
}
|
|
|
|
/** Every import input, narrowed by `--groups` (null = all). */
|
|
export function importInputs(groups) {
|
|
const hostile = hostileGroup()
|
|
const wanted = (i) => !groups || groups.includes(i.group)
|
|
const inputs = [...fixedGroups(), ...hostile.inputs].filter(wanted)
|
|
return { inputs, hostile }
|
|
}
|
|
|
|
/** A generator description becomes a temporary file, removed after the run. */
|
|
export function materialise(input, scratch) {
|
|
if (!isGenerator(input.path)) {
|
|
return { path: input.path, cleanup: () => undefined }
|
|
}
|
|
const path = join(scratch, `${basename(input.path, '.gen.json')}.pdf`)
|
|
writeFileSync(path, expandGenerator(input.path))
|
|
return { path, cleanup: () => unlinkSync(path) }
|
|
}
|
|
|
|
/** A fresh directory under `parent` for the run's temporary files. */
|
|
export function scratchDir(parent) {
|
|
const dir = mkdtempSync(join(parent, 'faunosteo-r4-import-'))
|
|
return { dir, remove: () => rmdirSync(dir) }
|
|
}
|