From 83d57790db3bf3034bd606b4a1aa6fa2883a4297 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 9 Nov 2026 03:42:24 -0800 Subject: [PATCH] chore(cloud-integration): bake dev billing and control-plane URLs into integration builds config/cloud-build-defaults.json feeds an ORCA_CLOUD_BUILD_DEFAULTS define in main; packaged builds read no shell env. ORCA_BUILD_BILLING_API_URL / ORCA_BUILD_CLOUD_SANDBOX_URL override at build time, ORCA_BILLING_API_URL / ORCA_CLOUD_SANDBOX_URL at run time. Public endpoints only. --- config/build-plugins/cloud-build-defaults.ts | 13 ++++++++++ config/cloud-build-defaults.json | 5 ++++ electron.vite.config.ts | 2 ++ src/main/billing/billing-service.ts | 7 ++++- src/main/cloud-build-defaults.test.ts | 26 +++++++++++++++++++ src/main/cloud-build-defaults.ts | 17 ++++++++++++ .../hosted-sandbox/hosted-sandbox-install.ts | 7 ++++- 7 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 config/build-plugins/cloud-build-defaults.ts create mode 100644 config/cloud-build-defaults.json create mode 100644 src/main/cloud-build-defaults.test.ts create mode 100644 src/main/cloud-build-defaults.ts diff --git a/config/build-plugins/cloud-build-defaults.ts b/config/build-plugins/cloud-build-defaults.ts new file mode 100644 index 00000000000..c3629a53a81 --- /dev/null +++ b/config/build-plugins/cloud-build-defaults.ts @@ -0,0 +1,13 @@ +import { readFileSync } from 'node:fs' +import { resolve } from 'node:path' + +/** Integration-branch backends baked into main (packaged builds read no shell env); build-time env overrides the file. */ +export function cloudBuildDefaultsDefine(env: NodeJS.ProcessEnv = process.env): string { + const file: { billingApiUrl?: string; cloudSandboxUrl?: string } = JSON.parse( + readFileSync(resolve('config/cloud-build-defaults.json'), 'utf8') + ) + return JSON.stringify({ + billingApiUrl: env.ORCA_BUILD_BILLING_API_URL || file.billingApiUrl, + cloudSandboxUrl: env.ORCA_BUILD_CLOUD_SANDBOX_URL || file.cloudSandboxUrl + }) +} diff --git a/config/cloud-build-defaults.json b/config/cloud-build-defaults.json new file mode 100644 index 00000000000..b8046b75191 --- /dev/null +++ b/config/cloud-build-defaults.json @@ -0,0 +1,5 @@ +{ + "_comment": "Integration-branch only (stablyai/orca-private cloud/integration). Public dev endpoints baked into packaged builds; no secrets. ORCA_BUILD_BILLING_API_URL / ORCA_BUILD_CLOUD_SANDBOX_URL at build time, or ORCA_BILLING_API_URL / ORCA_CLOUD_SANDBOX_URL at run time, override them.", + "billingApiUrl": "https://orca-billing-dev.lovecast.workers.dev", + "cloudSandboxUrl": "https://orca-sandbox-control-dev.lovecast.workers.dev" +} diff --git a/electron.vite.config.ts b/electron.vite.config.ts index 6f3700a4962..be2335f490f 100644 --- a/electron.vite.config.ts +++ b/electron.vite.config.ts @@ -20,6 +20,7 @@ import { createPlainNodeEntryGuardPlugin } from './config/build-plugins/plain-no import { createDevServeConfig } from './config/build-plugins/dev-serve-config' import { reactPluginOptions } from './config/build-plugins/react-compiler' import { resolveBuildSourceCommit } from './config/scripts/build-identity/build-source-commit.mjs' +import { cloudBuildDefaultsDefine } from './config/build-plugins/cloud-build-defaults' const BUNDLED_MAIN_DEPENDENCIES = new Set([ 'stream-json', @@ -252,6 +253,7 @@ export const electronViteConfig: UserConfig = { ORCA_POSTHOG_WRITE_KEY: ORCA_POSTHOG_WRITE_KEY_LITERAL, ORCA_DIAGNOSTICS_TOKEN_URL: ORCA_DIAGNOSTICS_TOKEN_URL_LITERAL, ORCA_BUILD_COMMIT: ORCA_BUILD_COMMIT_LITERAL, + ORCA_CLOUD_BUILD_DEFAULTS: cloudBuildDefaultsDefine(), ...DARK_BUILD_DEFINES }, // @xterm/headless declares exports:null; point Vite directly at its published CJS main to permit inlining. diff --git a/src/main/billing/billing-service.ts b/src/main/billing/billing-service.ts index aac2bf8bbe4..7aba167f2ad 100644 --- a/src/main/billing/billing-service.ts +++ b/src/main/billing/billing-service.ts @@ -1,3 +1,4 @@ +import { withCloudBuildDefaults } from '../cloud-build-defaults' // Plan & billing for the active Orca profile's signed-in account. Results are values, never // throws, so the renderer can show a precise state. A billing-service refusal never signs the // user out; only Orca Cloud auth rejecting the session does (via runWithFreshOrcaCloudSession). @@ -37,7 +38,11 @@ function prepare(userDataPath: string): Ready { if (!auth.configured) { return { ok: false, status: 'unconfigured' } } - const endpoints = getBillingEndpoints(auth.config, process.env, app.isPackaged) + const endpoints = getBillingEndpoints( + auth.config, + withCloudBuildDefaults(process.env), + app.isPackaged + ) if (!endpoints) { return { ok: false, status: 'unconfigured' } } diff --git a/src/main/cloud-build-defaults.test.ts b/src/main/cloud-build-defaults.test.ts new file mode 100644 index 00000000000..87b734c4074 --- /dev/null +++ b/src/main/cloud-build-defaults.test.ts @@ -0,0 +1,26 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' +import { withCloudBuildDefaults } from './cloud-build-defaults' + +describe('withCloudBuildDefaults', () => { + afterEach(() => vi.unstubAllGlobals()) + + it('leaves env untouched when the build defines no defaults', () => { + expect(withCloudBuildDefaults({ ORCA_BILLING_API_URL: 'https://b.example' })).toMatchObject({ + ORCA_BILLING_API_URL: 'https://b.example', + ORCA_CLOUD_SANDBOX_URL: undefined + }) + }) + + it('fills unset URLs from the build and keeps run-time overrides', () => { + vi.stubGlobal('ORCA_CLOUD_BUILD_DEFAULTS', { + billingApiUrl: 'https://billing.dev.example', + cloudSandboxUrl: 'https://sandbox.dev.example' + }) + expect( + withCloudBuildDefaults({ ORCA_CLOUD_SANDBOX_URL: 'https://override.example' }) + ).toMatchObject({ + ORCA_BILLING_API_URL: 'https://billing.dev.example', + ORCA_CLOUD_SANDBOX_URL: 'https://override.example' + }) + }) +}) diff --git a/src/main/cloud-build-defaults.ts b/src/main/cloud-build-defaults.ts new file mode 100644 index 00000000000..395695a8d45 --- /dev/null +++ b/src/main/cloud-build-defaults.ts @@ -0,0 +1,17 @@ +// Packaged builds read no shell env, so the integration build bakes in its backend URLs +// (config/cloud-build-defaults.json via electron.vite.config.ts). Run-time env still wins. +declare const ORCA_CLOUD_BUILD_DEFAULTS: { billingApiUrl?: string; cloudSandboxUrl?: string } | null + +function buildDefaults(): { billingApiUrl?: string; cloudSandboxUrl?: string } { + // oxlint-disable-next-line unicorn/no-typeof-undefined -- undeclared outside electron-vite builds; a bare read throws. + return (typeof ORCA_CLOUD_BUILD_DEFAULTS === 'undefined' ? null : ORCA_CLOUD_BUILD_DEFAULTS) ?? {} +} + +export function withCloudBuildDefaults(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv { + const defaults = buildDefaults() + return { + ...env, + ORCA_BILLING_API_URL: env.ORCA_BILLING_API_URL?.trim() || defaults.billingApiUrl, + ORCA_CLOUD_SANDBOX_URL: env.ORCA_CLOUD_SANDBOX_URL?.trim() || defaults.cloudSandboxUrl + } +} diff --git a/src/main/hosted-sandbox/hosted-sandbox-install.ts b/src/main/hosted-sandbox/hosted-sandbox-install.ts index 4a60fc31849..844b4dfdc81 100644 --- a/src/main/hosted-sandbox/hosted-sandbox-install.ts +++ b/src/main/hosted-sandbox/hosted-sandbox-install.ts @@ -1,3 +1,4 @@ +import { withCloudBuildDefaults } from '../cloud-build-defaults' // Wires Orca Cloud into the desktop when this build has a control plane configured (off by default). import { app, BrowserWindow } from 'electron' import { ensureActiveOrcaProfile } from '../orca-profiles/profile-index-store' @@ -25,7 +26,11 @@ export function installHostedSandbox(): void { return } const userDataPath = app.getPath('userData') - const config = getHostedSandboxConfig(userDataPath, process.env, app.isPackaged) + const config = getHostedSandboxConfig( + userDataPath, + withCloudBuildDefaults(process.env), + app.isPackaged + ) if (!config) { return }