Skip to content

Commit ddc71b5

Browse files
committed
test(#751): regression guard for #750 prompt no-arg error_kind and hint contract
1 parent ac925ed commit ddc71b5

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

ROADMAP.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7667,3 +7667,5 @@ Original filing (2026-04-18): the session emitted `SessionStart hook (completed)
76677667
749. **`claw compact --output-format json` returned `hint: null` — `compact_interactive_only_error()` returned a single-line string with no `\n` between short error and remediation text, so `split_error_hint` couldn't populate the hint field** — identified by gaebal-gajae on `04eb661e`. Same class as #738 / #745 / #746. Fix: add `\n` before the remediation text in `compact_interactive_only_error`. Regression guard: extended `compact_subcommand_json_help_fails_fast_when_stdin_closed` to also assert `hint` is non-empty and mentions `/compact` or `--resume`. Source: gaebal-gajae dogfood on `04eb661e`, 2026-05-26.
76687668

76697669
750. **`claw prompt --output-format json` (no text argument) returned `error_kind:"unknown"` and `hint: null`** — dogfooded 2026-05-26 on `2dfb7af6`. The error string `"prompt subcommand requires a prompt string"` had no prefix prefix for classifier and no `\n` for hint extraction. Fix: (a) prefix with `"missing_prompt: "` + newline before usage hint; (b) add `message.starts_with("missing_prompt:")` → `"missing_prompt"` classifier arm. Result: `error_kind:"missing_prompt"`, `hint:"Usage: claw prompt <text> or echo '<text>' | claw"`. Source: Jobdori dogfood on `2dfb7af6`, 2026-05-26.
7670+
7671+
751. **ROADMAP #750 has no regression test: `claw prompt --output-format json` no-arg `error_kind` and `hint` could silently regress** — confirmed by gaebal-gajae on `ac925ed4`. Fix: add `prompt_no_arg_json_error_kind_750` test asserting nonzero exit, `error_kind:"missing_prompt"`, non-empty `hint` mentioning `claw prompt` or `echo`. Source: gaebal-gajae dogfood on `ac925ed4`, 2026-05-26.

rust/crates/rusty-claude-cli/tests/output_format_contract.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,54 @@ fn diff_json_changed_file_count_deduplication_733() {
14561456
);
14571457
}
14581458

1459+
#[test]
1460+
fn prompt_no_arg_json_error_kind_750() {
1461+
// #751/#750: `claw prompt --output-format json` with no prompt argument must emit
1462+
// error_kind:"missing_prompt" and a non-empty hint. Before #750 it returned
1463+
// error_kind:"unknown" + hint:null.
1464+
use std::process::Command;
1465+
let root = unique_temp_dir("prompt-no-arg");
1466+
fs::create_dir_all(&root).expect("temp dir");
1467+
let bin = env!("CARGO_BIN_EXE_claw");
1468+
1469+
let output = Command::new(bin)
1470+
.current_dir(&root)
1471+
.args(["--output-format", "json", "prompt"])
1472+
.output()
1473+
.expect("claw prompt should run");
1474+
assert!(
1475+
!output.status.success(),
1476+
"claw prompt with no arg must exit non-zero"
1477+
);
1478+
let stdout = String::from_utf8_lossy(&output.stdout);
1479+
let stderr = String::from_utf8_lossy(&output.stderr)
1480+
.lines()
1481+
.filter(|l| l.starts_with('{'))
1482+
.collect::<Vec<_>>()
1483+
.join("");
1484+
let raw = if stdout.trim().starts_with('{') {
1485+
stdout.trim().to_string()
1486+
} else {
1487+
stderr
1488+
};
1489+
let parsed: serde_json::Value = serde_json::from_str(&raw).unwrap_or_else(|_| {
1490+
panic!("claw prompt (no arg) --output-format json must emit valid JSON; got: {raw}")
1491+
});
1492+
assert_eq!(
1493+
parsed["error_kind"], "missing_prompt",
1494+
"claw prompt no-arg must have error_kind:missing_prompt (#750); got: {parsed}"
1495+
);
1496+
let hint = parsed["hint"].as_str().unwrap_or("");
1497+
assert!(
1498+
!hint.is_empty(),
1499+
"claw prompt no-arg hint must be non-empty (#750)"
1500+
);
1501+
assert!(
1502+
hint.contains("claw prompt") || hint.contains("echo"),
1503+
"hint should mention 'claw prompt' or 'echo': {hint}"
1504+
);
1505+
}
1506+
14591507
#[test]
14601508
fn bare_slash_command_hint_745() {
14611509
// #747/#745: claw <slash-cmd> --output-format json must return non-null hint.

0 commit comments

Comments
 (0)