use crate::brain::tools::evolve::diagnose_releases_latest_status;
use reqwest::StatusCode;
#[test]
fn _404_says_no_release_not_rate_limit() {
let msg = diagnose_releases_latest_status(StatusCode::NOT_FOUND, "", None, None);
assert!(
msg.contains("no published"),
"404 must explain that no published release exists, not lie about rate limit: {msg}"
);
assert!(
!msg.contains("rate limit"),
"404 must NOT mention rate limit — that was the prior bug: {msg}"
);
}
#[test]
fn _403_names_rate_limit_and_suggests_token() {
let msg = diagnose_releases_latest_status(
StatusCode::FORBIDDEN,
"API rate limit exceeded",
Some("0"),
Some("1717179600"),
);
assert!(
msg.contains("rate limit"),
"403 must name rate limit: {msg}"
);
assert!(
msg.contains("GITHUB_TOKEN"),
"403 must suggest the token escape hatch: {msg}"
);
assert!(
msg.contains("x-ratelimit-remaining=0"),
"403 must surface the remaining quota: {msg}"
);
assert!(
msg.contains("x-ratelimit-reset=1717179600"),
"403 must surface the reset epoch so the user knows when to retry: {msg}"
);
assert!(
msg.contains("API rate limit exceeded"),
"403 must quote the API's own error message: {msg}"
);
}
#[test]
fn _429_treated_same_as_403() {
let msg = diagnose_releases_latest_status(StatusCode::TOO_MANY_REQUESTS, "", Some("0"), None);
assert!(
msg.contains("rate limit"),
"429 must name rate limit: {msg}"
);
assert!(msg.contains("x-ratelimit-remaining=0"));
}
#[test]
fn _5xx_says_transient_server_issue() {
let msg = diagnose_releases_latest_status(StatusCode::BAD_GATEWAY, "", None, None);
assert!(
msg.contains("server-side") || msg.contains("retry"),
"5xx must signal a transient server-side issue: {msg}"
);
assert!(
!msg.contains("rate limit"),
"5xx must NOT mention rate limit: {msg}"
);
}
#[test]
fn unknown_4xx_falls_through_to_generic_with_status() {
let msg = diagnose_releases_latest_status(StatusCode::UNAUTHORIZED, "", None, None);
assert!(
msg.contains("401"),
"fallthrough must carry the actual status so it's debuggable: {msg}"
);
}
#[test]
fn body_excerpt_is_appended_when_present() {
let msg = diagnose_releases_latest_status(
StatusCode::NOT_FOUND,
r#"{"message":"Not Found","documentation_url":"..."}"#,
None,
None,
);
assert!(
msg.contains("API said"),
"body excerpt must be appended with a clear lead-in: {msg}"
);
assert!(
msg.contains("\"message\":\"Not Found\""),
"the actual API message must be quoted verbatim: {msg}"
);
}
#[test]
fn empty_body_excerpt_omitted_cleanly() {
let msg = diagnose_releases_latest_status(StatusCode::NOT_FOUND, " ", None, None);
assert!(
!msg.contains("API said"),
"whitespace-only body must not produce an empty 'API said:' tail: {msg}"
);
}