Skip to content

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

test: report mock auth response status on login failure

Steven Enamakeld414143559af
diff --git a/app/test/e2e/helpers/shared-flows.ts b/app/test/e2e/helpers/shared-flows.ts
index 8b5ba02156..4dd052e8db 100644
--- a/app/test/e2e/helpers/shared-flows.ts
+++ b/app/test/e2e/helpers/shared-flows.ts
@@ -948,7 +948,7 @@ export async function performFullLogin(
// reached the mock but failed to complete.
const authRequests = getRequestLog()
.filter(entry => typeof entry.url === 'string' && entry.url.startsWith('/auth/'))
- .map(entry => `${entry.method} ${entry.url.split('?')[0]}`);
+ .map(entry => `${entry.method} ${entry.url.split('?')[0]} -> ${entry.status ?? 'pending'}`);
console.error(
`${logPrefix} auth bootstrap failed; mock auth endpoints=${JSON.stringify(authRequests)}`
);
diff --git a/scripts/mock-api/routes/__tests__/auth.test.mjs b/scripts/mock-api/routes/__tests__/auth.test.mjs
index 38ea7b026f..4300c01ac9 100644
--- a/scripts/mock-api/routes/__tests__/auth.test.mjs
+++ b/scripts/mock-api/routes/__tests__/auth.test.mjs
@@ -1,7 +1,13 @@
import assert from "node:assert/strict";
import test from "node:test";
-import { resetMockBehavior, startMockServer, stopMockServer } from "../../index.mjs";
+import {
+ clearRequestLog,
+ getRequestLog,
+ resetMockBehavior,
+ startMockServer,
+ stopMockServer,
+} from "../../index.mjs";
import { loopbackSignInRedirect } from "../auth.mjs";
import { MOCK_JWT } from "../../state.mjs";
@@ -19,7 +25,10 @@ test("signs a loopback redirectUri back in with a session JWT and the echoed sta
"/auth/github/login?redirectUri=http%3A%2F%2Flocalhost%3A1420%2F__dev-auth&state=nonce-1",
);
const target = new URL(location);
- assert.equal(target.origin + target.pathname, "http://localhost:1420/__dev-auth");
+ assert.equal(
+ target.origin + target.pathname,
+ "http://localhost:1420/__dev-auth",
+ );
assert.equal(target.searchParams.get("token"), MOCK_JWT);
assert.equal(target.searchParams.get("key"), "auth");
assert.equal(target.searchParams.get("state"), "nonce-1");
@@ -28,16 +37,21 @@ test("signs a loopback redirectUri back in with a session JWT and the echoed sta
test("ignores a missing, non-loopback or non-http redirectUri", () => {
assert.equal(loopbackSignInRedirect("/auth/github/login"), null);
assert.equal(
- loopbackSignInRedirect("/auth/github/login?redirectUri=http%3A%2F%2Fevil.example%2Fcb"),
+ loopbackSignInRedirect(
+ "/auth/github/login?redirectUri=http%3A%2F%2Fevil.example%2Fcb",
+ ),
null,
);
assert.equal(
- loopbackSignInRedirect("/auth/github/login?redirectUri=openhuman%3A%2F%2Fauth"),
+ loopbackSignInRedirect(
+ "/auth/github/login?redirectUri=openhuman%3A%2F%2Fauth",
+ ),
null,
);
});
test("serves the provider-login redirect and the /health probe", async () => {
+ clearRequestLog();
const started = await startMockServer(18576, { retryIfInUse: true });
const baseUrl = `http://127.0.0.1:${started.port}`;
@@ -46,14 +60,35 @@ test("serves the provider-login redirect and the /health probe", async () => {
{ redirect: "manual" },
);
assert.equal(login.status, 302);
- assert.match(login.headers.get("location"), /^http:\/\/127\.0\.0\.1:5173\/__dev-auth\?token=/);
+ assert.match(
+ login.headers.get("location"),
+ /^http:\/\/127\.0\.0\.1:5173\/__dev-auth\?token=/,
+ );
// Without a redirectUri the legacy mock-oauth page is unchanged.
- const legacy = await fetch(`${baseUrl}/auth/github/login`, { redirect: "manual" });
+ const legacy = await fetch(`${baseUrl}/auth/github/login`, {
+ redirect: "manual",
+ });
assert.equal(legacy.status, 302);
assert.equal(legacy.headers.get("location"), `${baseUrl}/mock-oauth`);
const health = await fetch(`${baseUrl}/health`);
assert.equal(health.status, 200);
assert.deepEqual(await health.json(), { status: "ok" });
+ assert.deepEqual(
+ getRequestLog().map(({ method, url, status }) => ({
+ method,
+ path: url,
+ status,
+ })),
+ [
+ {
+ method: "GET",
+ path: "/auth/github/login?redirectUri=http%3A%2F%2F127.0.0.1%3A5173%2F__dev-auth",
+ status: 302,
+ },
+ { method: "GET", path: "/auth/github/login", status: 302 },
+ { method: "GET", path: "/health", status: 200 },
+ ],
+ );
});
diff --git a/scripts/mock-api/server.mjs b/scripts/mock-api/server.mjs
index 6964db3c3b..00cefc2bef 100644
--- a/scripts/mock-api/server.mjs
+++ b/scripts/mock-api/server.mjs
@@ -75,12 +75,16 @@ async function handleRequest(req, res) {
const parsedBody = tryParseJson(body);
const origin = requestOrigin(req);
- appendRequest({
+ const requestLogEntry = {
method,
url,
body,
headers: normalizeHeaders(req.headers),
timestamp: Date.now(),
+ };
+ appendRequest(requestLogEntry);
+ res.once("finish", () => {
+ requestLogEntry.status = res.statusCode;
});
if (method === "OPTIONS") {