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.
This commit is contained in:
1 parent
59521dc195
commit
9e87016399
31 files changed
+2331
-154
No files matched your search
@@ -43,15 +43,34 @@ function buildV2Unresolved(sheet: SheetIndex) {
|
||||
).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: importAttachment(readJson('report-v2.full.json'), sheet).read
|
||||
.report,
|
||||
v2full: migratedBeforeR56(
|
||||
importAttachment(readJson('report-v2.full.json'), sheet).read.report,
|
||||
),
|
||||
demo: importAttachment(readJson('report-v3.demo.json'), sheet).read
|
||||
.report,
|
||||
v2unresolved: v2unresolved.report,
|
||||
v2unresolved: migratedBeforeR56(v2unresolved.report),
|
||||
},
|
||||
unresolvedOfV2Unresolved: v2unresolved.unresolvedFindings,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* R5.6 in the application, on the switched bundled sheet (`sha256-rfc8785-validated-v1`):
|
||||
* a v2 report migrated now carries the canonical value and exports one consistent envelope
|
||||
* that the N-1 readers accept; an old report on the historical value opens with no rebase and
|
||||
* re-exports with its own stamp in the snapshot (the goldens prove the bytes); no visible
|
||||
* change. The historical goldens run in their original context (`helpers/goldenReports.ts`).
|
||||
*/
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
readArchiveDocument,
|
||||
readAttachmentBytes,
|
||||
ReportArchiveEnvelopeSchema,
|
||||
} from '@faunosteo/core-wasm/n-1'
|
||||
import { exportReportToPdf } from '@/pdf/export'
|
||||
import type { SheetIndex } from '@/services/sheetIndex'
|
||||
import { bundledMigrationMap, loadTestSheet } from '../helpers/sheet'
|
||||
import { FIXTURES_DIR, ONE_PX_PNG } from '../helpers/goldens'
|
||||
import { HISTORICAL_FINGERPRINT } from '../helpers/goldenReports'
|
||||
import { importAttachment } from '../helpers/pdfImport'
|
||||
|
||||
vi.mock('@/pdf/browserRasterizer', () => ({
|
||||
browserRasterizer: vi.fn(async () => ONE_PX_PNG),
|
||||
}))
|
||||
vi.mock('@/pdf/branding', async () => {
|
||||
const { brandingOf } = await import('../helpers/goldens')
|
||||
return { loadBranding: vi.fn(() => brandingOf('nologos')) }
|
||||
})
|
||||
|
||||
const CANONICAL =
|
||||
'12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2'
|
||||
let sheet: SheetIndex
|
||||
|
||||
beforeAll(async () => {
|
||||
sheet = await loadTestSheet()
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => undefined)
|
||||
})
|
||||
afterAll(() => vi.restoreAllMocks())
|
||||
|
||||
interface Stamped {
|
||||
report: { sheet: { documentSha256: string } }
|
||||
sheetSnapshot: { ref: { documentSha256: string } }
|
||||
}
|
||||
|
||||
async function exported(
|
||||
report: Parameters<typeof exportReportToPdf>[0],
|
||||
): Promise<Stamped> {
|
||||
const { pdf } = await exportReportToPdf(report, sheet, { locale: 'fr' })
|
||||
const bytes = new Uint8Array(await pdf.arrayBuffer())
|
||||
return JSON.parse(
|
||||
new TextDecoder().decode(await readAttachmentBytes(bytes)),
|
||||
) as Stamped
|
||||
}
|
||||
|
||||
describe('R5.6 on the switched sheet', () => {
|
||||
it('stamps a new or newly migrated report with the canonical value', async () => {
|
||||
expect(sheet.sheet.ref.documentSha256).toBe(CANONICAL)
|
||||
const v2 = JSON.parse(
|
||||
readFileSync(resolve(FIXTURES_DIR, 'report-v2.full.json'), 'utf8'),
|
||||
)
|
||||
const migrated = importAttachment(v2, sheet).read.report
|
||||
expect(migrated.sheet.documentSha256).toBe(CANONICAL)
|
||||
const envelope = await exported(migrated)
|
||||
expect(envelope.report.sheet.documentSha256).toBe(CANONICAL)
|
||||
expect(envelope.sheetSnapshot.ref.documentSha256).toBe(CANONICAL)
|
||||
expect(ReportArchiveEnvelopeSchema.safeParse(envelope).success).toBe(true)
|
||||
const outcome = readArchiveDocument(envelope, await bundledMigrationMap())
|
||||
expect(outcome.snapshotRejected).toBeUndefined()
|
||||
}, 30_000)
|
||||
|
||||
it('opens an old report with no rebase and re-exports it with one stamp', async () => {
|
||||
const demo = JSON.parse(
|
||||
readFileSync(resolve(FIXTURES_DIR, 'report-v3.demo.json'), 'utf8'),
|
||||
)
|
||||
const imported = importAttachment(demo, sheet)
|
||||
expect(imported.rebase.rebased).toBe(false)
|
||||
expect(imported.rebase.report.sheet.documentSha256).toBe(
|
||||
HISTORICAL_FINGERPRINT,
|
||||
)
|
||||
const envelope = await exported(imported.rebase.report)
|
||||
expect(envelope.report.sheet.documentSha256).toBe(HISTORICAL_FINGERPRINT)
|
||||
expect(envelope.sheetSnapshot.ref.documentSha256).toBe(
|
||||
HISTORICAL_FINGERPRINT,
|
||||
)
|
||||
}, 30_000)
|
||||
})
|
||||
Reference in new issue
Block a user