summaryrefslogtreecommitdiffstats
path: root/tests/prompt.rs
blob: 97a3fa93a16731705b8c7ae6883e6f524b34b7ac (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
42
43
44
45
46
47
48
/*
 * This file is part of agent686
 * Copyright (C) 2026 Salmonik <salmon@2137697.xyz>
 * 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}");
}