mirror of
https://github.com/instructkr/claude-code.git
synced 2026-05-28 08:26:45 +00:00
fix(#796): agents/skills show <name> <extra> returned wrong not-found instead of unexpected_extra_args
This commit is contained in:
@@ -2459,12 +2459,29 @@ pub fn handle_agents_slash_command_json(args: Option<&str>, cwd: &Path) -> std::
|
||||
|| args.starts_with("info ")
|
||||
|| args.starts_with("describe ") =>
|
||||
{
|
||||
let name = args
|
||||
let name_raw = args
|
||||
.split_once(' ')
|
||||
.map(|(_, name)| name)
|
||||
.unwrap_or_default()
|
||||
.trim()
|
||||
.to_lowercase();
|
||||
// #796: extra positional args after the name (e.g. `agents show foo extra`)
|
||||
// produced a confusing agent_not_found for "foo extra" instead of flagging
|
||||
// the unexpected extra argument.
|
||||
let (name, extra) = name_raw
|
||||
.split_once(' ')
|
||||
.map(|(n, e)| (n.to_string(), Some(e.to_string())))
|
||||
.unwrap_or_else(|| (name_raw.clone(), None));
|
||||
if let Some(extra_token) = extra {
|
||||
return Ok(serde_json::json!({
|
||||
"kind": "agents",
|
||||
"action": "show",
|
||||
"status": "error",
|
||||
"error_kind": "unexpected_extra_args",
|
||||
"unexpected": extra_token,
|
||||
"hint": format!("Usage: claw agents show <name>\nUnexpected extra: '{extra_token}'"),
|
||||
}));
|
||||
}
|
||||
let roots = discover_definition_roots(cwd, "agents");
|
||||
let agents = load_agents_from_roots(&roots)?;
|
||||
let matched: Vec<_> = agents
|
||||
@@ -2624,12 +2641,29 @@ pub fn handle_skills_slash_command_json(args: Option<&str>, cwd: &Path) -> std::
|
||||
|| args.starts_with("info ")
|
||||
|| args.starts_with("describe ") =>
|
||||
{
|
||||
let name = args
|
||||
let name_raw = args
|
||||
.split_once(' ')
|
||||
.map(|(_, name)| name)
|
||||
.unwrap_or_default()
|
||||
.trim()
|
||||
.to_lowercase();
|
||||
// #796: extra positional args after the name (e.g. `skills show foo extra`)
|
||||
// produced a confusing skill_not_found for "foo extra" instead of flagging
|
||||
// the unexpected extra argument.
|
||||
let (name, extra) = name_raw
|
||||
.split_once(' ')
|
||||
.map(|(n, e)| (n.to_string(), Some(e.to_string())))
|
||||
.unwrap_or_else(|| (name_raw.clone(), None));
|
||||
if let Some(extra_token) = extra {
|
||||
return Ok(json!({
|
||||
"kind": "skills",
|
||||
"action": "show",
|
||||
"status": "error",
|
||||
"error_kind": "unexpected_extra_args",
|
||||
"unexpected": extra_token,
|
||||
"hint": format!("Usage: claw skills show <name>\nUnexpected extra: '{extra_token}'"),
|
||||
}));
|
||||
}
|
||||
let roots = discover_skill_roots(cwd);
|
||||
let skills = load_skills_from_roots(&roots)?;
|
||||
let matched: Vec<_> = skills
|
||||
|
||||
@@ -3282,3 +3282,94 @@ fn skills_install_not_found_and_unsupported_action_have_hints_795() {
|
||||
.expect("unsupported_skills_action must have non-null hint (#795)");
|
||||
assert!(!h2.is_empty(), "hint must be non-empty");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn agents_show_extra_positional_arg_returns_unexpected_extra_796() {
|
||||
// #796: `claw agents show <name> <extra>` treated the full "name extra" as a single
|
||||
// agent name, producing agent_not_found for "name extra" instead of flagging the
|
||||
// unexpected extra argument. Fix: detect space-containing "name" and return
|
||||
// unexpected_extra_args with usage hint.
|
||||
let root = unique_temp_dir("agents-show-extra-796");
|
||||
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",
|
||||
"some-agent",
|
||||
"--extra-flag",
|
||||
],
|
||||
&[],
|
||||
);
|
||||
assert!(
|
||||
!output.status.success(),
|
||||
"agents show with extra arg must exit non-zero (#796)"
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let j: serde_json::Value =
|
||||
serde_json::from_str(stdout.trim()).expect("agents show extra arg should emit valid JSON");
|
||||
assert_eq!(
|
||||
j["error_kind"], "unexpected_extra_args",
|
||||
"agents show extra arg should return unexpected_extra_args, got {:?}",
|
||||
j["error_kind"]
|
||||
);
|
||||
let h = j["hint"]
|
||||
.as_str()
|
||||
.expect("unexpected_extra_args must have hint (#796)");
|
||||
assert!(
|
||||
h.contains("claw agents show") || h.contains("Usage"),
|
||||
"hint should reference usage, got: {h:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn skills_show_extra_positional_arg_returns_unexpected_extra_796() {
|
||||
// #796: same gap as agents — `claw skills show <name> <extra>` treated "name extra"
|
||||
// as a single skill name → skill_not_found. Fix: detect space-containing name.
|
||||
let root = unique_temp_dir("skills-show-extra-796");
|
||||
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",
|
||||
"skills",
|
||||
"show",
|
||||
"some-skill",
|
||||
"--extra-flag",
|
||||
],
|
||||
&[],
|
||||
);
|
||||
assert!(
|
||||
!output.status.success(),
|
||||
"skills show with extra arg must exit non-zero (#796)"
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let j: serde_json::Value =
|
||||
serde_json::from_str(stdout.trim()).expect("skills show extra arg should emit valid JSON");
|
||||
assert_eq!(
|
||||
j["error_kind"], "unexpected_extra_args",
|
||||
"skills show extra arg should return unexpected_extra_args, got {:?}",
|
||||
j["error_kind"]
|
||||
);
|
||||
assert!(
|
||||
j["hint"]
|
||||
.as_str()
|
||||
.is_some_and(|h| h.contains("claw skills show") || h.contains("Usage")),
|
||||
"hint should reference usage (#796)"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user