From 69c199cc73ca1b429b2554bfccb919e4fc6664cc Mon Sep 17 00:00:00 2001 From: BLC Core Studio <207100624+BLCCoreStudio@users.noreply.github.com> Date: Sat, 3 Oct 2026 02:15:34 +0300 Subject: [PATCH] test: cover relative target normalization --- tests/target_normalization.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/target_normalization.rs diff --git a/tests/target_normalization.rs b/tests/target_normalization.rs new file mode 100644 index 0000000..933c4cc --- /dev/null +++ b/tests/target_normalization.rs @@ -0,0 +1,32 @@ +use agentcontextmap::analyze; +use std::fs; +use std::path::Path; + +#[test] +fn normalizes_safe_parent_components_inside_repository() { + let root = tempfile_root(); + fs::create_dir_all(root.join("src")).unwrap(); + fs::write(root.join("AGENTS.md"), "Always run tests.\n").unwrap(); + fs::write(root.join("README.md"), "hello\n").unwrap(); + + let analysis = analyze(&root, Some(Path::new("src/../README.md"))).unwrap(); + + assert_eq!(analysis.target.as_deref(), Some(Path::new("README.md"))); + assert_eq!(analysis.sources.len(), 1); + + let _ = fs::remove_dir_all(root); +} + +fn tempfile_root() -> std::path::PathBuf { + use std::time::{SystemTime, UNIX_EPOCH}; + let nonce = SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("clock should be after Unix epoch") + .as_nanos(); + let root = std::env::temp_dir().join(format!( + "agentcontext-target-normalization-{}-{nonce}", + std::process::id() + )); + fs::create_dir_all(&root).unwrap(); + root +}