feat(domain): R2.2 report migration, rebase, sheet snapshot and layered archive reading in Rust; draft restore and archive import operations
migrateReportV2ToV3 / readReportDocument (version read on the raw value, JS truthiness kept, a malformed mapped path still fails the read), rebaseReportOnSheet (??= labels, archived names first-match), buildSheetSnapshot / assertSnapshot (raw depth, shape, caps in UTF-16 and UTF-8, integrity), readArchiveDocument (layered: report first, wrapper, snapshot gate, sheet invariant, unsupported_envelope origin quirk). Checked against 84 cases frozen from the TypeScript and 765 Zod verdicts (one declared difference: L1, a lone surrogate reads as U+FFFD), the ported report and archive suites and the 612 legacy leaves. Facade: draft.restore (content kinds invalid / unsupported_version, rebase_failed never a content kind), archive.import (incompatible_version with found, no_attachment), archive.snapshot.
This commit is contained in:
1 parent
6c0533c1da
commit
21906c4358
28 files changed
+5239
-213
No files matched your search
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* The TypeScript types generated from the Rust contracts (ts-rs, `../types`) against the
|
||||
* output types of the Zod schemas they replace (the frozen N-1 copy): optional, nullable,
|
||||
* required and literal attributes, field by field. Checked by `tsc` (`pnpm typecheck`);
|
||||
* `expectTypeOf` is a no-op at run time.
|
||||
*/
|
||||
import { expectTypeOf } from 'vitest'
|
||||
import type { z } from 'zod'
|
||||
import type {
|
||||
BrandingSchema,
|
||||
FindingSchema,
|
||||
ObservationSchema,
|
||||
PdfLabelSetSchema,
|
||||
ReportArchiveEnvelopeSchema,
|
||||
ReportSchema,
|
||||
ReportZoneSchema,
|
||||
SheetRefSchema,
|
||||
SheetSnapshotSchema,
|
||||
} from './n-1/domain'
|
||||
import type {
|
||||
Branding,
|
||||
Finding,
|
||||
Observation,
|
||||
PdfLabelSet,
|
||||
Report,
|
||||
ReportArchiveEnvelope,
|
||||
ReportZone,
|
||||
SheetRef,
|
||||
SheetSnapshot,
|
||||
} from '../types'
|
||||
|
||||
describe('ts-rs contract types', () => {
|
||||
it('equal the Zod output types of the report', () => {
|
||||
expectTypeOf<Report>().toEqualTypeOf<z.output<typeof ReportSchema>>()
|
||||
expectTypeOf<Observation>().toEqualTypeOf<
|
||||
z.output<typeof ObservationSchema>
|
||||
>()
|
||||
expectTypeOf<ReportZone>().toEqualTypeOf<
|
||||
z.output<typeof ReportZoneSchema>
|
||||
>()
|
||||
expectTypeOf<Finding>().toEqualTypeOf<z.output<typeof FindingSchema>>()
|
||||
expectTypeOf<SheetRef>().toEqualTypeOf<z.output<typeof SheetRefSchema>>()
|
||||
})
|
||||
|
||||
it('equal the Zod output types of the archive parts', () => {
|
||||
expectTypeOf<Branding>().toEqualTypeOf<z.output<typeof BrandingSchema>>()
|
||||
expectTypeOf<PdfLabelSet>().toEqualTypeOf<
|
||||
z.output<typeof PdfLabelSetSchema>
|
||||
>()
|
||||
})
|
||||
|
||||
// The sheet document inside a snapshot is a union of one object per annotation kind in
|
||||
// Zod and one object with a `kind: 'point' | 'zone'` field in Rust: same values, another
|
||||
// form. The snapshot and the envelope are therefore checked for mutual assignability.
|
||||
it('are mutually assignable with the snapshot and the envelope', () => {
|
||||
type ZodSnapshot = z.output<typeof SheetSnapshotSchema>
|
||||
type ZodEnvelope = z.output<typeof ReportArchiveEnvelopeSchema>
|
||||
expectTypeOf<SheetSnapshot>().toMatchTypeOf<ZodSnapshot>()
|
||||
expectTypeOf<ZodSnapshot>().toMatchTypeOf<SheetSnapshot>()
|
||||
expectTypeOf<ReportArchiveEnvelope>().toMatchTypeOf<ZodEnvelope>()
|
||||
expectTypeOf<ZodEnvelope>().toMatchTypeOf<ReportArchiveEnvelope>()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user