/* * This file is part of agent686 * Copyright (C) 2026 Salmonik * SPDX-License-Identifier: GPL-3.0-or-later * https://git.2137697.xyz/agent686 */ use std::fs; use std::path::PathBuf; use agent686::agent; fn temp_dir(tag: &str) -> PathBuf { let dir = std::env::temp_dir().join(format!("agent686-prompt-{tag}-{}", std::process::id())); let _ = fs::remove_dir_all(&dir); fs::create_dir_all(&dir).unwrap(); dir } #[test] fn project_instructions_stop_at_the_git_root() { let dir = temp_dir("scope"); let repo = dir.join("repo"); fs::create_dir_all(repo.join("src")).unwrap(); fs::create_dir_all(repo.join(".git")).unwrap(); fs::write(dir.join("AGENTS.md"), "OUTSIDE THE REPO").unwrap(); fs::write(repo.join("AGENTS.md"), "INSIDE THE REPO").unwrap(); let prompt = agent::system_prompt_for(&repo.join("src")); let text = prompt["content"].as_str().unwrap(); assert!(text.contains("INSIDE THE REPO"), "{text}"); assert!( !text.contains("OUTSIDE THE REPO"), "a parent AGENTS.md above the git root must not be injected" ); } #[test] fn outside_a_repository_only_the_current_directory_is_read() { let dir = temp_dir("norepo"); fs::create_dir_all(dir.join("work")).unwrap(); fs::write(dir.join("AGENTS.md"), "PARENT INSTRUCTIONS").unwrap(); let prompt = agent::system_prompt_for(&dir.join("work")); let text = prompt["content"].as_str().unwrap(); assert!(!text.contains("PARENT INSTRUCTIONS"), "{text}"); }