Files
2026-05-16 15:59:57 -04:00

66 lines
2.1 KiB
Rust

//! Docs-sync guard for the terrain-generation surface.
//!
//! The terrain generator has landed in `src/terrain_gen.rs` (see
//! `tests/terrain_gen.rs`), but the docs have not been updated to describe it.
//! This test fails by design until README, the terrain-generation plan, and
//! the architecture notes mention the new surface.
use std::fs;
use std::path::Path;
/// Substrings every terrain-aware doc should mention now that the
/// terrain-generation module has landed.
const REQUIRED_TERMS: &[&str] = &[
"src/terrain_gen.rs",
"TerrainGenerationSpec",
"DeterministicTerrainGenerator",
"cargo test terrain_gen",
];
fn read_doc(relative: &str) -> String {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join(relative);
fs::read_to_string(&path).unwrap_or_else(|e| panic!("failed to read {}: {e}", path.display()))
}
/// Returns the required terrain-generation terms that `doc` fails to mention.
fn missing_terms(doc: &str) -> Vec<&'static str> {
let mut missing: Vec<&'static str> = REQUIRED_TERMS
.iter()
.copied()
.filter(|term| !doc.contains(term))
.collect();
// A determinism/seed note: the docs should say generation is seeded and
// reproducible, not just reuse the word "deterministic" elsewhere.
let lower = doc.to_lowercase();
if !(lower.contains("seed") && lower.contains("determin")) {
missing.push("a determinism/seed note");
}
missing
}
fn assert_doc_mentions_terrain_gen(relative: &str) {
let doc = read_doc(relative);
let missing = missing_terms(&doc);
assert!(
missing.is_empty(),
"{relative} does not mention the landed terrain-generation surface: {missing:?}"
);
}
#[test]
fn readme_mentions_terrain_generation_surface() {
assert_doc_mentions_terrain_gen("README.md");
}
#[test]
fn terrain_generation_plan_mentions_terrain_generation_surface() {
assert_doc_mentions_terrain_gen("docs/plans/terrain-generation.md");
}
#[test]
fn architecture_notes_mention_terrain_generation_surface() {
assert_doc_mentions_terrain_gen("docs/knowledgebase/architecture-notes.md");
}