use super::{TEMPLATE_PROVIDERS, rows_on, table};
use crate::config_edit::brazen::ProviderRow;
use crate::model_pick::{Pick, PickError, WORKER_ROLE, plan};
fn pick(provider: &str) -> Pick {
Pick {
role: WORKER_ROLE.to_string(),
provider: provider.to_string(),
model: "sonnet".to_string(),
}
}
fn refuse(rows: &[ProviderRow], provider: &str) -> PickError {
plan(TEMPLATE_PROVIDERS, rows, &pick(provider)).expect_err("the row cannot serve a role")
}
#[test]
fn a_pick_on_a_tool_less_protocol_is_refused_before_the_file_is_touched() {
let rows = rows_on(&["claude-code"], "claude_code");
let refused = refuse(&rows, "claude-code");
assert_eq!(
refused,
PickError::Incapable {
provider: "claude-code".to_string(),
why: rows[0].tools_blocked().expect("the dialect declines tools"),
}
);
let said = refused.to_string();
assert!(said.contains("`claude-code` cannot serve a role"), "{said}");
assert!(said.contains("claude_code declares no tools"), "{said}");
assert!(said.contains("`clients` tool"), "{said}");
assert!(said.contains("pick a tool-capable row"), "{said}");
}
#[test]
fn a_row_the_table_does_not_carry_is_unknown_not_incapable() {
assert_eq!(
refuse(&rows_on(&["claude-code"], "claude_code"), "nope"),
PickError::UnknownProvider {
provider: "nope".to_string(),
}
);
}
#[test]
fn an_unanswerable_table_and_a_capable_row_both_pass() {
assert!(plan(TEMPLATE_PROVIDERS, &[], &pick("claude-code")).is_ok());
assert!(plan(TEMPLATE_PROVIDERS, &table(&["codex"]), &pick("codex")).is_ok());
}
#[test]
fn a_dialect_that_leaves_the_context_to_the_server_is_not_refused() {
let rows = rows_on(&["local"], "ollama_chat");
assert_eq!(rows[0].tools_blocked(), None, "the tools read is the gate");
assert!(plan(TEMPLATE_PROVIDERS, &rows, &pick("local")).is_ok());
}
#[test]
fn neither_a_custom_id_nor_an_empty_role_tool_list_earns_an_exemption() {
let rows = rows_on(&["claude-code"], "claude_code");
let mut custom = pick("claude-code");
custom.model = "some-unlisted-preview".to_string();
assert!(matches!(
plan(TEMPLATE_PROVIDERS, &rows, &custom),
Err(PickError::Incapable { .. })
));
let mut bare_role = pick("claude-code");
bare_role.role = "compactor".to_string();
assert!(matches!(
plan(TEMPLATE_PROVIDERS, &rows, &bare_role),
Err(PickError::Incapable { .. })
));
}