use clap::Parser;
use crate::cli::{Cli, Command, SessionAction};
#[test]
fn cli_parses_session_new() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"session",
"new",
"https://github.com/owner/repo",
"--git-ref",
"feat/x",
"--task",
"do the thing",
"--name-hint",
"ticket-1",
])
.unwrap();
match cli.command.unwrap() {
Command::Session {
action:
SessionAction::New {
repo,
git_ref,
task,
name_hint,
runtime,
},
} => {
assert_eq!(repo, "https://github.com/owner/repo");
assert_eq!(git_ref, "feat/x");
assert_eq!(task, "do the thing");
assert_eq!(name_hint.as_deref(), Some("ticket-1"));
assert_eq!(runtime, trusty_mpm::runtime::RuntimeKind::ClaudeCode);
}
other => panic!("expected session new, got {other:?}"),
}
}
#[test]
fn cli_parses_session_new_with_tcode_runtime() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"session",
"new",
"https://github.com/owner/repo",
"--task",
"do the thing",
"--runtime",
"tcode",
])
.unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::New { runtime, .. },
} => {
assert_eq!(runtime, trusty_mpm::runtime::RuntimeKind::Tcode);
}
other => panic!("expected session new, got {other:?}"),
}
}
#[test]
fn cli_rejects_unknown_runtime_at_parse_time() {
let err = Cli::try_parse_from([
"trusty-mpm",
"session",
"new",
"https://github.com/owner/repo",
"--task",
"do the thing",
"--runtime",
"gpt",
])
.expect_err("unknown runtime must be rejected at parse time");
let msg = err.to_string();
assert!(
msg.contains("claude-code") && msg.contains("tcode"),
"error must list the supported runtimes: {msg}"
);
}
#[test]
fn cli_parses_session_ls() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "ls", "--json"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Ls { json, .. },
} => assert!(json),
other => panic!("expected session ls, got {other:?}"),
}
}
#[test]
fn cli_parses_session_ls_source_id() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "ls", "--source-id", "myorg/myrepo"])
.unwrap();
match cli.command.unwrap() {
Command::Session {
action:
SessionAction::Ls {
source_id,
current,
json,
all,
},
} => {
assert_eq!(source_id, Some("myorg/myrepo".to_string()));
assert!(!current);
assert!(!json);
assert!(!all, "--all must default to false");
}
other => panic!("expected session ls, got {other:?}"),
}
}
#[test]
fn cli_parses_session_ls_current() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "ls", "--current"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action:
SessionAction::Ls {
current,
source_id,
json,
all,
},
} => {
assert!(current);
assert!(source_id.is_none());
assert!(!json);
assert!(!all, "--all must default to false");
}
other => panic!("expected session ls, got {other:?}"),
}
}
#[test]
fn cli_session_ls_source_id_and_current_conflict() {
let result = Cli::try_parse_from([
"trusty-mpm",
"session",
"ls",
"--current",
"--source-id",
"foo/bar",
]);
assert!(
result.is_err(),
"passing both --current and --source-id must be a parse error"
);
}
#[test]
fn cli_parses_session_ls_all() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "ls", "--all"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Ls { all, json, .. },
} => {
assert!(all, "--all flag must parse to true");
assert!(!json);
}
other => panic!("expected session ls --all, got {other:?}"),
}
}
#[test]
fn cli_parses_session_activity() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "activity", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Activity { id },
} => assert_eq!(id, "abc"),
other => panic!("expected session activity, got {other:?}"),
}
}
#[test]
fn cli_parses_session_send() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "send", "abc", "hello"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Send { id, text },
} => {
assert_eq!(id, "abc");
assert_eq!(text, "hello");
}
other => panic!("expected session send, got {other:?}"),
}
}
#[test]
fn cli_parses_session_answer() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "answer", "abc", "rebase"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Answer { id, answer },
} => {
assert_eq!(id, "abc");
assert_eq!(answer, "rebase");
}
other => panic!("expected session answer, got {other:?}"),
}
}
#[test]
fn cli_parses_session_attach() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "attach", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Attach { id },
} => assert_eq!(id, "abc"),
other => panic!("expected session attach, got {other:?}"),
}
}
#[test]
fn cli_parses_session_managed_stop() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "managed-stop", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::ManagedStop { id },
} => assert_eq!(id, "abc"),
other => panic!("expected session managed-stop, got {other:?}"),
}
}
#[test]
fn cli_parses_session_runtime_stop() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "runtime-stop", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::RuntimeStop { id },
} => assert_eq!(id, "abc"),
other => panic!("expected session runtime-stop, got {other:?}"),
}
}
#[test]
fn cli_parses_session_managed_resume() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "managed-resume", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::ManagedResume { id },
} => assert_eq!(id, "abc"),
other => panic!("expected session managed-resume, got {other:?}"),
}
}
#[test]
fn cli_parses_session_stop_verb() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "stop", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Stop { id_or_name },
} => assert_eq!(id_or_name, "abc"),
other => panic!("expected session stop, got {other:?}"),
}
}
#[test]
fn cli_parses_session_resume_verb() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "resume", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Resume { id_or_name },
} => assert_eq!(id_or_name, "abc"),
other => panic!("expected session resume, got {other:?}"),
}
}
#[test]
fn cli_parses_session_decommission() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "decommission", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Decommission { id },
} => assert_eq!(id, "abc"),
other => panic!("expected session decommission, got {other:?}"),
}
}
#[test]
fn cli_parses_session_delete() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "delete", "abc"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Delete { id, force },
} => {
assert_eq!(id, "abc");
assert!(!force, "default must be the fail-closed force=false");
}
other => panic!("expected session delete, got {other:?}"),
}
let cli2 = Cli::try_parse_from(["trusty-mpm", "session", "delete", "abc", "--force"]).unwrap();
match cli2.command.unwrap() {
Command::Session {
action: SessionAction::Delete { id, force },
} => {
assert_eq!(id, "abc");
assert!(force, "--force must set force=true");
}
other => panic!("expected session delete, got {other:?}"),
}
}
#[test]
fn cli_parses_session_prune_idle() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "prune-idle", "--dry-run", "--json"])
.unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::PruneIdle { dry_run, json },
} => {
assert!(dry_run);
assert!(json);
}
other => panic!("expected session prune-idle, got {other:?}"),
}
}
#[test]
fn cli_parses_session_prune_idle_defaults() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "prune-idle"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::PruneIdle { dry_run, json },
} => {
assert!(!dry_run);
assert!(!json);
}
other => panic!("expected session prune-idle, got {other:?}"),
}
}
#[test]
fn cli_parses_session_decommission_ephemeral() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "decommission-ephemeral"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::DecommissionEphemeral,
} => {}
other => panic!("expected session decommission-ephemeral, got {other:?}"),
}
}
#[test]
fn cli_parses_session_prune() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"session",
"prune",
"--state",
"stopped",
"--dry-run",
])
.unwrap();
match cli.command.unwrap() {
Command::Session {
action:
SessionAction::Prune {
state,
dry_run,
include_active,
},
} => {
assert_eq!(state, "stopped");
assert!(dry_run);
assert!(
!include_active,
"include_active defaults to the fail-closed false"
);
}
other => panic!("expected session prune, got {other:?}"),
}
}
#[test]
fn cli_session_prune_requires_state() {
let err = Cli::try_parse_from(["trusty-mpm", "session", "prune"]);
assert!(err.is_err(), "prune without --state must fail to parse");
}
#[test]
fn cli_parses_session_prune_worktrees() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "prune-worktrees"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::PruneWorktrees { force },
} => {
assert!(!force, "default must be dry-run (force=false)");
}
other => panic!("expected session prune-worktrees, got {other:?}"),
}
let cli2 =
Cli::try_parse_from(["trusty-mpm", "session", "prune-worktrees", "--force"]).unwrap();
match cli2.command.unwrap() {
Command::Session {
action: SessionAction::PruneWorktrees { force },
} => {
assert!(force, "--force must set force=true");
}
other => panic!("expected session prune-worktrees, got {other:?}"),
}
}
#[test]
fn cli_parses_session_catchup() {
let cli = Cli::try_parse_from([
"trusty-mpm",
"session",
"catchup",
"--all-projects",
"--full",
])
.unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Catchup { all_projects, full },
} => {
assert!(all_projects, "--all-projects should be true");
assert!(full, "--full should be true");
}
other => panic!("expected session catchup, got {other:?}"),
}
}
#[test]
fn cli_parses_session_catchup_defaults() {
let cli = Cli::try_parse_from(["trusty-mpm", "session", "catchup"]).unwrap();
match cli.command.unwrap() {
Command::Session {
action: SessionAction::Catchup { all_projects, full },
} => {
assert!(!all_projects, "--all-projects should default to false");
assert!(!full, "--full should default to false");
}
other => panic!("expected session catchup, got {other:?}"),
}
}