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.
This commit is contained in:
Neil
2026-11-09 04:07:21 -08:00
parent 125d594560
commit 83d57790db
7 changed files with 75 additions and 2 deletions
@@ -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
})
}
+5
View File
@@ -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"
}
+2
View File
@@ -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.
+6 -1
View File
@@ -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' }
}
+26
View File
@@ -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'
})
})
})
+17
View File
@@ -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
}
}
@@ -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
}