Sheet document v2, report v3 / v2 / identity, migration map, sheet snapshot, branding, PDF labels and archive envelope ported from the Zod schemas with their exact semantics: strict objects where Zod is strict, optional fields absent (never null), nullable fields required, integers as JavaScript numbers, UTF-16 caps, hand-checked patterns, url crate for .url(), lone surrogate escapes read as U+FFFD (L1, owner confirmation pending). Fields in Zod schema order (PDF labels in the engine dictionary order): the curated and legacy sheets, the demo report and the three frozen archive envelopes print byte for byte as their Zod / attachment form. ts-rs types regenerated; plan rev 2 after three plan challenges.
47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
/**
|
|
* R2 freeze (RUST_ARCHITECTURE_REVIEW VI.1): what the Zod schemas output for the reference
|
|
* documents, written once as `JSON.stringify(Schema.parse(x), null, 2)` under
|
|
* crates/core/tests/oracles so the Rust contracts are checked byte for byte against the
|
|
* TypeScript they replace. `MAKE_R2_ORACLES=1` writes them; otherwise they are asserted.
|
|
*/
|
|
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
import { dirname, resolve } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { describe, expect, it } from 'vitest'
|
|
import type { z } from 'zod'
|
|
import {
|
|
AnatomicalSheetDocumentSchema,
|
|
ReportMigrationMapSchema,
|
|
ReportSchema,
|
|
ReportV2Schema,
|
|
} from '../src'
|
|
|
|
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '../../..')
|
|
const OUT = resolve(ROOT, 'crates/core/tests/oracles')
|
|
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],
|
|
]
|
|
|
|
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 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`)
|
|
}
|
|
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)
|
|
})
|
|
})
|