use super::*;
pub(super) async fn get_readiness(
registry: &SessionRegistry,
params: Value,
_ctx: ConnectionContext,
) -> Result<Value, RpcError> {
let p: SessionIdParams = parse(params, "session.get_readiness")?;
Ok(json!(registry.get_readiness(&p.session_id)?))
}
#[cfg(test)]
mod tests {
use super::*;
use tokio::sync::mpsc;
fn test_ctx() -> ConnectionContext {
let (tx, _rx) = mpsc::unbounded_channel();
ConnectionContext::new(tx)
}
#[tokio::test]
async fn get_readiness_never_probed_session_returns_never_probed() {
let registry = SessionRegistry::new();
let session = registry.create("t".to_string(), None, crate::binding::ProjectBinding::None);
let result = get_readiness(®istry, json!({"session_id": session.id}), test_ctx())
.await
.unwrap();
assert_eq!(result["status"], "never_probed");
}
#[tokio::test]
async fn get_readiness_returns_probed_snapshot_after_recording() {
let registry = SessionRegistry::new();
let session = registry.create("t".to_string(), None, crate::binding::ProjectBinding::None);
registry
.record_index_readiness(&session.id, None, "no daemon")
.unwrap();
let result = get_readiness(®istry, json!({"session_id": session.id}), test_ctx())
.await
.unwrap();
assert_eq!(result["status"], "probed");
assert_eq!(result["state"], "unavailable");
assert_eq!(result["summary"], "no daemon");
}
#[tokio::test]
async fn get_readiness_unknown_session_maps_to_session_not_found() {
let registry = SessionRegistry::new();
let err = get_readiness(®istry, json!({"session_id": "nope"}), test_ctx())
.await
.unwrap_err();
assert_eq!(err.code, -32007);
}
}