Skip to content

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

refactor(debug): extract core auth check into shared helper

Steven Enamakelfd35b9c15461
diff --git a/scripts/__tests__/debug-web-ui.test.mjs b/scripts/__tests__/debug-web-ui.test.mjs
index 91fc7dc28a..bd20bbea23 100644
--- a/scripts/__tests__/debug-web-ui.test.mjs
+++ b/scripts/__tests__/debug-web-ui.test.mjs
@@ -9,6 +9,7 @@ import {
ensureSignedInChat,
mergeChildEnv,
freePort,
+ isCoreAuthenticated,
isLoopback,
parseArgs,
runStamp,
@@ -16,6 +17,23 @@ import {
waitFor,
} from "../debug/web-ui-lib.mjs";
+test("isCoreAuthenticated reads the logged auth result envelope", () => {
+ assert.equal(
+ isCoreAuthenticated({
+ logs: ["session state fetched"],
+ result: { isAuthenticated: true },
+ }),
+ true,
+ );
+ assert.equal(
+ isCoreAuthenticated({
+ logs: ["session state fetched"],
+ result: { isAuthenticated: false },
+ }),
+ false,
+ );
+});
+
test("ensureSignedInChat opens the canonical chat route from an authenticated home", async () => {
let visible = false;
let navigatedTo;
diff --git a/scripts/debug/web-ui-lib.mjs b/scripts/debug/web-ui-lib.mjs
index 4401506a6f..86d152dd67 100644
--- a/scripts/debug/web-ui-lib.mjs
+++ b/scripts/debug/web-ui-lib.mjs
@@ -48,6 +48,11 @@ export function startCoreChild(startChild, core, corePort, launchSpec) {
);
}
+/** Whether a logged core RPC auth state reports an authenticated credential. */
+export function isCoreAuthenticated(authState) {
+ return authState?.isAuthenticated === true;
+}
+
/** Navigate an authenticated scripted session to chat when Home has no composer. */
export async function ensureSignedInChat(page, appOrigin) {
const composer = page.getByRole("textbox", { name: "Message input" });
diff --git a/scripts/debug/web-ui.mjs b/scripts/debug/web-ui.mjs
index 574b49e2d1..4df83d1837 100644
--- a/scripts/debug/web-ui.mjs
+++ b/scripts/debug/web-ui.mjs
@@ -25,6 +25,7 @@ import {
ensureSignedInChat,
coreLaunchSpec,
createCoreRpcClient,
+ isCoreAuthenticated,
freePort,
isLoopback,
mergeChildEnv,
@@ -157,30 +158,13 @@ async function signIn(page, rpc, appOrigin) {
await page.getByText("Welcome to OpenHuman").waitFor({ timeout: 120_000 });
log("signing in through the GitHub provider button (mock backend)…");
await page.getByRole("button", { name: "GitHub" }).click();
- let lastAuthState;
- try {
- await waitFor(
- async () => {
- lastAuthState = await rpc("openhuman.auth_get_state");
- return lastAuthState.isAuthenticated;
- },
- {
- timeoutMs: 120_000,
- what: "the core's authenticated state after mock sign-in",
- },
- );
- } catch (error) {
- const nested = lastAuthState?.result;
- log(
- `auth state diagnostic: ${JSON.stringify({
- response_keys: Object.keys(lastAuthState ?? {}),
- direct_is_authenticated: lastAuthState?.isAuthenticated === true,
- result_keys: Object.keys(nested ?? {}),
- nested_is_authenticated: nested?.isAuthenticated === true,
- })}`,
- );
- throw error;
- }
+ await waitFor(
+ async () => isCoreAuthenticated(await rpc("openhuman.auth_get_state")),
+ {
+ timeoutMs: 120_000,
+ what: "the core's authenticated state after mock sign-in",
+ },
+ );
await ensureSignedInChat(page, appOrigin);
}