use super::*;
use crate::git_tree::tests::fixture::Fixture;
use crate::model_pick::BRANCH;
use crate::test_support::TEMPLATE_PROVIDERS;
#[test]
fn the_worker_gains_clients_and_authoring_is_a_fixed_point() {
let once = authored(TEMPLATE_PROVIDERS);
assert_ne!(once, TEMPLATE_PROVIDERS, "the shipped template drifts");
let granted = entry_field(&once, ROLES, WORKER_ROLE, TOOLS)
.and_then(|v| flow_members(&v))
.expect("the worker's grant");
assert!(granted.iter().any(|n| n == clients::NAME), "{granted:?}");
for shipped in ["apply_patch", "bash", "dispatch", "read_file"] {
assert!(granted.iter().any(|n| n == shipped), "{granted:?}");
}
assert_eq!(authored(&once), once, "the fixed point");
}
#[test]
fn the_checkpoint_roles_are_left_exactly_as_they_were() {
let once = authored(TEMPLATE_PROVIDERS);
assert_eq!(entry_field(&once, ROLES, "compactor", TOOLS), None);
assert_eq!(
entry_field(&once, ROLES, "reviewer", TOOLS),
entry_field(TEMPLATE_PROVIDERS, ROLES, "reviewer", TOOLS),
);
}
#[test]
fn a_file_this_has_nothing_to_say_about_is_unchanged() {
for base in [
"",
"roles:\n worker:\n provider: anthropic\n model: m\n",
"roles:\n worker:\n provider: anthropic\n model: m\n tools:\n - bash\n",
"roles:\n compactor:\n provider: anthropic\n model: m\n",
] {
assert_eq!(authored(base), base, "{base:?}");
}
}
fn staged(fixture: &Fixture) -> Vec<String> {
drift(&fixture.path, BRANCH)
.into_iter()
.map(|d| d.rel_path)
.collect()
}
#[test]
fn the_grant_and_the_description_it_is_worthless_without_move_together() {
let fixture = Fixture::new();
fixture.commit_other(PROVIDERS_YAML, TEMPLATE_PROVIDERS);
assert_eq!(staged(&fixture), [PROVIDERS_YAML, SCHEMA_PATH]);
fixture.commit_other(PROVIDERS_YAML, &authored(TEMPLATE_PROVIDERS));
assert_eq!(staged(&fixture), [SCHEMA_PATH]);
fixture.commit_other(SCHEMA_PATH, &described());
assert!(staged(&fixture).is_empty());
}
#[test]
fn the_description_is_the_declared_schema_verbatim() {
let said: serde_json::Value = serde_json::from_str(&described()).expect("valid JSON");
assert_eq!(said, clients::schema());
assert!(described().ends_with('\n'));
}
#[test]
fn no_grant_means_no_description_and_no_lineage_means_neither() {
let fixture = Fixture::new();
fixture.commit_other(
PROVIDERS_YAML,
"roles:\n worker:\n provider: anthropic\n model: m\n",
);
assert!(staged(&fixture).is_empty());
assert!(drift(&Fixture::new().path, BRANCH).is_empty());
}