#![allow(clippy::expect_used)] #![doc = "Published schema, registry, and reviewed-fixture parity tests."] use std::{collections::BTreeSet, fs, path::PathBuf}; use ghidra_cli::{ error::ErrorEnvelope, operation::{ CleanupData, DecompilationData, DoctorData, FunctionsData, InspectionData, OPERATIONS, QueryProvenance, SuccessEnvelope, ToolProvenance, }, }; fn root(relative: &str) -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(relative) } fn fixture(name: &str) -> String { fs::read_to_string(root(&format!("fixtures/golden/v1/{name}"))).expect("read fixture") } #[test] fn registry_has_exact_schema_and_golden_coverage() { let mut operations = BTreeSet::new(); for descriptor in OPERATIONS { assert!(operations.insert(descriptor.operation.as_str())); assert!(root(&format!("schemas/v1/{}", descriptor.schema)).is_file()); assert!(root(&format!("fixtures/golden/v1/{}", descriptor.golden)).is_file()); let value: serde_json::Value = serde_json::from_str(&fixture(descriptor.golden)).expect("fixture JSON"); assert_eq!(value["kind"], descriptor.public_kind); } assert_eq!( operations, BTreeSet::from(["clean", "decompile", "doctor", "functions", "inspect"]) ); } #[test] fn reviewed_goldens_deserialize_through_public_contracts() { serde_json::from_str::>(&fixture("doctor.json")) .expect("doctor contract"); serde_json::from_str::>(&fixture( "inspection.json", )) .expect("inspection contract"); serde_json::from_str::>(&fixture( "functions.json", )) .expect("functions contract"); serde_json::from_str::>(&fixture( "decompilation.json", )) .expect("decompilation contract"); serde_json::from_str::>(&fixture("cleanup.json")) .expect("cleanup contract"); serde_json::from_str::(&fixture("error.json")).expect("error contract"); }