aboutsummaryrefslogtreecommitdiffstats
path: root/tests/prompt.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/prompt.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/prompt.rs b/tests/prompt.rs
new file mode 100644
index 0000000..38fbe40
--- /dev/null
+++ b/tests/prompt.rs
@@ -0,0 +1,41 @@
1use std::fs;
2use std::path::PathBuf;
3
4use agent686::agent;
5
6fn temp_dir(tag: &str) -> PathBuf {
7 let dir = std::env::temp_dir().join(format!("agent686-prompt-{tag}-{}", std::process::id()));
8 let _ = fs::remove_dir_all(&dir);
9 fs::create_dir_all(&dir).unwrap();
10 dir
11}
12
13#[test]
14fn project_instructions_stop_at_the_git_root() {
15 let dir = temp_dir("scope");
16 let repo = dir.join("repo");
17 fs::create_dir_all(repo.join("src")).unwrap();
18 fs::create_dir_all(repo.join(".git")).unwrap();
19 fs::write(dir.join("AGENTS.md"), "OUTSIDE THE REPO").unwrap();
20 fs::write(repo.join("AGENTS.md"), "INSIDE THE REPO").unwrap();
21
22 let prompt = agent::system_prompt_for(&repo.join("src"));
23 let text = prompt["content"].as_str().unwrap();
24
25 assert!(text.contains("INSIDE THE REPO"), "{text}");
26 assert!(
27 !text.contains("OUTSIDE THE REPO"),
28 "a parent AGENTS.md above the git root must not be injected"
29 );
30}
31
32#[test]
33fn outside_a_repository_only_the_current_directory_is_read() {
34 let dir = temp_dir("norepo");
35 fs::create_dir_all(dir.join("work")).unwrap();
36 fs::write(dir.join("AGENTS.md"), "PARENT INSTRUCTIONS").unwrap();
37
38 let prompt = agent::system_prompt_for(&dir.join("work"));
39 let text = prompt["content"].as_str().unwrap();
40 assert!(!text.contains("PARENT INSTRUCTIONS"), "{text}");
41}