Files
faunosteo/apps/app/tests/helpers/goldenReports.ts
T
bchanot 9e87016399 feat(domain): R5.6 fingerprint switch to sha256-rfc8785-validated-v1
The Rust pipeline is the official seed writer (pnpm import:equine); sheet-ref.json
and report-migration-map.json carry 12d78872...74e2 and the v1 block, the only two
seed files changed. 27c7383c...2660 stays a registered alias, honoured only through
LoadedSheet::recognises_historical_stamp (verified v1, recomputed document). M1: the
snapshot of an old report keeps its stamp; export, archive reader strict. Historical
oracles run in their pre-switch context; equivalence is crate-private.
2026-10-25 02:02:42 +01:00

78 lines
2.9 KiB
TypeScript

import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import type { Report } from '@faunosteo/core-wasm/types'
import { importAttachment } from './pdfImport'
import type { SheetIndex } from '@/services/sheetIndex'
import { FIXTURES_DIR } from './goldens'
import {
leavesAsV2Report,
legacyLeaves,
loadLegacyBaseline,
} from './legacyLeaves'
/**
* The three reports the Step 6 goldens and the R2 envelope freeze are drawn
* from: the Step 5 v2 archive fixture migrated, the v3 demo report, and a v2
* report whose sphenoid and ssb findings the migration cannot place. Since
* R2 they are read the way the application reads an attachment: the core's
* layered reading (v3 parsed, v2 migrated through the sheet's map).
*/
export const GOLDEN_REPORTS = ['v2full', 'demo', 'v2unresolved'] as const
export type GoldenReportName = (typeof GOLDEN_REPORTS)[number]
export interface GoldenReports {
reports: Record<GoldenReportName, Report>
/** Findings the migration flagged in `v2unresolved`. */
unresolvedOfV2Unresolved: number
}
const readJson = (name: string): unknown =>
JSON.parse(readFileSync(resolve(FIXTURES_DIR, name), 'utf8'))
/** sphenoid + ssb (the families the migration cannot place) plus one leaf that resolves. */
function buildV2Unresolved(sheet: SheetIndex) {
const leaves = legacyLeaves(loadLegacyBaseline())
const unresolvedFamilies = leaves.filter(
(l) => l.zoneId === 'sphenoid' || l.zoneId === 'ssb',
)
const resolved = leaves.find((l) => l.zoneId === 'frontal')!
return importAttachment(
leavesAsV2Report([...unresolvedFamilies, resolved]),
sheet,
).read
}
/**
* The goldens were frozen before R5.6, when a v2 migration stamped the historical fingerprint
* (the pre-switch migration map). Since R5.6 the map stamps the canonical `v1` value and
* nothing else of the migrated report changes (Rust `pdf_import`
* `o7_after_r5_6_migrated_v2_reports_carry_the_canonical_stamp_and_nothing_else_moves`): the
* golden v2 reports are taken in that original context, as reports migrated before the switch
* and exported now. Their export keeps the stamp in the snapshot (M1), so the frozen bytes hold.
*/
export const HISTORICAL_FINGERPRINT =
'27c7383c445c73dc2001ebf4794a3ea63d416910bbbaa0d7848dd720de7c2660'
export function migratedBeforeR56(report: Report): Report {
return {
...report,
sheet: { ...report.sheet, documentSha256: HISTORICAL_FINGERPRINT },
}
}
export function buildGoldenReports(sheet: SheetIndex): GoldenReports {
const v2unresolved = buildV2Unresolved(sheet)
return {
reports: {
v2full: migratedBeforeR56(
importAttachment(readJson('report-v2.full.json'), sheet).read.report,
),
demo: importAttachment(readJson('report-v3.demo.json'), sheet).read
.report,
v2unresolved: migratedBeforeR56(v2unresolved.report),
},
unresolvedOfV2Unresolved: v2unresolved.unresolvedFindings,
}
}