Files

138 lines
5.2 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// R4 J1 device acceptance kit (plan 2026-10-17 §A.4, BDR-058): gathers in one
// folder the files the owner picks from a phone or a computer, each with the
// message expected (docs/development/R4_J1.md). Reference PDFs (Step 5 v2 and
// v3, Step 6 envelopes, R3 exports), a hostile folder with the expected
// message per file (from the frozen O8 oracle, the declared R4 differences
// applied), rescue copies (valid, BOM, invalid UTF-8, oversized, refused) and
// the large synthetic L export built like the application exports it is NOT
// here (it needs the browser: export the L report from the editor, see the
// doc). Synthetic data only. Usage: node scripts/r4-j1-kit.mjs [out-dir]
// (default: a `faunosteo-j1-kit` folder next to the repository).
import { mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
import { join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
const FIXTURES = join(ROOT, 'apps/app/tests/fixtures')
const OUT = resolve(process.argv[2] ?? join(ROOT, '..', 'faunosteo-j1-kit'))
// The FR messages of apps/app/src/i18n/fr.ts, by kind (kept in step by hand).
const MESSAGES = {
editor: 'ouvre le bilan dans l’éditeur',
invalid_pdf: "Ce fichier n'est pas un PDF lisible.",
no_attachment:
"Ce PDF n'a pas été généré par Faunosteo (pas de données détectées).",
attachment_stripped:
'Ce PDF Faunosteo a perdu ses données embarquées (pièce jointe supprimée…). Utilisez le fichier d’origine.',
incompatible_version:
'Ce PDF est au format v{version}, que cette version de l’application ne sait pas lire…',
lone_surrogate:
'Ce PDF Faunosteo contient un texte mal encodé que cette version ne peut pas relire sans l’altérer. Import refusé…',
invalid_copy:
'Ce fichier n’est pas une copie de secours Faunosteo lisible par cette version. Import refusé…',
}
/** The R4 outcome of an O8 case (RUST.md §10.3 declared differences applied). */
const DECLARED = {
'values-1m': 'attachment_stripped',
'surrogate-content-overwritten': 'lone_surrogate',
'surrogate-version-overwritten': 'lone_surrogate',
'two-files-decoy-first': 'lone_surrogate',
}
function copy(from, toDir, name = from.split('/').pop()) {
mkdirSync(toDir, { recursive: true })
writeFileSync(join(toDir, name), readFileSync(from))
return name
}
const lines = ['# Kit J1 (R4) — fichiers et message attendu', '']
// 1. Reference PDFs: every one opens the editor.
lines.push('## 1-reference : chaque fichier ouvre l’éditeur', '')
const reference = join(OUT, '1-reference')
for (const f of [
'report-v2.full.pdf',
'report-v2.minimal.pdf',
'report-v3.bare.pdf',
]) {
lines.push(`- ${copy(join(FIXTURES, f), reference)} (Step 5)`)
}
for (const f of readdirSync(join(FIXTURES, 'pdf/r3')).filter((n) =>
n.endsWith('.pdf'),
)) {
lines.push(
`- ${copy(join(FIXTURES, 'pdf/r3', f), reference, `r3-${f}`)} (R3)`,
)
}
lines.push(
`- ${copy(join(FIXTURES, 'pdf/r3/real/v2full-obs1.fr.logos.pdf'), reference, 'r3-real-raster.pdf')} (R3, rasters réels)`,
)
for (const f of readdirSync(join(FIXTURES, 'pdf/step6')).filter((n) =>
n.endsWith('.pdf'),
)) {
lines.push(
`- ${copy(join(FIXTURES, 'pdf/step6', f), reference, `step6-${f}`)} (Step 6)`,
)
}
// 2. Hostile folder from the O8 oracle.
lines.push('', '## 2-hostile : message attendu par fichier (corpus O8)', '')
const oracle = JSON.parse(
readFileSync(
join(ROOT, 'crates/core/tests/oracles/r4/tolerance.json'),
'utf8',
),
)
const hostile = join(OUT, '2-hostile')
for (const c of oracle.cases) {
const kind = DECLARED[c.id] ?? (c.outcome.ok ? 'editor' : c.outcome.kind)
const name = copy(join(ROOT, c.pdf), hostile)
const expected = MESSAGES[kind].replace(
'{version}',
String(c.outcome.foundVersion ?? ''),
)
lines.push(`- ${name} : ${expected}`)
}
// 3. Rescue copies.
lines.push('', '## 3-copies : copies de secours', '')
const copies = join(OUT, '3-copies')
mkdirSync(copies, { recursive: true })
const demo = readFileSync(join(FIXTURES, 'report-v3.demo.json'), 'utf8')
const write = (name, data, note) => {
writeFileSync(join(copies, name), data)
lines.push(`- ${name} : ${note}`)
}
write('copie-valide.json', demo, MESSAGES.editor)
write('copie-bom.json', `${demo}`, `${MESSAGES.editor} (BOM accepté)`)
write(
'copie-sans-extension',
demo,
`${MESSAGES.editor} (routée par le contenu)`,
)
write(
'copie-utf8-invalide.json',
Buffer.concat([
Buffer.from('{"version": 3, "x": "'),
Buffer.from([0xff]),
Buffer.from('"}'),
]),
MESSAGES.invalid_copy,
)
write('copie-json-invalide.json', '{"version": 3,', MESSAGES.invalid_copy)
write('copie-version-1.json', '{"version": 1}', MESSAGES.invalid_copy)
write(
'copie-L-60-observations.json',
readFileSync(join(FIXTURES, 'r4/reports/L.json'), 'utf8'),
`${MESSAGES.editor} ; sur l’ordinateur, exporter ensuite ce bilan en PDF (export Rust, ≈ 44 Mo) pour J1.8 et J1.9`,
)
write(
'copie-trop-grande.json',
`{"version":3,"a":[${'1,'.repeat((9 * 1024 * 1024) / 2)}1]}`,
`${MESSAGES.invalid_copy} (18 Mo, au-dessus de 16 Mio)`,
)
writeFileSync(join(OUT, 'ATTENDU.md'), `${lines.join('\n')}\n`)
console.log(`kit written to ${OUT} (${lines.length} lines in ATTENDU.md)`)