use super::super::super::{Decided, run};
use super::super::{argv, said};
use crate::cli::verdict::REFUSED;
#[test]
fn the_start_word_carries_a_workspace_and_a_goal() {
let Decided::Start { address, goal, .. } = run(argv(&["start", "home", "do the thing"])) else {
panic!("`start` begins a conversation");
};
assert_eq!(address, "home");
assert_eq!(goal, "do the thing");
}
#[test]
fn the_enrollment_carries_the_destination_it_was_given() {
let Decided::Enroll { into, asking, .. } = run(argv(&[
"enroll",
"ops",
"box-1",
"foot",
crate::cli::INTO,
"/home/u/carry",
])) else {
panic!("`enroll` with a destination is still an enrollment");
};
assert_eq!(into.as_deref(), Some("/home/u/carry"));
assert_eq!(asking.grade, "foot");
}
#[test]
fn the_enrollment_carries_the_route_the_new_box_will_dial() {
let Decided::Enroll { asking, into, .. } = run(argv(&[
"enroll",
"ops",
"alpha2",
"foot",
crate::cli::AT,
"host.containers.internal:7773",
])) else {
panic!("`enroll` with a route is still an enrollment");
};
assert_eq!(asking.at.as_deref(), Some("host.containers.internal:7773"));
assert_eq!(into, None, "the route says nothing about writing files");
}
#[test]
fn the_two_optional_words_are_independent_and_unordered() {
for tail in [
vec![
"enroll",
"ops",
"alpha2",
"foot",
crate::cli::AT,
"alias:7773",
crate::cli::INTO,
"/home/u/carry",
],
vec![
"enroll",
"ops",
"alpha2",
"foot",
crate::cli::INTO,
"/home/u/carry",
crate::cli::AT,
"alias:7773",
],
] {
let Decided::Enroll { asking, into, .. } = run(argv(&tail)) else {
panic!("{tail:?} is an enrollment");
};
assert_eq!(
(asking.at.as_deref(), into.as_deref()),
(Some("alias:7773"), Some("/home/u/carry")),
"{tail:?}"
);
}
}
#[test]
fn a_tail_that_is_not_the_two_words_refuses_and_names_them() {
for tail in [
vec!["enroll", "ops", "box-1", "foot", "/home/u/carry"],
vec!["enroll", "ops", "box-1", "foot", "--out", "/home/u/carry"],
vec!["enroll", "ops", "box-1", "foot", crate::cli::INTO],
vec!["enroll", "ops", "box-1", "foot", crate::cli::AT],
vec![
"enroll",
"ops",
"box-1",
"foot",
crate::cli::INTO,
"/home/u/carry",
"extra",
],
vec![
"enroll",
"ops",
"box-1",
"foot",
crate::cli::AT,
"alias:7773",
crate::cli::AT,
"other:7773",
],
vec![
"enroll",
"ops",
"box-1",
"foot",
crate::cli::INTO,
"/home/u/carry",
crate::cli::INTO,
"/home/u/again",
],
] {
let refused = said(&tail);
assert_eq!(refused.code, REFUSED, "{tail:?}");
for word in [crate::cli::AT, crate::cli::INTO] {
assert!(refused.text.contains(word), "{tail:?}: {}", refused.text);
}
}
}
#[test]
fn a_third_word_aims_the_start_at_a_directory() {
let Decided::Start {
address, goal, dir, ..
} = run(argv(&["start", "home", "do the thing", "/work/repo"]))
else {
panic!("a start with a work target");
};
assert_eq!(
(address, goal, dir),
(
"home".to_owned(),
"do the thing".to_owned(),
Some("/work/repo".to_owned())
)
);
let Decided::Start { dir: None, .. } = run(argv(&["start", "home", "do the thing"])) else {
panic!("two words is the bare rung");
};
}
#[test]
fn the_model_word_carries_the_four_it_assigns() {
let Decided::Model {
workspace,
role,
provider,
model,
..
} = run(argv(&["model", "home", "worker", "codex", "gpt-5.4"]))
else {
panic!("`model` checks before it assigns");
};
assert_eq!(
(workspace, role, provider, model),
(
"home".to_owned(),
"worker".to_owned(),
"codex".to_owned(),
"gpt-5.4".to_owned()
)
);
let refused = said(&["model", "home", "worker"]);
assert_eq!(refused.code, REFUSED);
assert!(
refused
.text
.contains("lernie model <workspace> <role> <provider> <model>"),
"{}",
refused.text
);
}