use super::{SiteIndex, expand};
use std::{fs, path::Path};
fn project(root: &Path) {
let definitions = root.join(".artifactize");
fs::create_dir(&definitions).unwrap();
fs::write(root.join("module.md"), "# Module\n").unwrap();
for (file, text) in [
(
"module.artf",
"artf module = reviewed!(file = \"module.md\")",
),
("tools.artf", "tool local = markdown"),
(
"profiles.artfprofiles",
"profile readers : agent = { backend = \"codex\" model = \"fixture\" }",
),
(
"macro.artf",
r#"artf! reviewed(file) : local = {
path = "@{param file}"
eval review : readers = { title = "Read the module" instruction = "Review @{artf self}." }
}"#,
),
(
"elsewhere.artf",
"artf elsewhere = { path = \"elsewhere.md\" basis = true }",
),
] {
fs::write(definitions.join(file), text).unwrap();
}
}
#[test]
fn indexed_source_resolves_its_macro_toolset_and_profile_without_opening_other_files() {
let repo = crate::test_os::tempdir();
project(repo.path());
let sites = SiteIndex::read(repo.path()).unwrap();
fs::write(repo.path().join(".artifactize/elsewhere.artf"), "?").unwrap();
let source = expand::indexed(repo.path(), &sites, &"module".parse().unwrap()).unwrap();
assert_eq!(source.macro_name.as_deref(), Some("reviewed!"));
assert_eq!(source.evals[0].file, Path::new(".artifactize/macro.artf"));
assert!(
source.expanded.contains("Read the module"),
"{}",
source.expanded
);
}
#[test]
fn a_moved_macro_uses_discovery_when_the_recorded_scope_can_no_longer_answer() {
let repo = crate::test_os::tempdir();
project(repo.path());
let sites = SiteIndex::read(repo.path()).unwrap();
fs::rename(
repo.path().join(".artifactize/macro.artf"),
repo.path().join(".artifactize/moved.artf"),
)
.unwrap();
let source = expand::indexed(repo.path(), &sites, &"module".parse().unwrap()).unwrap();
assert_eq!(source.evals[0].file, Path::new(".artifactize/moved.artf"));
}