test(#747): regression guard for #745 bare slash command hint contract (issue/pr/commit)

This commit is contained in:
YeonGyu-Kim
2026-05-26 19:06:59 +09:00
parent 18e7744e42
commit 04eb661e57
2 changed files with 50 additions and 0 deletions

View File

@@ -7659,3 +7659,5 @@ Original filing (2026-04-18): the session emitted `SessionStart hook (completed)
745. **`claw issue --output-format json` and all other direct-CLI slash commands (pr, commit, etc.) returned `hint: null` — the `bare_slash_command_guidance` message strings had no `\n` separator between short error and remediation text, so `split_error_hint` couldn't populate the hint field** — dogfooded 2026-05-26 on `92e053a1`. The #738 fix added `\n` to the `--resume SESSION /cmd` path but missed the direct-CLI path (e.g. `claw issue`, `claw pr`). The `bare_slash_command_guidance` function formats two message variants: resume-supported and non-resume; both lacked `\n`. Fix: add `\n` before the remediation text in both format strings. Source: Jobdori dogfood on `92e053a1`, 2026-05-26.
746. **`claw --output-format json` (bare, no TTY, no prompt) returned `hint: null` — the non-TTY interactive-only guard error string had no `\n` separator, so `split_error_hint` couldn't extract the remediation text into `.hint`** — dogfooded 2026-05-26 on `3c5459a3`. The single-string message `"interactive_only: claw requires an interactive terminal (stdin is not a TTY and no prompt was provided \u2014 pipe a prompt or run in a TTY)"` contained the hint inline but no newline, so callers reading `.hint` got null and had to parse the prose `error` string. Fix: split at `\n` — short error `"interactive_only: claw requires an interactive terminal."` + hint `"Stdin is not a TTY…pipe a prompt with \`echo 'task' | claw\` or run \`claw\` in an interactive terminal."`. Source: Jobdori dogfood on `3c5459a3`, 2026-05-26.
747. **ROADMAP #745 has no regression test: `claw issue/pr/commit --output-format json hint` could silently regress to null** — confirmed by gaebal-gajae on `3c5459a33`. Same pattern as #737, #742, #744. Fix: add `bare_slash_command_hint_745` test iterating `issue`, `pr`, `commit` and asserting `error_kind:"interactive_only"` + non-empty `hint` field. Source: gaebal-gajae dogfood on `3c5459a33`, fixed on `18e7744e`, 2026-05-26.

View File

@@ -1456,6 +1456,54 @@ fn diff_json_changed_file_count_deduplication_733() {
);
}
#[test]
fn bare_slash_command_hint_745() {
// #747/#745: claw <slash-cmd> --output-format json must return non-null hint.
// bare_slash_command_guidance() previously had no \n so split_error_hint returned hint:null.
use std::process::Command;
let root = unique_temp_dir("bare-slash-hint");
fs::create_dir_all(&root).expect("temp dir");
let bin = env!("CARGO_BIN_EXE_claw");
// issue and pr are non-resume-supported; commit is resume-supported.
// All must emit non-null hint in their interactive_only error envelope.
for cmd in &["issue", "pr", "commit"] {
let output = Command::new(bin)
.current_dir(&root)
.args(["--output-format", "json", cmd])
.env("ANTHROPIC_API_KEY", "test")
.output()
.expect("claw should run");
assert!(
!output.status.success(),
"claw {cmd} outside REPL must exit non-zero"
);
// Error envelope is on stderr (type:error path) or stdout
let stderr = String::from_utf8_lossy(&output.stderr)
.lines()
.filter(|l| l.starts_with('{'))
.collect::<Vec<_>>()
.join("");
let stdout = String::from_utf8_lossy(&output.stdout);
let raw = if !stderr.is_empty() {
stderr
} else {
stdout.trim().to_string()
};
let parsed: serde_json::Value = serde_json::from_str(&raw)
.unwrap_or_else(|_| panic!("claw {cmd} must emit JSON; got: {raw}"));
assert_eq!(
parsed["error_kind"], "interactive_only",
"claw {cmd} must have error_kind:interactive_only (#745)"
);
let hint = parsed["hint"].as_str().unwrap_or("");
assert!(
!hint.is_empty(),
"claw {cmd} --output-format json hint must be non-empty (#745); got null"
);
}
}
#[test]
fn config_unsupported_section_json_hint_741() {
// #744/#741: claw config <unknown-section> --output-format json must return