Files
faunosteo/crates/core/tests/report_contract.rs
bchanot 0da7d3ab9f test(domain): R5.7 port the contracts only the TS suites checked
612 leaves and 26 legacy ids (curation_leaves), region inference, R5.1 ledger rows,
generated folder lists, migration-map oracle entry by entry, overlay removal, halo
filter, CHG-000 and dollar-tag refusals; report-v2 fixtures moved to crates/core/tests
(sha256 unchanged).
2026-10-25 03:59:49 +01:00

76 lines
3.2 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}");
}
}
/// `r2-oracles.test.ts` on `migration-map.draft.json` (R5.7): what Zod read from the map the
/// TypeScript wrote (the pre-switch copy) is what the core reads, entry by entry, nulls
/// included; the committed map since R5.6 differs only by the sheet fingerprint.
#[test]
fn the_draft_migration_map_reads_as_zod_read_it_entry_by_entry() {
let (_, oracle) = common::oracle_file("migration-map.draft.json");
let frozen: ReportMigrationMap = serde_json::from_value(oracle["output"].clone()).unwrap();
let pre_switch =
common::repo_file("crates/core/tests/fixtures/r5-6/pre-switch/report-migration-map.json");
let read: ReportMigrationMap =
serde_json::from_value(parse_json(&pre_switch).unwrap()).unwrap();
assert_eq!(read, frozen);
assert_eq!(
(
read.annotations.len(),
read.finding_paths.len(),
read.views.len()
),
(27, 792, 1)
);
let nulls = read.finding_paths.values().filter(|p| p.is_none()).count();
assert_eq!(nulls, 34);
let committed =
common::repo_file("supabase/seed/anatomical-sheets/equine/draft/report-migration-map.json");
let mut committed: ReportMigrationMap =
serde_json::from_value(parse_json(&committed).unwrap()).unwrap();
assert_eq!(
committed.sheet.document_sha256,
"12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2"
);
committed.sheet.document_sha256 = frozen.sheet.document_sha256.clone();
assert_eq!(committed, frozen);
}