mirror of
https://github.com/instructkr/claude-code.git
synced 2026-06-05 12:06:43 +00:00
fix: keep failed resume side-effect free
Generated with https://github.com/Yeachan-Heo/gajae-code Co-authored-by: Gajae Code <dev@gajae-code.com>
This commit is contained in:
@@ -5424,6 +5424,54 @@ fn multi_word_unknown_subcommand_json_emits_command_not_found_826() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compact_flag_missing_argument_and_shorthand_prompt_contract_435() {
|
||||
let root = unique_temp_dir("compact-flag-435");
|
||||
let config_home = root.join("config-home");
|
||||
let home = root.join("home");
|
||||
std::fs::create_dir_all(&root).expect("create temp dir");
|
||||
std::fs::create_dir_all(&config_home).expect("create config home");
|
||||
std::fs::create_dir_all(&home).expect("create home");
|
||||
let envs = [
|
||||
(
|
||||
"CLAW_CONFIG_HOME",
|
||||
config_home.to_str().expect("config home utf8"),
|
||||
),
|
||||
("HOME", home.to_str().expect("home utf8")),
|
||||
("ANTHROPIC_API_KEY", ""),
|
||||
("ANTHROPIC_AUTH_TOKEN", ""),
|
||||
("OPENAI_API_KEY", ""),
|
||||
];
|
||||
|
||||
let missing = run_claw(&root, &["--output-format", "json", "--compact"], &envs);
|
||||
assert_eq!(missing.status.code(), Some(1));
|
||||
assert!(
|
||||
missing.stderr.is_empty(),
|
||||
"compact missing-argument JSON should keep stderr empty: {}",
|
||||
String::from_utf8_lossy(&missing.stderr)
|
||||
);
|
||||
let missing_json = parse_json_stdout(&missing, "compact missing argument");
|
||||
assert_eq!(missing_json["error_kind"], "missing_argument");
|
||||
assert_eq!(missing_json["argument"], "prompt or subcommand");
|
||||
|
||||
let prompt = run_claw(
|
||||
&root,
|
||||
&["--output-format", "json", "--compact", "hello"],
|
||||
&envs,
|
||||
);
|
||||
assert_eq!(prompt.status.code(), Some(1));
|
||||
assert!(
|
||||
prompt.stderr.is_empty(),
|
||||
"compact prompt JSON should keep stderr empty: {}",
|
||||
String::from_utf8_lossy(&prompt.stderr)
|
||||
);
|
||||
let prompt_json = parse_json_stdout(&prompt, "compact shorthand prompt");
|
||||
assert_eq!(
|
||||
prompt_json["error_kind"], "missing_credentials",
|
||||
"--compact hello should stay on the prompt/provider path, not command_not_found: {prompt_json}"
|
||||
);
|
||||
}
|
||||
|
||||
// #827: direct /unknown-slash-command must emit typed error_kind, not "unknown"
|
||||
// Uses the direct-slash CLI path (no session load needed; reproducible on CI).
|
||||
#[test]
|
||||
|
||||
@@ -222,6 +222,73 @@ fn resume_latest_restores_the_most_recent_managed_session() {
|
||||
assert!(stdout.contains(newer_path.to_str().expect("utf8 path")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resume_latest_missing_session_fails_without_creating_session_dirs_435() {
|
||||
// given
|
||||
let temp_dir = unique_temp_dir("resume-latest-missing-435");
|
||||
let project_dir = temp_dir.join("project");
|
||||
let config_home = temp_dir.join("config-home");
|
||||
let home = temp_dir.join("home");
|
||||
fs::create_dir_all(&project_dir).expect("project dir should exist");
|
||||
fs::create_dir_all(&config_home).expect("config home should exist");
|
||||
fs::create_dir_all(&home).expect("home should exist");
|
||||
let envs = [
|
||||
(
|
||||
"CLAW_CONFIG_HOME",
|
||||
config_home.to_str().expect("utf8 config home"),
|
||||
),
|
||||
("HOME", home.to_str().expect("utf8 home")),
|
||||
("ANTHROPIC_API_KEY", ""),
|
||||
("ANTHROPIC_AUTH_TOKEN", ""),
|
||||
("OPENAI_API_KEY", ""),
|
||||
];
|
||||
|
||||
// when — both text and JSON resume failures should be non-zero and read-only.
|
||||
let text = run_claw_with_env(&project_dir, &["--resume", "latest"], &envs);
|
||||
let json = run_claw_with_env(
|
||||
&project_dir,
|
||||
&["--output-format", "json", "--resume", "latest"],
|
||||
&envs,
|
||||
);
|
||||
|
||||
// then
|
||||
assert_eq!(
|
||||
text.status.code(),
|
||||
Some(1),
|
||||
"text resume failure must be non-zero"
|
||||
);
|
||||
assert!(
|
||||
text.stdout.is_empty(),
|
||||
"text resume failure should not claim success on stdout: {}",
|
||||
String::from_utf8_lossy(&text.stdout)
|
||||
);
|
||||
let text_stderr = String::from_utf8_lossy(&text.stderr);
|
||||
assert!(
|
||||
text_stderr.contains("no managed sessions found"),
|
||||
"text failure should explain missing sessions: {text_stderr}"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
json.status.code(),
|
||||
Some(1),
|
||||
"JSON resume failure must be non-zero"
|
||||
);
|
||||
assert!(
|
||||
json.stderr.is_empty(),
|
||||
"JSON resume failure should keep stderr empty: {}",
|
||||
String::from_utf8_lossy(&json.stderr)
|
||||
);
|
||||
let parsed: Value = serde_json::from_slice(&json.stdout)
|
||||
.expect("JSON resume failure should emit JSON to stdout");
|
||||
assert_eq!(parsed["status"], "error");
|
||||
assert_eq!(parsed["action"], "restore");
|
||||
assert_eq!(parsed["error_kind"], "no_managed_sessions");
|
||||
assert!(
|
||||
!project_dir.join(".claw").exists(),
|
||||
"failed resume must not create .claw/session directories"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resumed_status_command_emits_structured_json_when_requested() {
|
||||
// given
|
||||
|
||||
Reference in New Issue
Block a user