refactor(cli): tighten auth-required classification code

Simplifies three spots surfaced by a code-reuse pass: use
console::strip_ansi_codes in fatal_error_line, use provider_kind()
instead of re-pattern-matching the LLM error shape in
classify_server_agent_auth, and drop an unused const on Classified::class.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-04-21 23:59:36 -04:00
parent 105559bc8a
commit d0578f67f0
No known key found for this signature in database
3 changed files with 4 additions and 11 deletions

View file

@ -220,10 +220,8 @@ fn classify_server_agent_auth(err: anyhow::Error) -> anyhow::Error {
.is_some_and(|error| {
matches!(
error,
fabro_agent::Error::Llm(fabro_llm::Error::Provider {
kind: fabro_llm::ProviderErrorKind::Authentication,
..
})
fabro_agent::Error::Llm(llm)
if llm.provider_kind() == Some(ProviderErrorKind::Authentication)
)
})
});

View file

@ -63,13 +63,8 @@ pub(crate) fn run_output_filters(context: &TestContext) -> Vec<(String, String)>
}
pub(crate) fn fatal_error_line(stderr: &[u8]) -> String {
static ANSI_RE: std::sync::OnceLock<regex::Regex> = std::sync::OnceLock::new();
let ansi_re = ANSI_RE.get_or_init(|| {
regex::Regex::new(r"\x1b\[[0-9;]*m").expect("ANSI-stripping regex should compile")
});
let stderr = String::from_utf8_lossy(stderr);
let stripped = ansi_re.replace_all(&stderr, "");
stripped
console::strip_ansi_codes(&stderr)
.lines()
.rev()
.find_map(|line| line.strip_prefix("error: ").map(ToOwned::to_owned))

View file

@ -13,7 +13,7 @@ struct Classified {
}
impl Classified {
const fn class(&self) -> ExitClass {
fn class(&self) -> ExitClass {
self.class
}
}