use super::*;
use std::fs;
fn plans(current: &Current) -> Vec<(String, Plan)> {
current
.artifacts
.iter()
.map(|artifact| (artifact.name.to_string(), artifact.plan))
.collect()
}
fn edges(current: &Current) -> Vec<(String, String)> {
current
.edges
.iter()
.map(|edge| (edge.from.to_string(), edge.to.to_string()))
.collect()
}
#[tokio::test]
async fn declarations_draw_the_graph_before_an_explicit_status_check() {
let repo = crate::test_os::tempdir();
let state = crate::test_os::tempdir();
for (folder, declaration) in [
(
"notes",
"name = 'notes'\nfingerprint = { files = ['.'] }\n[evals.read]\ntitle = 'Read the notes'\nprofile = { kind = 'human' }\npayload = { instruction = 'Read them.' }\n",
),
(
"app",
"name = 'app'\nfingerprint = { files = ['.'] }\n[evals.review]\ntitle = 'Review the app'\nprofile = { kind = 'human' }\npayload = { instruction = 'Review it with {notes}.' }\n",
),
] {
fs::create_dir(repo.path().join(folder)).unwrap();
crate::test_declaration::write(
repo.path(),
repo.path().join(folder).join("index.artf"),
declaration,
)
.unwrap();
}
let first = outline(repo.path()).unwrap();
assert_eq!(
plans(&first),
[
("app".into(), Plan::Unchecked),
("notes".into(), Plan::Unchecked)
]
);
assert!(first.scanned_at.is_none());
assert_eq!(edges(&first), [("notes".into(), "app".into())]);
let mut counts = Vec::new();
let current = scan_scope(
repo.path(),
state.path(),
&Selection::All,
None,
CancellationToken::new(),
|left| counts.push(left),
)
.await
.unwrap();
assert_eq!(counts, [2, 1, 0]);
assert_eq!(
plans(¤t),
[("app".into(), Plan::Run), ("notes".into(), Plan::Run)]
);
assert!(current.scanned_at.is_some());
assert!(first.same_shape(¤t));
let review = ¤t
.artifacts
.iter()
.find(|artifact| artifact.name == "app")
.unwrap()
.evals[0]
.card
.instruction;
assert_eq!(
review.parts,
[
crate::scope::InstructionPart::Text("Review it with ".into()),
crate::scope::InstructionPart::Artifact("notes".parse().unwrap()),
crate::scope::InstructionPart::Text(".".into()),
]
);
assert_eq!(
review.paths.get("notes").map(String::as_str),
Some("notes/")
);
}
#[tokio::test]
async fn a_whole_holds_its_parts_without_edges_to_them_and_does_what_they_do() {
let repo = crate::test_os::tempdir();
let state = crate::test_os::tempdir();
for (folder, declaration) in [
("kit", "name = 'kit'\nparts = ['core', 'notes']\n"),
(
"kit/core",
"name = 'core'\nfingerprint = { files = ['.'] }\n[evals.review]\ntitle = 'Review the core'\nprofile = { kind = 'human' }\npayload = { instruction = 'Review it.' }\n",
),
("notes", "name = 'notes'\nbasis = true\n"),
] {
fs::create_dir_all(repo.path().join(folder)).unwrap();
crate::test_declaration::write(
repo.path(),
repo.path().join(folder).join("index.artf"),
declaration,
)
.unwrap();
}
let current = scan_scope(
repo.path(),
state.path(),
&Selection::All,
None,
CancellationToken::new(),
|_| {},
)
.await
.unwrap();
let kit = current
.artifacts
.iter()
.find(|artifact| artifact.name.as_str() == "kit")
.unwrap();
assert_eq!(
kit.parts
.iter()
.map(|part| part.as_str())
.collect::<Vec<_>>(),
["core", "notes"]
);
assert!(edges(¤t).is_empty());
assert_eq!(kit.plan, Plan::Run);
assert_eq!(kit.text(), "would run");
}