Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: add test support module for session tests

Steven Enamakel0f38ad6021e4
diff --git a/crates/openhuman-session/src/client_tests.rs b/crates/openhuman-session/src/client_tests.rs
index 1dc4555543..8617235064 100644
--- a/crates/openhuman-session/src/client_tests.rs
+++ b/crates/openhuman-session/src/client_tests.rs
@@ -51,7 +51,7 @@ async fn consume_login_token_returns_jwt_and_sends_attribution_headers() {
let backend = Backend::start(vec![MeAnswer::Ok(me_user())]).await;
let client = SessionClient::new(&backend.url, &headers()).unwrap();
let jwt = client.consume_login_token(" tok ").await.unwrap();
- assert_eq!(jwt, &*LIVE_JWT);
+ assert_eq!(jwt, *LIVE_JWT);
assert_eq!(backend.consume_calls(), vec![json!({ "token": "tok" })]);
let user = client
diff --git a/crates/openhuman-session/src/credential_tests.rs b/crates/openhuman-session/src/credential_tests.rs
index cabe84c212..0c6a17b86d 100644
--- a/crates/openhuman-session/src/credential_tests.rs
+++ b/crates/openhuman-session/src/credential_tests.rs
@@ -54,7 +54,7 @@ fn constructors_trim_and_keep_kind() {
assert_eq!(key.kind, CredentialKind::ApiKey);
assert_eq!(key.expires_at, None);
let local = Credential::local(format!(" {} ", &*LOCAL_TOKEN));
- assert_eq!(local.secret, &*LOCAL_TOKEN);
+ assert_eq!(local.secret, *LOCAL_TOKEN);
}
#[test]
diff --git a/crates/openhuman-session/src/manager_tests.rs b/crates/openhuman-session/src/manager_tests.rs
index 17e0d12272..dd26abba70 100644
--- a/crates/openhuman-session/src/manager_tests.rs
+++ b/crates/openhuman-session/src/manager_tests.rs
@@ -38,7 +38,7 @@ async fn login_with_token_exchanges_validates_and_stores() {
let stored = core.session().unwrap();
assert_eq!(stored.kind, "session");
- assert_eq!(stored.token, &*LIVE_JWT);
+ assert_eq!(stored.token, *LIVE_JWT);
assert_eq!(stored.user_id.as_deref(), Some("user-123"));
assert_eq!(stored.user.unwrap()["_id"], "user-123");
assert_eq!(identity::peek_user_id().as_deref(), Some("user-123"));
@@ -70,7 +70,9 @@ async fn expired_jwt_is_refused_locally_without_a_request() {
let core = FakeCore::new(&backend.url);
let m = manager(&core);
assert_eq!(
- m.store_session_token(&*EXPIRED_JWT, None).await.unwrap_err(),
+ m.store_session_token(&*EXPIRED_JWT, None)
+ .await
+ .unwrap_err(),
SessionError::Expired
);
assert_eq!(backend.me_calls(), 0);
diff --git a/crates/openhuman-session/src/test_support.rs b/crates/openhuman-session/src/test_support.rs
index 3caa6a79b5..5ea7549f62 100644
--- a/crates/openhuman-session/src/test_support.rs
+++ b/crates/openhuman-session/src/test_support.rs
@@ -24,11 +24,14 @@ pub static ENV_LOCK: AsyncMutex<()> = AsyncMutex::const_new(());
/// Unpadded base64url, enough to assemble unsigned JWT fixtures at runtime
/// (kept out of source as literals so secret scanners do not trip on them).
fn b64url(input: &[u8]) -> String {
- const ALPHABET: &[u8; 64] =
- b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+ const ALPHABET: &[u8; 64] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
let mut out = String::new();
for chunk in input.chunks(3) {
- let b = [chunk[0], *chunk.get(1).unwrap_or(&0), *chunk.get(2).unwrap_or(&0)];
+ let b = [
+ chunk[0],
+ *chunk.get(1).unwrap_or(&0),
+ *chunk.get(2).unwrap_or(&0),
+ ];
let n = (u32::from(b[0]) << 16) | (u32::from(b[1]) << 8) | u32::from(b[2]);
out.push(ALPHABET[(n >> 18) as usize & 63] as char);
out.push(ALPHABET[(n >> 12) as usize & 63] as char);
@@ -50,7 +53,10 @@ fn unsigned_jwt(claims: Value, signature: &str) -> String {
/// A JWT (alg none) with `sub`/`userId` = `user-123` and `exp` in 2100.
pub static LIVE_JWT: LazyLock<String> = LazyLock::new(|| {
- unsigned_jwt(json!({ "sub": "user-123", "userId": "user-123", "exp": 4102444800u64 }), "sig")
+ unsigned_jwt(
+ json!({ "sub": "user-123", "userId": "user-123", "exp": 4102444800u64 }),
+ "sig",
+ )
});
/// Same subject, `exp` in 2001.
pub static EXPIRED_JWT: LazyLock<String> =