use std::path::PathBuf;
fn schema_path() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../docs/graph-schema.json")
}
fn generate() -> String {
let schema = salvor_graph::graph_schema();
let mut json = serde_json::to_string_pretty(&schema).expect("schema serializes");
json.push('\n');
json
}
#[test]
fn graph_schema_matches_the_checked_in_copy() {
let generated = generate();
if std::env::var_os("UPDATE_GRAPH_SCHEMA").is_some() {
std::fs::write(schema_path(), &generated).expect("writing docs/graph-schema.json");
return;
}
let checked_in = std::fs::read_to_string(schema_path()).expect(
"docs/graph-schema.json should exist; create it with `UPDATE_GRAPH_SCHEMA=1 cargo test \
-p salvor-graph --test graph_schema`",
);
assert_eq!(
generated, checked_in,
"docs/graph-schema.json is stale: it no longer matches the Graph types in src/document.rs. \
Regenerate it with `UPDATE_GRAPH_SCHEMA=1 cargo test -p salvor-graph --test graph_schema` \
and commit the result."
);
}
#[test]
fn graph_schema_generation_is_deterministic() {
assert_eq!(
generate(),
generate(),
"regenerating twice must produce byte-identical output"
);
}