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."
|
||||
let seq = state.bus.current_seq();
|
||||
let login = *state.login.lock().unwrap();
|
||||
let status = match login {
|
||||
LoginState::Online if state.bus.is_rate_limited() => "rate_limited",
|
||||
LoginState::Online => "online",
|
||||
LoginState::NeedsLogin => "needs_login_idle",
|
||||
};
|
||||
let status = status_of(login, state.bus.is_rate_limited());
|
||||
let dashboard_port = std::env::var("HIVE_DASHBOARD_PORT")
|
||||
.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)]
|
||||
mod tests {
|
||||
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 {
|
||||
Choice {
|
||||
|
|
|
|||
Loading…
Reference in a new issue