Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix(desktop): sign-in keeps an explicit OMNIRUSH_GATEWAY_URL after the server starts

ogsamrat9286ef752a1c
diff --git a/apps/desktop/electron/omnirush-account.mjs b/apps/desktop/electron/omnirush-account.mjs
index a2294bd3..1e063299 100644
--- a/apps/desktop/electron/omnirush-account.mjs
+++ b/apps/desktop/electron/omnirush-account.mjs
@@ -317,6 +317,10 @@ export function createDesktopOmniRushAccountStore({
// `X-OmniRush-Client: gui/<version>`; unset sends no header.
clientVersion = null,
}) {
+ // An explicit OMNIRUSH_GATEWAY_URL, read once here: the runtime deletes it
+ // from process.env when it starts the embedded server (runtime.mjs), and a
+ // later sign-in must still go to the server it named, not to omnirush.ai.
+ const explicitGatewayUrl = normalizeGatewayUrl(env.OMNIRUSH_GATEWAY_URL);
const clientHeader = guiClientHeaderValue(clientVersion);
/** fetchImpl with `X-OmniRush-Client` added to every account request. */
const send = clientHeader
@@ -704,7 +708,7 @@ export function createDesktopOmniRushAccountStore({
// OMNIRUSH_GATEWAY_URL, or OMNIRUSH_DEV_MODE=1 together with
// OMNIRUSH_LOCAL_API=1, points the account service at a local API.
const localApiSelected = env.OMNIRUSH_DEV_MODE === "1" && env.OMNIRUSH_LOCAL_API === "1";
- return normalizeGatewayUrl(env.OMNIRUSH_GATEWAY_URL)
+ return explicitGatewayUrl
?? normalizeGatewayUrl(await readMacKeychain(KEYCHAIN_SERVICES.gatewayUrl, platform, runSecurity))
?? (localApiSelected ? DEV_GATEWAY_URL : DEFAULT_GATEWAY_URL);
}
diff --git a/apps/desktop/electron/omnirush-account.test.mjs b/apps/desktop/electron/omnirush-account.test.mjs
index 3d0ed459..0132bcf2 100644
--- a/apps/desktop/electron/omnirush-account.test.mjs
+++ b/apps/desktop/electron/omnirush-account.test.mjs
@@ -132,6 +132,41 @@ test("an explicit OMNIRUSH_GATEWAY_URL always wins", async () => {
);
});
+test("OMNIRUSH_GATEWAY_URL is read when the store is created: deleting it later (the runtime does) keeps sign-in there", async () => {
+ const env = { OMNIRUSH_GATEWAY_URL: "https://staging.example/omnirush/v1" };
+ const requested = [];
+ const options = await storeOptions({
+ env,
+ fetchImpl: async (url) => {
+ requested.push(String(url));
+ return Response.json({ detail: "unavailable" }, { status: 503 });
+ },
+ });
+ const store = createDesktopOmniRushAccountStore(options);
+ // runtime.mjs clears the account variables before it starts the embedded server.
+ delete env.OMNIRUSH_GATEWAY_URL;
+ await assert.rejects(store.authorize({ gatewayUrl: undefined, deviceName: "Test Mac", openVerification: async () => undefined }));
+ assert.deepEqual(requested, ["https://staging.example/omnirush/device/authorize"]);
+ assert.equal((await store.status()).gatewayUrl, "https://staging.example/omnirush/v1");
+});
+
+test("without an override, sign-in goes to omnirush.ai even if one appears after startup", async () => {
+ const env = {};
+ const requested = [];
+ const options = await storeOptions({
+ env,
+ fetchImpl: async (url) => {
+ requested.push(String(url));
+ return Response.json({ detail: "unavailable" }, { status: 503 });
+ },
+ });
+ const store = createDesktopOmniRushAccountStore(options);
+ // The runtime copies a child environment into process.env; it never redirects the account service.
+ env.OMNIRUSH_GATEWAY_URL = "https://elsewhere.example/omnirush/v1";
+ await assert.rejects(store.authorize({ gatewayUrl: undefined, deviceName: "Test Mac", openVerification: async () => undefined }));
+ assert.deepEqual(requested, ["https://omnirush.ai/omnirush/device/authorize"]);
+});
+
test("profile lookup refreshes an expired device credential and persists the rotation", async () => {
const options = await storeOptions({
env: {