Files
faunosteo/crates/core/tests/report_contract.rs
T
bchanot ee0700887f feat(domain): R2.1 Rust contracts of the sheet, report and archive documents
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.
2026-10-14 00:04:01 +02:00

42 lines
1.7 KiB
Rust

//! Report contracts against the Zod oracles.
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
mod common;
use faunosteo_core::domain::js::parse_json;
use faunosteo_core::domain::report::v2::ReportV2;
use faunosteo_core::domain::report::{Report, ReportMigrationMap};
use faunosteo_core::json::to_js_pretty;
#[test]
fn the_demo_report_prints_as_zod_outputs_it() {
let (source, expected) = common::zod_oracle("report-v3.demo.json");
let report: Report = serde_json::from_value(parse_json(&source).unwrap()).unwrap();
assert_eq!(to_js_pretty(&report).unwrap(), expected);
}
#[test]
fn the_v2_fixtures_and_the_migration_map_parse() {
for name in ["report-v2.full.json", "report-v2.minimal.json"] {
let (source, _) = common::zod_oracle(name);
let parsed: Result<ReportV2, _> = serde_json::from_value(parse_json(&source).unwrap());
assert!(parsed.is_ok(), "{name}: {parsed:?}");
}
let (source, _) = common::zod_oracle("migration-map.draft.json");
let map: ReportMigrationMap = serde_json::from_value(parse_json(&source).unwrap()).unwrap();
assert!(map.annotations.len() > 20 && map.finding_paths.len() > 600);
}
#[test]
fn the_frozen_envelopes_parse_and_print_as_their_attachment() {
use faunosteo_core::domain::archive::ReportArchiveEnvelope;
for name in ["demo", "v2full", "v2unresolved"] {
let text = common::repo_file(&format!(
"apps/app/tests/fixtures/goldens/r2/envelope.{name}.fr.nologos.json"
));
let envelope: ReportArchiveEnvelope =
serde_json::from_value(parse_json(&text).unwrap()).unwrap();
assert_eq!(to_js_pretty(&envelope).unwrap(), text, "{name}");
}
}