use phora::cli::exit_code;
use phora::error::Error;
use phora::sync::state::StateError;
#[test]
fn contended_lock_maps_to_ex_tempfail() {
let state_error = StateError::Lock(
"another phora process is running for this project (state.lock held)".to_owned(),
);
let state_display = state_error.to_string();
let err = Error::StateCtx(state_error);
assert_eq!(
exit_code(&err),
75,
"a contended StateError::Lock must surface as EX_TEMPFAIL (75) so callers \
can distinguish 'busy, retry' from a hard failure"
);
assert_eq!(
err.to_string(),
state_display,
"the CLI-edge StateCtx variant must preserve StateError's transparent Display"
);
}
#[test]
fn other_errors_keep_exit_code_one() {
let err = Error::Config("read phora.toml: no such file".to_owned());
assert_eq!(
exit_code(&err),
1,
"non-lock failures must keep the historical exit code 1"
);
}
#[test]
fn state_registry_error_is_not_treated_as_tempfail() {
let state_error = StateError::StateStore("corrupt record".to_owned());
let state_display = state_error.to_string();
let err = Error::StateCtx(state_error);
assert_eq!(
exit_code(&err),
1,
"only the Lock variant is EX_TEMPFAIL; a registry error is a hard failure"
);
assert_eq!(
err.to_string(),
state_display,
"the CLI-edge StateCtx variant must preserve StateError's transparent Display"
);
}