test(tests): R4.8 ledger reads its 301 frozen cases from the committed TSV, re-derives the dispositions of the deleted suites, checks every cargo and vitest target; browser scripts cite the frozen N-1 inflate copy
This commit is contained in:
1 parent
0dc1ba27c7
commit
e88769a707
5 files changed
+343
-316
No files matched your search
@@ -184,7 +184,7 @@ length and digest) to a temporary `<slug>.pdf`, removed after its run.
|
||||
Reads `crates/core/tests/oracles/r4/inflate.json` and its inputs under
|
||||
`apps/app/tests/fixtures/pdf/r4/inflate/` (each checked against the recorded
|
||||
length and sha256), runs in each engine, on the application's Home page, a
|
||||
copy of `inflateFlate` from `packages/pdf/src/attachment/inflate.ts`
|
||||
copy of `inflateFlate` from the R3 engine (now the frozen N-1 copy `packages/core-wasm/tests/n-1/scanner/attachment/inflate.ts`)
|
||||
(`DecompressionStream('deflate')`, 16 KiB awaited slices, concurrent drain,
|
||||
null past the row's limit or on any error), and writes
|
||||
`inflate.browsers.json`: per row, Node's verdict copied from `inflate.json`
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// O9 browser verdicts (R4.1e, plan §B.1.2 "Inflation", §B.5.1): runs, in
|
||||
// each engine, the algorithm of packages/pdf/src/attachment/inflate.ts
|
||||
// `inflateFlate` (copied into the page below) on every row of
|
||||
// each engine, the algorithm of the R3 engine's `inflateFlate` (the frozen
|
||||
// copy packages/core-wasm/tests/n-1/scanner/attachment/inflate.ts; copied
|
||||
// into the page below) on every row of
|
||||
// crates/core/tests/oracles/r4/inflate.json, with the row's limit, on the
|
||||
// input bytes of apps/app/tests/fixtures/pdf/r4/inflate/. Writes
|
||||
// crates/core/tests/oracles/r4/inflate.browsers.json (per row: Node's
|
||||
|
||||
@@ -4,8 +4,9 @@ import { dirname, join, resolve } from 'node:path'
|
||||
|
||||
/**
|
||||
* Fixture files, and the R4 oracle inputs committed as generator
|
||||
* descriptions (`<slug>.gen.json`, generator `concat/1`, written by
|
||||
* packages/pdf/tests/helpers/r4-reader-io.ts for inputs over 2 MiB).
|
||||
* descriptions (`<slug>.gen.json`, generator `concat/1`, written at the
|
||||
* R4.1 freeze by the engine's generator helper, deleted at R4.8, for inputs
|
||||
* over 2 MiB; `crates/core/tests/common/r4.rs` expands them).
|
||||
*/
|
||||
|
||||
export const sha256 = (bytes) =>
|
||||
|
||||
+136
-111
@@ -1,21 +1,22 @@
|
||||
// R4 test ledger (plan 2026-10-17 §B.6): one row per TypeScript test case
|
||||
// of the PDF path at the freeze, with its planned disposition. Runs vitest
|
||||
// with its JSON reporter (report files in os.tmpdir()) on every packages/pdf
|
||||
// suite, the application's PDF, route and store suites and its r4.*
|
||||
// generators, and the core-wasm N-1 scanner test; writes
|
||||
// crates/core/tests/pdf/LEDGER.tsv (files sorted, cases in declaration
|
||||
// order) and prints the rows per file and disposition. Fails, writing
|
||||
// nothing, when a run fails, a requested file is missing from its report, a
|
||||
// case matches no rule, a rule matches no case, or the rows do not reconcile
|
||||
// with vitest's totals. "(pending)" targets are filled when the case is
|
||||
// ported.
|
||||
// of the PDF path at the freeze (R4.1), with its disposition. The frozen
|
||||
// case list is the committed ledger itself (ts_file, case_title: 301 rows;
|
||||
// the engine suites and the deleted app suites no longer run, R4.8); the
|
||||
// dispositions, targets and notes are re-derived from the rules below and
|
||||
// checked: every `cargo` target names a test `cargo test -- --list` knows,
|
||||
// every `vitest (same case…)` target names a case the live vitest report of
|
||||
// that file holds (the surviving suites run with the JSON reporter, report
|
||||
// files in os.tmpdir()). Writes crates/core/tests/pdf/LEDGER.tsv (files
|
||||
// sorted, cases in frozen order) and prints the rows per file and
|
||||
// disposition. Fails, writing nothing, when a run fails, a frozen case
|
||||
// matches no rule, a rule matches no case, a target is missing, or the row
|
||||
// count is not the freeze's.
|
||||
// Usage: node scripts/r4-ledger.mjs (core module built: pnpm wasm:build)
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import {
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
rmdirSync,
|
||||
unlinkSync,
|
||||
@@ -36,21 +37,12 @@ const COLUMNS = [
|
||||
'note',
|
||||
]
|
||||
const DISPOSITIONS = ['ported', 'replaced', 'kept', 'deleted']
|
||||
/** The rows of the freeze (R4.1: 140 engine cases + 155 app cases + 6 N-1 scanner cases). */
|
||||
const FROZEN_ROWS = 301
|
||||
|
||||
const PDF = 'packages/pdf/tests/'
|
||||
const APP = 'apps/app/tests/unit/'
|
||||
const N1_SCANNER = 'packages/core-wasm/tests/n-1.scanner.test.ts'
|
||||
const APP_PDF_SUITES = [
|
||||
'pdf.goldens.test.ts',
|
||||
'pdf.roundtrip.test.ts',
|
||||
'pdf.import.test.ts',
|
||||
'archive.envelopes.test.ts',
|
||||
'n-1.reader.test.ts',
|
||||
'pdf.export.app.test.ts',
|
||||
'migration.leaves.test.ts',
|
||||
'pdf.browserRasterizer.test.ts',
|
||||
'scripts.compare.test.ts',
|
||||
]
|
||||
/** Suites mocking `@/pdf/*`: rewritten when the import (R4.3) and the
|
||||
* export (R4.6) switch. */
|
||||
const APP_MOCKING_SUITES = [
|
||||
@@ -96,18 +88,25 @@ const RASTER_CHECK =
|
||||
'vitest (same case); cargo pdf_png::every_o6_decode_matches_pdf_lib'
|
||||
const SAME = 'vitest (same case)'
|
||||
const NONE = '-'
|
||||
const GENERATOR = 'generator; oracle files kept (R4.8)'
|
||||
const N1_SWITCH = 'reader switched to the frozen O11 scanner at R4.8'
|
||||
const PDF_LIB_LEAVES =
|
||||
'pdf-lib leaves the app; read-back moves to cargo/lopdf or the wasm reader'
|
||||
/** R4.6: the export side of these cases runs on the core; the reader is the kept TS one
|
||||
* until R4.8, the kinds and round trips are cargo's. */
|
||||
const IMPORT_R46 =
|
||||
'vitest (same case, export on the core); cargo pdf_import (kinds), pdf_serialize::restoration_round_trip_loses_nothing'
|
||||
/** R4.6: the roundtrip suite reads the Rust export's content streams and metadata through
|
||||
* pdf-lib (kept in the tests until R4.8); the read-back is cargo's from R4.8. */
|
||||
const ROUNDTRIP_R46 =
|
||||
'vitest (same case, read from the file); cargo pdf_serialize::restoration_round_trip_loses_nothing from R4.8'
|
||||
const GENERATOR = 'generator deleted at R4.8; oracle files kept'
|
||||
const ENGINE_GONE = 'engine suite deleted at R4.8 with packages/pdf'
|
||||
const N1_SWITCH =
|
||||
'reader = the frozen O11 scanner (@faunosteo/core-wasm/n-1) since R4.8'
|
||||
const PDF_LIB_LEFT =
|
||||
'read back by tests/helpers/pdfFile.ts since R4.8 (no pdf-lib); import by the module reader (tests/helpers/pdfImport.ts)'
|
||||
/** R4.8: the TS import path left the application with its suite; the kinds are cargo's
|
||||
* and the worker suites'. */
|
||||
const IMPORT_R48 =
|
||||
'cargo pdf_import::o8_import_matches_the_r3_path_outside_the_declared_differences, pdf_import::the_facade_envelope_carries_the_closed_kinds; vitest core.importWorker.test.ts (the kinds through the worker)'
|
||||
const IMPORT_SUITE_GONE =
|
||||
'suite deleted at R4.8: importReportFromPdf left apps/app/src (the app imports through the worker)'
|
||||
const REEXPORT_GONE =
|
||||
'suite deleted at R4.8: the re-export from the envelope alone is cargo export_from_envelope (no sheet, no branding in its signature), byte-equal on 13 runs'
|
||||
const COMPARE_GONE =
|
||||
'TS CLI and suite deleted at R4.8 (pnpm report:compare runs the binary)'
|
||||
/** The roundtrip suite reads the Rust export's content streams and metadata from the file. */
|
||||
const ROUNDTRIP =
|
||||
'vitest (same case, read from the file); cargo pdf_serialize::restoration_round_trip_loses_nothing'
|
||||
|
||||
/** R4.7: the `scripts.compare.test.ts` case → the cargo test replaying its O10 rows. */
|
||||
const COMPARE_CASES = {
|
||||
@@ -261,7 +260,11 @@ const RULES = [
|
||||
{
|
||||
file: GOLDENS,
|
||||
title: 'golden inputs > the 2×1 PNG decodes',
|
||||
...replaced(RASTER_CHECK, 'O6', 'pdf-lib embedPng check of the golden rasters'),
|
||||
...replaced(
|
||||
RASTER_CHECK,
|
||||
'O6',
|
||||
'the golden rasters as the core writes them (XObject sizes read from the file since R4.8)',
|
||||
),
|
||||
},
|
||||
{
|
||||
file: GOLDENS,
|
||||
@@ -271,7 +274,11 @@ const RULES = [
|
||||
{
|
||||
file: GOLDENS,
|
||||
title: /^goldens of [^>]+ > [^>]+ > text, images and links per locale/,
|
||||
...replaced(CARGO_GOLDENS, 'O1', 'Step 6 text, images and links goldens'),
|
||||
...replaced(
|
||||
CARGO_GOLDENS,
|
||||
'O1',
|
||||
`Step 6 text, images and links goldens; ${PDF_LIB_LEFT}`,
|
||||
),
|
||||
},
|
||||
{
|
||||
file: GOLDENS,
|
||||
@@ -285,17 +292,17 @@ const RULES = [
|
||||
},
|
||||
{
|
||||
file: `${APP}pdf.import.test.ts`,
|
||||
...replaced(IMPORT_R46, NONE, PDF_LIB_LEAVES),
|
||||
...replaced(IMPORT_R48, NONE, IMPORT_SUITE_GONE),
|
||||
},
|
||||
{
|
||||
file: `${APP}pdf.roundtrip.test.ts`,
|
||||
...replaced(ROUNDTRIP_R46, NONE, PDF_LIB_LEAVES),
|
||||
...replaced(ROUNDTRIP, NONE, PDF_LIB_LEFT),
|
||||
},
|
||||
{ file: `${APP}archive.envelopes.test.ts`, ...kept(NONE, N1_SWITCH) },
|
||||
{ file: `${APP}n-1.reader.test.ts`, ...kept(NONE, N1_SWITCH) },
|
||||
{
|
||||
file: `${APP}pdf.export.app.test.ts`,
|
||||
...ported(ROUND_TRIP, NONE, 'export_from_envelope'),
|
||||
...ported(ROUND_TRIP, NONE, REEXPORT_GONE),
|
||||
},
|
||||
{ file: `${APP}migration.leaves.test.ts`, ...kept(NONE) },
|
||||
{ file: `${APP}pdf.browserRasterizer.test.ts`, ...kept(NONE) },
|
||||
@@ -303,7 +310,7 @@ const RULES = [
|
||||
...Object.entries(COMPARE_CASES).map(([title, test]) => ({
|
||||
file: `${APP}scripts.compare.test.ts`,
|
||||
title,
|
||||
...ported(`cargo pdf_compare::${test}`, 'O10'),
|
||||
...ported(`cargo pdf_compare::${test}`, 'O10', COMPARE_GONE),
|
||||
})),
|
||||
...APP_MOCKING_SUITES.map((name) => ({
|
||||
file: `${APP}${name}`,
|
||||
@@ -312,26 +319,34 @@ const RULES = [
|
||||
{ file: N1_SCANNER, ...kept('O11') },
|
||||
]
|
||||
|
||||
function testFiles(dir, keep) {
|
||||
return readdirSync(join(ROOT, dir))
|
||||
.filter(keep)
|
||||
.sort()
|
||||
.map((name) => `${dir}${name}`)
|
||||
/** The frozen cases: the committed ledger's (ts_file, case_title), in file order. */
|
||||
function frozenCases() {
|
||||
const [header, ...lines] = readFileSync(OUT, 'utf8').trimEnd().split('\n')
|
||||
const columns = header.split('\t')
|
||||
const at = (name) => columns.indexOf(name)
|
||||
const cases = lines.map((line) => {
|
||||
const fields = line.split('\t')
|
||||
return { file: fields[at('ts_file')], title: fields[at('case_title')] }
|
||||
})
|
||||
if (cases.length !== FROZEN_ROWS) {
|
||||
throw new Error(
|
||||
`${relative(ROOT, OUT)}: ${cases.length} rows, ${FROZEN_ROWS} frozen`,
|
||||
)
|
||||
}
|
||||
return cases
|
||||
}
|
||||
|
||||
function suites() {
|
||||
const appGenerators = testFiles(APP, (n) => /^r4\..+\.test\.tsx?$/.test(n))
|
||||
const appNamed = [...APP_PDF_SUITES, ...APP_MOCKING_SUITES].map(
|
||||
(n) => `${APP}${n}`,
|
||||
/** The frozen files that still exist, grouped by the package that runs them. */
|
||||
function liveSuites(cases) {
|
||||
const files = [...new Set(cases.map((c) => c.file))].filter((file) =>
|
||||
existsSync(join(ROOT, file)),
|
||||
)
|
||||
return [
|
||||
{
|
||||
pkg: 'packages/pdf',
|
||||
files: testFiles(PDF, (n) => n.endsWith('.test.ts')),
|
||||
},
|
||||
{ pkg: 'apps/app', files: [...appNamed, ...appGenerators] },
|
||||
{ pkg: 'packages/core-wasm', files: [N1_SCANNER] },
|
||||
]
|
||||
const pkgOf = (file) => file.split('/tests/')[0]
|
||||
const pkgs = [...new Set(files.map(pkgOf))]
|
||||
return pkgs.map((pkg) => ({
|
||||
pkg,
|
||||
files: files.filter((f) => pkgOf(f) === pkg),
|
||||
}))
|
||||
}
|
||||
|
||||
/** vitest's JSON report of `files`, run from the package as test:run. */
|
||||
@@ -359,6 +374,27 @@ function runVitest({ pkg, files }, reportDir, errors) {
|
||||
return parsed
|
||||
}
|
||||
|
||||
/** file → the titles of its live cases (every one must pass). */
|
||||
function liveCases(suites, reportDir, errors, totals) {
|
||||
const live = new Map()
|
||||
for (const suite of suites) {
|
||||
const report = runVitest(suite, reportDir, errors)
|
||||
if (!report) continue
|
||||
totals.push([suite.pkg, report.numTotalTests])
|
||||
for (const result of report.testResults) {
|
||||
const file = relative(ROOT, result.name)
|
||||
if (result.status !== 'passed') errors.push(`${file}: ${result.status}`)
|
||||
const titles = result.assertionResults.map((a) =>
|
||||
[...a.ancestorTitles, a.title].join(' > '),
|
||||
)
|
||||
live.set(file, new Set(titles))
|
||||
}
|
||||
for (const file of suite.files)
|
||||
if (!live.has(file)) errors.push(`missing from the report: ${file}`)
|
||||
}
|
||||
return live
|
||||
}
|
||||
|
||||
function matches(rule, file, title) {
|
||||
if (rule.file !== file) return false
|
||||
if (rule.title === undefined) return true
|
||||
@@ -367,8 +403,7 @@ function matches(rule, file, title) {
|
||||
: title.startsWith(rule.title)
|
||||
}
|
||||
|
||||
function rowOf(file, assertion, used, errors) {
|
||||
const title = [...assertion.ancestorTitles, assertion.title].join(' > ')
|
||||
function rowOf({ file, title }, used, errors) {
|
||||
const at = RULES.findIndex((rule) => matches(rule, file, title))
|
||||
if (at < 0) {
|
||||
errors.push(`no disposition: ${file} > ${title}`)
|
||||
@@ -376,68 +411,52 @@ function rowOf(file, assertion, used, errors) {
|
||||
}
|
||||
used.add(at)
|
||||
const { disposition, target, oracle, note } = RULES[at]
|
||||
const status =
|
||||
assertion.status === 'passed'
|
||||
? ''
|
||||
: ` (status at freeze: ${assertion.status})`
|
||||
const gone = file.startsWith(PDF) && note === NONE ? ENGINE_GONE : note
|
||||
return {
|
||||
ts_file: file,
|
||||
case_title: title,
|
||||
disposition,
|
||||
target,
|
||||
oracle,
|
||||
note: note + status,
|
||||
note: gone,
|
||||
}
|
||||
}
|
||||
|
||||
/** The rows of one package's report, checked to hold the requested files. */
|
||||
function suiteRows(suite, report, context) {
|
||||
const { errors, used } = context
|
||||
const results = report.testResults.map((result) => ({
|
||||
...result,
|
||||
file: relative(ROOT, result.name),
|
||||
}))
|
||||
const found = results.map((r) => r.file)
|
||||
for (const file of suite.files)
|
||||
if (!found.includes(file)) errors.push(`missing: ${file}`)
|
||||
for (const file of found)
|
||||
if (!suite.files.includes(file)) errors.push(`unrequested: ${file}`)
|
||||
for (const r of results)
|
||||
if (r.status !== 'passed') errors.push(`${r.file}: ${r.status}`)
|
||||
const rows = results.flatMap((r) =>
|
||||
r.assertionResults.map((a) => rowOf(r.file, a, used, errors)),
|
||||
)
|
||||
if (rows.length !== report.numTotalTests) {
|
||||
const total = report.numTotalTests
|
||||
errors.push(`${suite.pkg}: ${rows.length} rows, ${total} vitest cases`)
|
||||
}
|
||||
return rows.filter((row) => row !== null)
|
||||
/** A `vitest (same case…)` target names a live case of the same file. */
|
||||
function missingVitestTargets(rows, live) {
|
||||
return rows
|
||||
.filter((row) => row.target.startsWith('vitest (same case'))
|
||||
.filter((row) => !live.get(row.ts_file)?.has(row.case_title))
|
||||
.map((row) => `${row.ts_file} > ${row.case_title}`)
|
||||
}
|
||||
|
||||
function collect() {
|
||||
const context = { errors: [], used: new Set(), totals: [] }
|
||||
const errors = []
|
||||
const used = new Set()
|
||||
const totals = []
|
||||
const cases = frozenCases()
|
||||
const reportDir = mkdtempSync(join(tmpdir(), 'faunosteo-r4-ledger-'))
|
||||
let live
|
||||
try {
|
||||
const rows = suites().flatMap((suite) => {
|
||||
const report = runVitest(suite, reportDir, context.errors)
|
||||
if (!report) return []
|
||||
context.totals.push([suite.pkg, report.numTotalTests])
|
||||
return suiteRows(suite, report, context)
|
||||
})
|
||||
RULES.forEach((rule, at) => {
|
||||
if (!context.used.has(at))
|
||||
context.errors.push(
|
||||
`rule matches no case: ${rule.file} ${rule.title ?? ''}`,
|
||||
)
|
||||
})
|
||||
// Stable sort: files in path order, cases in declaration order.
|
||||
rows.sort((a, b) =>
|
||||
a.ts_file === b.ts_file ? 0 : a.ts_file < b.ts_file ? -1 : 1,
|
||||
)
|
||||
return { rows, ...context }
|
||||
live = liveCases(liveSuites(cases), reportDir, errors, totals)
|
||||
} finally {
|
||||
rmdirSync(reportDir)
|
||||
}
|
||||
const rows = cases
|
||||
.map((c) => rowOf(c, used, errors))
|
||||
.filter((row) => row !== null)
|
||||
RULES.forEach((rule, at) => {
|
||||
if (!used.has(at))
|
||||
errors.push(`rule matches no case: ${rule.file} ${rule.title ?? ''}`)
|
||||
})
|
||||
for (const name of missingVitestTargets(rows, live)) {
|
||||
errors.push(`vitest target missing from the live report: ${name}`)
|
||||
}
|
||||
// Stable sort: files in path order, cases in frozen order.
|
||||
rows.sort((a, b) =>
|
||||
a.ts_file === b.ts_file ? 0 : a.ts_file < b.ts_file ? -1 : 1,
|
||||
)
|
||||
return { rows, errors, totals }
|
||||
}
|
||||
|
||||
function tsvField(value) {
|
||||
@@ -484,7 +503,9 @@ function printSummary(rows, totals) {
|
||||
console.log(countLine('total', rows))
|
||||
const vitest = totals.map(([pkg, n]) => `${pkg} ${n}`).join(', ')
|
||||
const sum = totals.reduce((n, [, count]) => n + count, 0)
|
||||
console.log(`vitest cases: ${vitest} = ${sum}; ledger rows: ${rows.length}`)
|
||||
console.log(
|
||||
`live vitest cases of the frozen files: ${vitest} = ${sum}; ledger rows: ${rows.length} (frozen ${FROZEN_ROWS})`,
|
||||
)
|
||||
console.log(`written: ${relative(ROOT, OUT)}`)
|
||||
}
|
||||
|
||||
@@ -521,14 +542,15 @@ function cargoTests(file) {
|
||||
return names
|
||||
}
|
||||
|
||||
/** Census (plan §B.6): every `cargo` target of a ported row names an existing test. */
|
||||
/** Census (plan §B.6): every `cargo file::test` of every target names an existing test. */
|
||||
function missingCargoTargets(rows) {
|
||||
const wanted = new Set()
|
||||
for (const row of rows) {
|
||||
if (row.disposition !== 'ported' || !row.target.startsWith('cargo '))
|
||||
continue
|
||||
for (const name of row.target.slice('cargo '.length).split(', '))
|
||||
wanted.add(name)
|
||||
for (const part of row.target.split('; ')) {
|
||||
if (!part.startsWith('cargo ')) continue
|
||||
for (const name of part.slice('cargo '.length).split(', '))
|
||||
if (name.includes('::')) wanted.add(name)
|
||||
}
|
||||
}
|
||||
const listed = new Map()
|
||||
const missing = []
|
||||
@@ -543,7 +565,10 @@ function missingCargoTargets(rows) {
|
||||
function main() {
|
||||
const { rows, errors, totals } = collect()
|
||||
for (const name of missingCargoTargets(rows)) {
|
||||
errors.push(`ported target missing from cargo test --list: ${name}`)
|
||||
errors.push(`cargo target missing from cargo test --list: ${name}`)
|
||||
}
|
||||
if (rows.length !== FROZEN_ROWS) {
|
||||
errors.push(`${rows.length} rows, ${FROZEN_ROWS} frozen`)
|
||||
}
|
||||
if (errors.length) {
|
||||
for (const error of errors) console.error(`r4-ledger: ${error}`)
|
||||
|
||||
Reference in new issue
Block a user