hive-agent: test the state status computation
This commit is contained in:
parent
ac3b3cfcd3
commit
934ba3a9c5
1 changed files with 24 additions and 6 deletions
|
|
@ -13,11 +13,7 @@ pub(super) async fn api_state(State(state): State<AppState>) -> axum::Json<State
|
||||||
// "events with seq > snapshot.seq are post-snapshot, never missed."
|
// "events with seq > snapshot.seq are post-snapshot, never missed."
|
||||||
let seq = state.bus.current_seq();
|
let seq = state.bus.current_seq();
|
||||||
let login = *state.login.lock().unwrap();
|
let login = *state.login.lock().unwrap();
|
||||||
let status = match login {
|
let status = status_of(login, state.bus.is_rate_limited());
|
||||||
LoginState::Online if state.bus.is_rate_limited() => "rate_limited",
|
|
||||||
LoginState::Online => "online",
|
|
||||||
LoginState::NeedsLogin => "needs_login_idle",
|
|
||||||
};
|
|
||||||
let dashboard_port = std::env::var("HIVE_DASHBOARD_PORT")
|
let dashboard_port = std::env::var("HIVE_DASHBOARD_PORT")
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|s| s.parse::<u16>().ok())
|
.and_then(|s| s.parse::<u16>().ok())
|
||||||
|
|
@ -430,11 +426,33 @@ fn offered_shown(model: String, effort: String, offered: hive_runtime::SessionCh
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The `status` string of the state snapshot: credentials missing beats
|
||||||
|
/// everything, then a rate limit, else online.
|
||||||
|
fn status_of(login: LoginState, rate_limited: bool) -> &'static str {
|
||||||
|
match login {
|
||||||
|
LoginState::Online if rate_limited => "rate_limited",
|
||||||
|
LoginState::Online => "online",
|
||||||
|
LoginState::NeedsLogin => "needs_login_idle",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use hive_runtime::{Choice, SessionChoices};
|
use hive_runtime::{Choice, SessionChoices};
|
||||||
|
|
||||||
use super::{Shown, offered_shown};
|
use super::{LoginState, Shown, offered_shown, status_of};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn status_follows_the_credentials_then_the_rate_limit() {
|
||||||
|
assert_eq!(status_of(LoginState::Online, false), "online");
|
||||||
|
assert_eq!(status_of(LoginState::Online, true), "rate_limited");
|
||||||
|
assert_eq!(status_of(LoginState::NeedsLogin, false), "needs_login_idle");
|
||||||
|
assert_eq!(
|
||||||
|
status_of(LoginState::NeedsLogin, true),
|
||||||
|
"needs_login_idle",
|
||||||
|
"missing credentials outrank a rate limit"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn choice(current: &str, values: &[&str]) -> Choice {
|
fn choice(current: &str, values: &[&str]) -> Choice {
|
||||||
Choice {
|
Choice {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue