Skip to content

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

test(e2e): extract auth state helpers into shared module

Steven Enamakel76d2766e6015
diff --git a/app/test/auth-state.test.ts b/app/test/auth-state.test.ts
new file mode 100644
index 0000000000..73a7be83a0
--- /dev/null
+++ b/app/test/auth-state.test.ts
@@ -0,0 +1,23 @@
+import { describe, expect, it } from 'vitest';
+
+import { authStateValue } from './e2e/helpers/auth-state';
+
+describe('authStateValue', () => {
+ it('unwraps the logged Outcome result from auth_get_state', () => {
+ const state = authStateValue({
+ result: {
+ result: { isAuthenticated: false, credential: undefined },
+ logs: ['session state fetched'],
+ },
+ });
+
+ expect(state.isAuthenticated).toBe(false);
+ });
+
+ it('accepts a bare auth DTO when the RPC operation has no log envelope', () => {
+ const state = authStateValue({ result: { isAuthenticated: true, credential: 'session' } });
+
+ expect(state.isAuthenticated).toBe(true);
+ expect(state.credential).toBe('session');
+ });
+});
diff --git a/app/test/e2e/specs/auth-access-control.spec.ts b/app/test/e2e/specs/auth-access-control.spec.ts
index bec2cb7aa5..004064e46e 100644
--- a/app/test/e2e/specs/auth-access-control.spec.ts
+++ b/app/test/e2e/specs/auth-access-control.spec.ts
@@ -24,6 +24,7 @@
import { waitForApp, waitForAppReady, waitForAuthBootstrap } from '../helpers/app-helpers';
import { callOpenhumanRpc, expectRpcOk } from '../helpers/core-rpc';
import { triggerAuthDeepLink } from '../helpers/deep-link-helpers';
+import { authStateValue, type AuthStateResponse } from '../helpers/auth-state';
import {
clickButton,
clickText,
@@ -195,23 +196,6 @@ async function performFullLogin(token = 'e2e-test-token') {
console.log(`[AuthAccess] Home page confirmed: found "${homeText}"`);
}
-/**
- * `AuthStateResponse` — `crates/openhuman-core/src/security/credentials/responses.rs`.
- *
- * `credential` is `skip_serializing_if = "Option::is_none"` on the Rust side,
- * so it is absent (not null) when signed out.
- */
-interface AuthStateResponse {
- isAuthenticated: boolean;
- userId?: string | null;
- credential?: 'session' | 'api-key' | 'local';
-}
-
-function authStateValue(state: { result?: unknown }): AuthStateResponse {
- const raw = (state.result ?? {}) as { value?: AuthStateResponse } & AuthStateResponse;
- return raw.value ?? raw;
-}
-
// ===========================================================================
// Test suite
// ===========================================================================