test(tests): R4.2 ledger: reader rows point at their cargo tests, census checks they exist
69 ported rows of scan, inflate, read and the security import cases now name the O7/O9 cargo tests; r4-ledger.mjs refuses a ported cargo target absent from cargo test --list.
This commit is contained in:
1 parent
6ee04c96c5
commit
ebcae06ac1
2 files changed
+146
-75
No files matched your search
+77
-6
@@ -62,7 +62,13 @@ const APP_MOCKING_SUITES = [
|
||||
'state.coreFailures.test.tsx',
|
||||
]
|
||||
|
||||
const READER = 'R4.2 cargo (pending)'
|
||||
// R4.2 targets: one cargo test per oracle checks every frozen row (several TS cases fold
|
||||
// into one Rust test; the census below checks that each named test exists).
|
||||
const SCAN = 'cargo pdf_scan::every_pdf_input_scans_as_the_typescript_did'
|
||||
const DECODE = 'cargo pdf_scan::decode_pdf_string_rows_match'
|
||||
const LOCATE = 'cargo pdf_import::o7_locate_and_read_match_the_typescript'
|
||||
const INFLATE =
|
||||
'cargo pdf_inflate::every_o9_row_matches_node, pdf_inflate::every_o7_flate_input_matches_node'
|
||||
const WRITER = 'R4.4/R4.5 cargo (pending)'
|
||||
const CARGO_GOLDENS = 'R4.4/R4.5 cargo goldens (pending)'
|
||||
const SAME = 'vitest (same case)'
|
||||
@@ -104,18 +110,28 @@ const GOLDENS = `${APP}pdf.goldens.test.ts`
|
||||
// First match wins. `title` (a prefix or a RegExp) splits a file's cases.
|
||||
const RULES = [
|
||||
// packages/pdf, reader side (R4.2)
|
||||
{ file: `${PDF}scan.test.ts`, ...ported(READER, 'O7') },
|
||||
{ file: `${PDF}inflate.test.ts`, ...ported(READER, 'O7/O9') },
|
||||
{ file: `${PDF}read.test.ts`, ...ported(READER, 'O7') },
|
||||
{
|
||||
file: `${PDF}scan.test.ts`,
|
||||
title: /decodePdfString/,
|
||||
...ported(DECODE, 'O7'),
|
||||
},
|
||||
{
|
||||
file: `${PDF}scan.test.ts`,
|
||||
title: /locateAttachment|readAttachmentBytes|readAttachedDocument/,
|
||||
...ported(LOCATE, 'O7'),
|
||||
},
|
||||
{ file: `${PDF}scan.test.ts`, ...ported(SCAN, 'O7') },
|
||||
{ file: `${PDF}inflate.test.ts`, ...ported(INFLATE, 'O7/O9') },
|
||||
{ file: `${PDF}read.test.ts`, ...ported(LOCATE, 'O7') },
|
||||
{
|
||||
file: SECURITY,
|
||||
title: 'import: the report survives a rejected snapshot > ',
|
||||
...ported(READER, 'O7'),
|
||||
...ported(LOCATE, 'O7'),
|
||||
},
|
||||
{
|
||||
file: SECURITY,
|
||||
title: '__proto__ ids and the inflate bomb > inflates a normal payload',
|
||||
...ported(READER, 'O7'),
|
||||
...ported(INFLATE, 'O7'),
|
||||
},
|
||||
// packages/pdf, export side (R4.4 layout, R4.5 serialiser)
|
||||
{
|
||||
@@ -403,8 +419,63 @@ function printSummary(rows, totals) {
|
||||
console.log(`written: ${relative(ROOT, OUT)}`)
|
||||
}
|
||||
|
||||
/** The tests of one cargo test file of the core (`cargo test --test <file> -- --list`). */
|
||||
function cargoTests(file) {
|
||||
const run = spawnSync(
|
||||
'cargo',
|
||||
[
|
||||
'test',
|
||||
'-p',
|
||||
'faunosteo-core',
|
||||
'--features',
|
||||
'pdf-read',
|
||||
'--locked',
|
||||
'--test',
|
||||
file,
|
||||
'--',
|
||||
'--list',
|
||||
],
|
||||
{
|
||||
cwd: ROOT,
|
||||
encoding: 'utf8',
|
||||
env: { ...process.env, CARGO_TERM_COLOR: 'never' },
|
||||
},
|
||||
)
|
||||
if (run.status !== 0) {
|
||||
throw new Error(`cargo test --test ${file} -- --list failed: ${run.stderr}`)
|
||||
}
|
||||
const names = new Set()
|
||||
for (const line of run.stdout.split('\n')) {
|
||||
const test = /^(\S+): test$/.exec(line)
|
||||
if (test) names.add(test[1])
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
/** Census (plan §B.6): every `cargo` target of a ported row 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)
|
||||
}
|
||||
const listed = new Map()
|
||||
const missing = []
|
||||
for (const name of wanted) {
|
||||
const [file, test] = name.split('::')
|
||||
if (!listed.has(file)) listed.set(file, cargoTests(file))
|
||||
if (!listed.get(file).has(test)) missing.push(name)
|
||||
}
|
||||
return missing
|
||||
}
|
||||
|
||||
function main() {
|
||||
const { rows, errors, totals } = collect()
|
||||
for (const name of missingCargoTargets(rows)) {
|
||||
errors.push(`ported target missing from cargo test --list: ${name}`)
|
||||
}
|
||||
if (errors.length) {
|
||||
for (const error of errors) console.error(`r4-ledger: ${error}`)
|
||||
console.error('r4-ledger: nothing written')
|
||||
|
||||
Reference in new issue
Block a user