//! Validation of the four `ContextInjection` variants (ARCHITECTURE ยง3.2). use domain::{ContextInjection, DomainError}; // --- ConventionFile ------------------------------------------------------- #[test] fn convention_file_relative_ok() { let ci = ContextInjection::convention_file("CLAUDE.md").unwrap(); assert!(matches!(ci, ContextInjection::ConventionFile { target } if target == "CLAUDE.md")); } #[test] fn convention_file_nested_relative_ok() { assert!(ContextInjection::convention_file("docs/AGENTS.md").is_ok()); } #[test] fn convention_file_rejects_absolute() { assert!(matches!( ContextInjection::convention_file("/etc/CLAUDE.md").unwrap_err(), DomainError::PathNotRelativeSafe { .. } )); } #[test] fn convention_file_rejects_dotdot() { assert!(matches!( ContextInjection::convention_file("../CLAUDE.md").unwrap_err(), DomainError::PathNotRelativeSafe { .. } )); } #[test] fn convention_file_rejects_windows_drive() { assert!(matches!( ContextInjection::convention_file("C:\\CLAUDE.md").unwrap_err(), DomainError::PathNotRelativeSafe { .. } )); } // --- Flag ----------------------------------------------------------------- #[test] fn flag_non_empty_ok() { let ci = ContextInjection::flag("--context-file {path}").unwrap(); assert!(matches!(ci, ContextInjection::Flag { flag } if flag == "--context-file {path}")); } #[test] fn flag_rejects_empty() { assert!(matches!( ContextInjection::flag("").unwrap_err(), DomainError::EmptyField { .. } )); assert!(matches!( ContextInjection::flag(" ").unwrap_err(), DomainError::EmptyField { .. } )); } // --- Stdin ---------------------------------------------------------------- #[test] fn stdin_variant() { assert_eq!(ContextInjection::stdin(), ContextInjection::Stdin); } // --- Env ------------------------------------------------------------------ #[test] fn env_valid_identifier_ok() { assert!(ContextInjection::env("AGENT_CONTEXT_FILE").is_ok()); assert!(ContextInjection::env("_private").is_ok()); assert!(ContextInjection::env("X1").is_ok()); } #[test] fn env_rejects_leading_digit() { assert!(matches!( ContextInjection::env("1BAD").unwrap_err(), DomainError::InvalidEnvVar { .. } )); } #[test] fn env_rejects_invalid_chars() { assert!(matches!( ContextInjection::env("BAD-VAR").unwrap_err(), DomainError::InvalidEnvVar { .. } )); assert!(matches!( ContextInjection::env("HAS SPACE").unwrap_err(), DomainError::InvalidEnvVar { .. } )); } #[test] fn env_rejects_empty() { assert!(matches!( ContextInjection::env("").unwrap_err(), DomainError::InvalidEnvVar { .. } )); }