mirror of
https://github.com/instructkr/claude-code.git
synced 2026-05-28 16:36:45 +00:00
fix(#789): agents show and plugins show not-found now exit 1; parity with skills (#788) and mcp (#68)
This commit is contained in:
@@ -6281,10 +6281,17 @@ impl LiveCli {
|
||||
let cwd = env::current_dir()?;
|
||||
match output_format {
|
||||
CliOutputFormat::Text => println!("{}", handle_agents_slash_command(args, &cwd)?),
|
||||
CliOutputFormat::Json => println!(
|
||||
"{}",
|
||||
serde_json::to_string_pretty(&handle_agents_slash_command_json(args, &cwd)?)?
|
||||
),
|
||||
CliOutputFormat::Json => {
|
||||
let value = handle_agents_slash_command_json(args, &cwd)?;
|
||||
// #789: parity with print_mcp/#788 print_skills — exit 1 when envelope
|
||||
// reports an error so automation can rely on exit code instead of
|
||||
// parsing the JSON status field.
|
||||
let is_error = value.get("status").and_then(|v| v.as_str()) == Some("error");
|
||||
println!("{}", serde_json::to_string_pretty(&value)?);
|
||||
if is_error {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -6428,7 +6435,8 @@ impl LiveCli {
|
||||
"hint": "Run `claw plugins list` to see available plugins.",
|
||||
});
|
||||
println!("{}", serde_json::to_string_pretty(&obj)?);
|
||||
return Ok(());
|
||||
// #789: exit 1 on not-found so automation can rely on exit code
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,9 @@ fn inventory_commands_emit_structured_json_when_requested() {
|
||||
isolated_codex.to_str().expect("utf8 codex home"),
|
||||
),
|
||||
];
|
||||
let agents_show_missing = assert_json_command_with_env(
|
||||
// #789: agents show not-found now exits 1 (parity with skills #788);
|
||||
// use run_claw directly instead of assert_json_command_with_env which checks success.
|
||||
let agents_show_out = run_claw(
|
||||
&root,
|
||||
&[
|
||||
"--output-format",
|
||||
@@ -214,6 +216,12 @@ fn inventory_commands_emit_structured_json_when_requested() {
|
||||
],
|
||||
&agents_show_env,
|
||||
);
|
||||
assert!(
|
||||
!agents_show_out.status.success(),
|
||||
"agents show not-found must exit non-zero"
|
||||
);
|
||||
let agents_show_missing: serde_json::Value =
|
||||
serde_json::from_slice(&agents_show_out.stdout).expect("agents show stdout should be json");
|
||||
assert_eq!(agents_show_missing["kind"], "agents", "agents show kind");
|
||||
assert_eq!(agents_show_missing["action"], "show", "agents show action");
|
||||
assert_eq!(
|
||||
@@ -2765,3 +2773,72 @@ fn skills_show_not_found_emits_single_json_object_788() {
|
||||
);
|
||||
assert_eq!(json_objects[0]["status"], "error");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn agents_show_not_found_exits_nonzero_789() {
|
||||
// #789: `claw --output-format json agents show <not-found>` returned exit 0 despite
|
||||
// emitting status:"error". print_agents had no error check — just println + Ok(()).
|
||||
// Skills was fixed in #788 (exit 1 via process::exit); agents/plugins had the same gap.
|
||||
let root = unique_temp_dir("agents-show-exit-789");
|
||||
fs::create_dir_all(&root).expect("temp dir");
|
||||
std::process::Command::new("git")
|
||||
.args(["init", "-q"])
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
.ok();
|
||||
|
||||
let output = run_claw(
|
||||
&root,
|
||||
&[
|
||||
"--output-format",
|
||||
"json",
|
||||
"agents",
|
||||
"show",
|
||||
"no-such-agent-xyz-789",
|
||||
],
|
||||
&[],
|
||||
);
|
||||
assert!(
|
||||
!output.status.success(),
|
||||
"agents show not-found must exit non-zero (#789), got exit 0"
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let j: serde_json::Value =
|
||||
serde_json::from_str(stdout.trim()).expect("agents show should emit valid JSON");
|
||||
assert_eq!(j["error_kind"], "agent_not_found");
|
||||
assert_eq!(j["status"], "error");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plugins_show_not_found_exits_nonzero_789() {
|
||||
// #789: same as agents — `claw --output-format json plugins show <not-found>` exited 0
|
||||
// despite status:"error". The not-found branch used `return Ok(())` instead of exit(1).
|
||||
let root = unique_temp_dir("plugins-show-exit-789");
|
||||
fs::create_dir_all(&root).expect("temp dir");
|
||||
std::process::Command::new("git")
|
||||
.args(["init", "-q"])
|
||||
.current_dir(&root)
|
||||
.output()
|
||||
.ok();
|
||||
|
||||
let output = run_claw(
|
||||
&root,
|
||||
&[
|
||||
"--output-format",
|
||||
"json",
|
||||
"plugins",
|
||||
"show",
|
||||
"no-such-plugin-xyz-789",
|
||||
],
|
||||
&[],
|
||||
);
|
||||
assert!(
|
||||
!output.status.success(),
|
||||
"plugins show not-found must exit non-zero (#789), got exit 0"
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let j: serde_json::Value =
|
||||
serde_json::from_str(stdout.trim()).expect("plugins show should emit valid JSON");
|
||||
assert_eq!(j["error_kind"], "plugin_not_found");
|
||||
assert_eq!(j["status"], "error");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user