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:
bchanot committed 2026-10-25 02:02:42 +01:00
1 parent 59521dc195
commit 9e87016399
31 files changed
+2331 -154

No files matched your search

@@ -350,8 +350,16 @@ describe('R5.1 oracles (crates/core/tests/oracles/r5)', () => {
const oracle = JSON.parse(frozen('pipeline.json')) as {
artifacts: Array<{ folder: string; file: string; sha256: string }>
}
// Since R5.6 the two fingerprinted draft files are Rust's (`v1`); the ledger recorded the
// TypeScript's, frozen under `crates/core/tests/fixtures/r5-6/pre-switch` (the Rust suite
// `curation_draft` proves the committed ones are those under the declared rule).
const preSwitch = new Set(['sheet-ref.json', 'report-migration-map.json'])
for (const row of oracle.artifacts) {
const committed = readFileSync(resolve(REPO, row.folder, row.file))
const folder =
row.folder.endsWith('/draft') && preSwitch.has(row.file)
? 'crates/core/tests/fixtures/r5-6/pre-switch'
: row.folder
const committed = readFileSync(resolve(REPO, folder, row.file))
expect(sha256Hex(committed), `${row.folder}/${row.file}`).toBe(row.sha256)
}
})
+13 -2
View File
@@ -62,10 +62,21 @@ describe('committed legacy-import folder (golden)', () => {
})
})
/**
* Since R5.6 the Rust pipeline writes the seed (`pnpm import:equine`) under the fingerprint
* convention `sha256-rfc8785-validated-v1`; this TypeScript generator (`import:equine:legacy`)
* keeps the historical one. Its two fingerprint-bearing files are compared with the pre-switch
* files it wrote (frozen under `crates/core/tests/fixtures/r5-6/pre-switch`, proven against the
* R5.1 ledger by the Rust suite `curation_draft`); every other file with the committed seed.
*/
const PRE_SWITCH = join(REPO_ROOT, 'crates/core/tests/fixtures/r5-6/pre-switch')
const FINGERPRINTED = new Set(['sheet-ref.json', 'report-migration-map.json'])
describe('committed draft folder (golden)', () => {
it('equals a fresh run for every produced file (rerun pnpm import:equine)', async () => {
it('equals a fresh run for every produced file (the two fingerprinted ones before R5.6)', async () => {
for (const [file, content] of Object.entries(draftFiles)) {
expect(await readFile(join(draftDir, file), 'utf8'), file).toBe(content)
const dir = FINGERPRINTED.has(file) ? PRE_SWITCH : draftDir
expect(await readFile(join(dir, file), 'utf8'), file).toBe(content)
}
})
+121
View File
@@ -0,0 +1,121 @@
/**
* R5.6 M1 (owner 2026-10-25) through the module and the frozen N-1 readers: an old PDF stamped
* with the registered historical value, re-exported on the switched sheet, gets its snapshot
* from the core (`archive.snapshot` on the sheet handle: the loaded sheet verified its `v1`
* value, recomputed now), carrying the report's own stamp; the N-1 scanner and Zod readers of
* the R3 build and 0.2.0 keep that snapshot and its content. On an unverified v0 sheet the
* core's snapshot carries the sheet's value and the export refuses the old report. The native
* side is `crates/core/tests/r5_6_switch.rs`.
*/
import { readFileSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { CoreRuntime } from '../src/index'
import { loadProofModule, nodeCoreSource } from '../src/node'
import { readArchiveDocument, ReportArchiveEnvelopeSchema } from './n-1'
import { ReportMigrationMapSchema } from './n-1/domain'
import { readAttachedDocument } from './n-1/scanner/attachment/read'
const ROOT = fileURLToPath(new URL('../../../', import.meta.url))
const SEED = join(ROOT, 'supabase/seed/anatomical-sheets/equine/draft')
const ALIAS = '27c7383c445c73dc2001ebf4794a3ea63d416910bbbaa0d7848dd720de7c2660'
const CANONICAL = '12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2'
const json = (path: string): unknown => JSON.parse(readFileSync(path, 'utf8'))
interface Envelope {
report: { sheet: { documentSha256: string } }
sheetSnapshot: { ref: { documentSha256: string }; document: unknown; assets: unknown }
branding: unknown
labels: unknown
locale: string
}
/** The bundle as `apps/app/vite/sheet-bundle.ts` builds it, with `ref` replaceable. */
function bundle(ref: unknown): string {
const manifest = json(join(SEED, 'assets.json')) as Array<{
file: string
sha256: string
svg_asset_id: string
}>
const assets: Record<string, string> = {}
const assetHashes: Record<string, string> = {}
for (const asset of manifest) {
assets[asset.svg_asset_id] = readFileSync(join(SEED, 'assets', asset.file), 'utf8')
assetHashes[asset.svg_asset_id] = asset.sha256
}
return JSON.stringify({
status: 'draft',
ref,
document: json(join(SEED, 'document.json')),
migrationMap: json(join(SEED, 'report-migration-map.json')),
assets,
assetHashes,
})
}
async function coreSnapshot(ref: unknown, report: unknown): Promise<Envelope['sheetSnapshot']> {
const runtime = new CoreRuntime(nodeCoreSource('pkg'))
expect(await runtime.ready()).toBe(true)
const outcome = runtime
.sheet(bundle(ref))
.call<Envelope['sheetSnapshot']>('archive.snapshot', JSON.stringify({ report }))
expect(outcome.ok).toBe(true)
return (outcome as { ok: true; value: Envelope['sheetSnapshot'] }).value
}
function exportInput(old: Envelope, snapshot: unknown): string {
return JSON.stringify({
report: old.report,
sheetSnapshot: snapshot,
branding: old.branding,
labels: old.labels,
locale: old.locale,
exportedAt: '2026-10-25T12:00:00.000Z',
})
}
async function oldEnvelope(): Promise<Envelope> {
const pdf = new Uint8Array(
readFileSync(join(ROOT, 'apps/app/tests/fixtures/pdf/r3/demo.fr.nologos.pdf')),
)
return (await readAttachedDocument(pdf)) as Envelope
}
describe('R5.6 re-export of an old archive, read by the N-1 readers', () => {
it('writes one stamp and the frozen readers keep the snapshot and its content', async () => {
const proofs = await loadProofModule()
const old = await oldEnvelope()
expect(old.report.sheet.documentSha256).toBe(ALIAS)
const ref = json(join(SEED, 'sheet-ref.json')) as { document_sha256: string }
expect(ref.document_sha256).toBe(CANONICAL)
const snapshot = await coreSnapshot(ref, old.report)
expect(snapshot.ref.documentSha256).toBe(ALIAS)
const written = (await readAttachedDocument(
proofs.export_pdf_for_test(exportInput(old, snapshot), JSON.stringify({ views: [] })),
)) as Envelope
expect(written.report.sheet.documentSha256).toBe(ALIAS)
expect(written.sheetSnapshot.ref.documentSha256).toBe(ALIAS)
expect(ReportArchiveEnvelopeSchema.safeParse(written).success).toBe(true)
const map = ReportMigrationMapSchema.parse(json(join(SEED, 'report-migration-map.json')))
const outcome = readArchiveDocument(written, map)
expect(outcome.snapshotRejected).toBeUndefined()
expect(outcome.archive).toBeDefined()
expect(written.sheetSnapshot.document).toEqual(old.sheetSnapshot.document)
expect(written.sheetSnapshot.assets).toEqual(old.sheetSnapshot.assets)
expect(written.labels).toEqual(old.labels)
expect(written.branding).toEqual(old.branding)
}, 60_000)
it('refuses the old report on an unverified v0 sheet carrying the canonical value', async () => {
const proofs = await loadProofModule()
const old = await oldEnvelope()
const v0 = json(join(SEED, 'sheet-ref.json')) as Record<string, unknown>
delete v0.fingerprint
const snapshot = await coreSnapshot(v0, old.report)
expect(snapshot.ref.documentSha256).toBe(CANONICAL)
expect(() =>
proofs.export_pdf_for_test(exportInput(old, snapshot), JSON.stringify({ views: [] })),
).toThrow(/sheet_mismatch/)
}, 60_000)
})
+73 -9
View File
@@ -22,25 +22,89 @@ const MAKE = process.env.MAKE_R2_ORACLES === '1'
const SEED = 'supabase/seed/anatomical-sheets/equine'
const CASES: Array<[string, string, z.ZodTypeAny]> = [
['sheet.draft.json', `${SEED}/draft/document.json`, AnatomicalSheetDocumentSchema],
['sheet.legacy-import.json', `${SEED}/legacy-import/document.json`, AnatomicalSheetDocumentSchema],
['migration-map.draft.json', `${SEED}/draft/report-migration-map.json`, ReportMigrationMapSchema],
['report-v3.demo.json', 'apps/app/tests/fixtures/report-v3.demo.json', ReportSchema],
['report-v2.full.json', 'apps/app/tests/fixtures/report-v2.full.json', ReportV2Schema],
['report-v2.minimal.json', 'apps/app/tests/fixtures/report-v2.minimal.json', ReportV2Schema],
[
'sheet.draft.json',
`${SEED}/draft/document.json`,
AnatomicalSheetDocumentSchema,
],
[
'sheet.legacy-import.json',
`${SEED}/legacy-import/document.json`,
AnatomicalSheetDocumentSchema,
],
[
'migration-map.draft.json',
`${SEED}/draft/report-migration-map.json`,
ReportMigrationMapSchema,
],
[
'report-v3.demo.json',
'apps/app/tests/fixtures/report-v3.demo.json',
ReportSchema,
],
[
'report-v2.full.json',
'apps/app/tests/fixtures/report-v2.full.json',
ReportV2Schema,
],
[
'report-v2.minimal.json',
'apps/app/tests/fixtures/report-v2.minimal.json',
ReportV2Schema,
],
]
/**
* Since R5.6 the committed migration map carries the `v1` fingerprint; the oracle was frozen on
* the pre-switch file, read here in that original context (`tests/fixtures/r5-6/pre-switch`,
* proven the same TypeScript output by the Rust suite `curation_draft`).
*/
const PRE_SWITCH: Record<string, string> = {
[`${SEED}/draft/report-migration-map.json`]:
'crates/core/tests/fixtures/r5-6/pre-switch/report-migration-map.json',
}
const ALIAS = '27c7383c445c73dc2001ebf4794a3ea63d416910bbbaa0d7848dd720de7c2660'
const CANONICAL =
'12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2'
describe('Zod output oracles of the R2 switch', () => {
it.each(CASES)('%s', (name, source, schema) => {
const input: unknown = JSON.parse(readFileSync(resolve(ROOT, source), 'utf8'))
const read = PRE_SWITCH[source] ?? source
const input: unknown = JSON.parse(readFileSync(resolve(ROOT, read), 'utf8'))
const text = JSON.stringify(schema.parse(input), null, 2)
const file = resolve(OUT, name)
if (MAKE) {
mkdirSync(OUT, { recursive: true })
writeFileSync(file, `${JSON.stringify({ source, output: JSON.parse(text) })}\n`)
writeFileSync(
file,
`${JSON.stringify({ source, output: JSON.parse(text) })}\n`,
)
}
const oracle = JSON.parse(readFileSync(file, 'utf8')) as {
source: string
output: unknown
}
const oracle = JSON.parse(readFileSync(file, 'utf8')) as { source: string; output: unknown }
expect(oracle.source).toBe(source)
expect(JSON.stringify(oracle.output, null, 2)).toBe(text)
})
})
describe('the committed migration map after R5.6', () => {
it('is the oracle with only the fingerprint moved to the canonical value', () => {
const source = `${SEED}/draft/report-migration-map.json`
const committed = ReportMigrationMapSchema.parse(
JSON.parse(readFileSync(resolve(ROOT, source), 'utf8')),
)
const oracle = JSON.parse(
readFileSync(resolve(OUT, 'migration-map.draft.json'), 'utf8'),
) as { output: { sheet: { documentSha256: string } } }
expect(oracle.output.sheet.documentSha256).toBe(ALIAS)
const expected = {
...oracle.output,
sheet: { ...oracle.output.sheet, documentSha256: CANONICAL },
}
expect(JSON.stringify(committed, null, 2)).toBe(
JSON.stringify(expected, null, 2),
)
})
})