blob: 38fbe40b508de3a7c7f0d007cda2465fc1a2b2be (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
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}");
}
|