fix(#801): diff non-git-dir error envelope now includes error_kind, hint, and message fields

This commit is contained in:
YeonGyu-Kim
2026-05-27 18:34:58 +09:00
parent 1201dc60ef
commit 53953a8157
3 changed files with 41 additions and 0 deletions

View File

@@ -7766,3 +7766,5 @@ Original filing (2026-04-18): the session emitted `SessionStart hook (completed)
799. **`claw --output-format json ""` and `claw " "` returned `empty_prompt` + `hint:null`** — dogfooded 2026-05-27 on `bff37000`. The empty-prompt guard at the fallthrough path emitted `"empty prompt: provide a subcommand..."` with no `\n` delimiter. Fix: added `\n` + usage hint. Integration test `empty_prompt_has_non_null_hint_798`. Committed as `efb1542a`. 61 CLI contract tests pass. [SCOPE: claw-code]
800. **`classify_error_kind` unit test coverage gap: `invalid_history_count` and `unknown_option` arms had zero assertions** — found 2026-05-27 on `efb1542a`. Audit of 39 distinct classifier return values vs 37 unit test assertions revealed 2 untested arms. Fix: added 3 `assert_eq!` covering both arms (invalid_history_count prefix + contains paths, unknown_option prefix). Committed as `6ee67d6c`. All 39 return values now have unit test coverage. [SCOPE: claw-code]
801. **`claw --output-format json diff` in a non-git directory was missing `error_kind`, `hint`, and `message` fields** — dogfooded 2026-05-27 on `1201dc60`. The diff handler's no-git-repo JSON branch constructed a custom object with only `status:"error"` + `result:"no_git_repo"` + `detail`, violating the error envelope contract that every error has `error_kind` + `hint`. Fix: added `error_kind: "no_git_repo"`, `hint: "Run git init..."`, and `message` fields. Integration test `diff_non_git_dir_has_error_kind_and_hint_801`. 62 CLI contract tests pass. [SCOPE: claw-code] Source: Jobdori non-git-dir probe on `1201dc60`, 2026-05-27.

View File

@@ -8331,11 +8331,15 @@ fn render_diff_json_for(cwd: &Path) -> Result<serde_json::Value, Box<dyn std::er
.map(|o| o.status.success())
.unwrap_or(false);
if !in_git_repo {
// #801: add error_kind, hint, message fields for envelope parity with other error paths
return Ok(serde_json::json!({
"kind": "diff",
"action": "diff",
"status": "error",
"error_kind": "no_git_repo",
"result": "no_git_repo",
"message": format!("{} is not inside a git project", cwd.display()),
"hint": "Run `git init` to create a repository, or change to a directory that is inside a git project.",
"working_directory": cwd.display().to_string(),
"detail": format!("{} is not inside a git project", cwd.display()),
}));

View File

@@ -3451,3 +3451,38 @@ fn empty_prompt_has_non_null_hint_798() {
"hint should reference usage, got: {h:?}"
);
}
#[test]
fn diff_non_git_dir_has_error_kind_and_hint_801() {
// #801: `claw --output-format json diff` in a non-git directory returned
// status:"error" + result:"no_git_repo" but had no error_kind, hint, or
// message fields — violating the error envelope contract. Fix: added all
// three fields to the no_git_repo JSON branch.
let root = unique_temp_dir("diff-nongit-801");
fs::create_dir_all(&root).expect("temp dir");
// Intentionally NOT running git init
let output = run_claw(&root, &["--output-format", "json", "diff"], &[]);
// diff non-git may exit 0 (custom JSON handler) — check envelope content
let stdout = String::from_utf8_lossy(&output.stdout);
let j: serde_json::Value =
serde_json::from_str(stdout.trim()).expect("diff non-git should emit valid JSON");
assert_eq!(j["status"], "error");
assert_eq!(j["result"], "no_git_repo");
assert_eq!(
j["error_kind"], "no_git_repo",
"diff non-git must have error_kind (#801), got {:?}",
j["error_kind"]
);
let h = j["hint"]
.as_str()
.expect("diff non-git must have non-null hint (#801)");
assert!(
h.contains("git init") || h.contains("git"),
"hint should suggest git init, got: {h:?}"
);
assert!(
j["message"].as_str().is_some(),
"diff non-git must have message field (#801)"
);
}