From 27a0e774d8a5ab379f48972f5f799a4f14a3506b Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 9 Sep 2026 00:21:03 -0700 Subject: [PATCH 1/3] test(web): cover production CodeRouter login origin --- web/tests/cli-config-route.test.ts | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/web/tests/cli-config-route.test.ts b/web/tests/cli-config-route.test.ts index d7feba6daae9..7af57952eb3f 100644 --- a/web/tests/cli-config-route.test.ts +++ b/web/tests/cli-config-route.test.ts @@ -48,6 +48,35 @@ async function withCliConfigEnvironment( } describe("CLI config route", () => { + test("uses cmux.com for production CodeRouter browser auth and preserves the login code", async () => { + await withCliConfigEnvironment(testEnvironment, async () => { + const response = GET( + new Request("https://coderouter.dev/api/cli/config"), + ); + + expect(response.status).toBe(200); + const body = await response.json(); + expect(body.auth.confirmUrl).toBe( + "https://cmux.com/handler/cli-auth-confirm", + ); + expect(body.coderouter.sessionUrl).toBe( + "https://coderouter.dev/api/coderouter/session", + ); + expect(body.coderouter.openaiBaseUrl).toBe("https://coderouter.dev/v1"); + + const confirmation = new URL(body.auth.confirmUrl); + confirmation.searchParams.set("login_code", "fresh-test-login-code"); + const signIn = new URL("https://cmux.com/handler/sign-in"); + signIn.searchParams.set( + "after_auth_return_to", + `${confirmation.pathname}${confirmation.search}`, + ); + expect(signIn.toString()).toBe( + "https://cmux.com/handler/sign-in?after_auth_return_to=%2Fhandler%2Fcli-auth-confirm%3Flogin_code%3Dfresh-test-login-code", + ); + }); + }); + test("publishes CodeRouter and the hosted Subrouter POST contract", async () => { await withCliConfigEnvironment(testEnvironment, async () => { const response = GET(new Request("https://cmux.com/api/cli/config")); @@ -128,6 +157,23 @@ describe("CLI config route", () => { }); }); + test("keeps confirmation on a custom staging origin", async () => { + await withCliConfigEnvironment(testEnvironment, async () => { + const response = GET( + new Request("https://coderouter-staging.example.test/api/cli/config"), + ); + + expect(response.status).toBe(200); + const body = await response.json(); + expect(body.auth.confirmUrl).toBe( + "https://coderouter-staging.example.test/handler/cli-auth-confirm", + ); + expect(body.coderouter.sessionUrl).toBe( + "https://coderouter-staging.example.test/api/coderouter/session", + ); + }); + }); + test("returns 503 instead of advertising incomplete Stack configuration", async () => { await withCliConfigEnvironment( { From 726bdb97a4df765c74d66590c8605fe4b39c54e1 Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 9 Sep 2026 00:22:44 -0700 Subject: [PATCH 2/3] fix(web): send CodeRouter login through cmux.com --- web/app/api/cli/config/route.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/web/app/api/cli/config/route.ts b/web/app/api/cli/config/route.ts index 5ebe585dc2c1..b2c8e38ea70f 100644 --- a/web/app/api/cli/config/route.ts +++ b/web/app/api/cli/config/route.ts @@ -5,6 +5,10 @@ import { const DEFAULT_STACK_API_URL = "https://api.stack-auth.com/api/v1"; +const PRODUCTION_CODEROUTER_HOSTS = new Set([ + "coderouter.dev", + "www.coderouter.dev", +]); // This metadata is informational for now. Keep the legacy `version` field // below for clients that already consume the config response, and do not gate @@ -45,7 +49,7 @@ export function GET(request: Request): Response { publishableClientKey, // Start and complete the CLI login against the same deployment so the // confirmation page uses the Stack project that issued the login code. - confirmUrl: new URL("/handler/cli-auth-confirm", request.url).toString(), + confirmUrl: cliAuthConfirmationURL(request), }, coderouter: { sessionUrl: new URL("/api/coderouter/session", request.url).toString(), @@ -74,6 +78,23 @@ export function GET(request: Request): Response { ); } +/** + * Keep the CodeRouter data plane on its dedicated host while sending browser + * sign-in through cmux.com's canonical auth surface. The Stack login code is + * issued by the same deployment and remains in the CLI confirmation query. + * Non-production and explicitly configured hosts stay on their own origin. + */ +function cliAuthConfirmationURL(request: Request): string { + const url = new URL("/handler/cli-auth-confirm", request.url); + if ( + url.protocol === "https:" && + PRODUCTION_CODEROUTER_HOSTS.has(url.hostname) + ) { + url.hostname = "cmux.com"; + } + return url.toString(); +} + function unavailableResponse(): Response { return Response.json( { error: "cli_auth_unavailable" }, From 71cf9c5ccc003cad5e1fee205e8a3ad0d038726a Mon Sep 17 00:00:00 2001 From: austinpower1258 Date: Wed, 9 Sep 2026 00:33:16 -0700 Subject: [PATCH 3/3] fix(web): canonicalize CodeRouter auth port --- web/app/api/cli/config/route.ts | 1 + web/tests/cli-config-route.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/web/app/api/cli/config/route.ts b/web/app/api/cli/config/route.ts index b2c8e38ea70f..7f9263185abb 100644 --- a/web/app/api/cli/config/route.ts +++ b/web/app/api/cli/config/route.ts @@ -91,6 +91,7 @@ function cliAuthConfirmationURL(request: Request): string { PRODUCTION_CODEROUTER_HOSTS.has(url.hostname) ) { url.hostname = "cmux.com"; + url.port = ""; } return url.toString(); } diff --git a/web/tests/cli-config-route.test.ts b/web/tests/cli-config-route.test.ts index 7af57952eb3f..30c3f51f32b5 100644 --- a/web/tests/cli-config-route.test.ts +++ b/web/tests/cli-config-route.test.ts @@ -64,6 +64,17 @@ describe("CLI config route", () => { ); expect(body.coderouter.openaiBaseUrl).toBe("https://coderouter.dev/v1"); + const nonDefaultPortResponse = GET( + new Request("https://coderouter.dev:4443/api/cli/config"), + ); + const nonDefaultPortBody = await nonDefaultPortResponse.json(); + expect(nonDefaultPortBody.auth.confirmUrl).toBe( + "https://cmux.com/handler/cli-auth-confirm", + ); + expect(nonDefaultPortBody.coderouter.sessionUrl).toBe( + "https://coderouter.dev:4443/api/coderouter/session", + ); + const confirmation = new URL(body.auth.confirmUrl); confirmation.searchParams.set("login_code", "fresh-test-login-code"); const signIn = new URL("https://cmux.com/handler/sign-in");