From 5679739c9d295b5b11859f986c45abf5884ae061 Mon Sep 17 00:00:00 2001 From: VihaanAgarwal Date: Wed, 22 Jul 2026 11:27:35 -0700 Subject: [PATCH] fix(cli): publish the resolved dev org under every org env alias --- packages/cli/src/cmd/dev/index.ts | 30 +++++++++++++++---- packages/cli/test/cmd/dev/org-id.test.ts | 38 +++++++++++++++++++++++- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/packages/cli/src/cmd/dev/index.ts b/packages/cli/src/cmd/dev/index.ts index dca47eb20..c240000a5 100644 --- a/packages/cli/src/cmd/dev/index.ts +++ b/packages/cli/src/cmd/dev/index.ts @@ -68,6 +68,24 @@ export function resolveDevOrgId(options: ResolveDevOrgIdOptions): string | undef ); } +const DEV_ORG_ENV_ALIASES = [ + 'AGENTUITY_ORGID', + 'AGENTUITY_ORG_ID', + 'AGENTUITY_CLOUD_ORG_ID', +] as const; + +export function applyDevOrgEnv( + env: Record, + orgId: string | undefined +): void { + if (!orgId) return; + for (const name of DEV_ORG_ENV_ALIASES) { + if (!normalizeOrgId(env[name])) { + env[name] = orgId; + } + } +} + export const command = createCommand({ name: 'dev', description: 'Run the project development server', @@ -175,14 +193,14 @@ export const command = createCommand({ // Load agentuity.json (if present) so we can surface the project's // orgId to the dev process. The aigateway client and other service // clients accept orgId as a constructor option but otherwise have no - // way to pick it up under `agentuity dev`. Other parts of the platform - // (pi, coder-tui) already read AGENTUITY_ORGID from env, so we match - // that name here. + // way to pick it up under `agentuity dev`. Consumers read different + // subsets of the org env aliases (pi reads all of them, coder-tui + // reads AGENTUITY_ORGID and AGENTUITY_CLOUD_ORG_ID, the docs point + // apps at AGENTUITY_CLOUD_ORG_ID), so publish under every alias the + // developer has not already set. const projectConfig = await tryLoadProjectConfig(rootDir, config); const orgId = resolveDevOrgId({ env, projectConfig, config }); - if (orgId && !normalizeOrgId(env.AGENTUITY_ORGID)) { - env.AGENTUITY_ORGID = orgId; - } + applyDevOrgEnv(env, orgId); // Inject AI Gateway env vars so LLM SDKs route through Agentuity const gatewayInjected = injectGatewayEnv(env, logger); diff --git a/packages/cli/test/cmd/dev/org-id.test.ts b/packages/cli/test/cmd/dev/org-id.test.ts index 5119ee97f..65910dcbc 100644 --- a/packages/cli/test/cmd/dev/org-id.test.ts +++ b/packages/cli/test/cmd/dev/org-id.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from 'bun:test'; -import { resolveDevOrgId } from '../../../src/cmd/dev/index.ts'; +import { applyDevOrgEnv, resolveDevOrgId } from '../../../src/cmd/dev/index.ts'; describe('resolveDevOrgId', () => { test('prefers project org ID over env and config values', () => { @@ -49,3 +49,39 @@ describe('resolveDevOrgId', () => { ).toBe('org_alt'); }); }); + +describe('applyDevOrgEnv', () => { + test('publishes the resolved org under every org env alias', () => { + const env: Record = {}; + applyDevOrgEnv(env, 'org_project'); + expect(env.AGENTUITY_ORGID).toBe('org_project'); + expect(env.AGENTUITY_ORG_ID).toBe('org_project'); + expect(env.AGENTUITY_CLOUD_ORG_ID).toBe('org_project'); + }); + + test('preserves each alias the developer already set', () => { + const env: Record = { + AGENTUITY_ORG_ID: 'org_shell', + }; + applyDevOrgEnv(env, 'org_project'); + expect(env.AGENTUITY_ORGID).toBe('org_project'); + expect(env.AGENTUITY_ORG_ID).toBe('org_shell'); + expect(env.AGENTUITY_CLOUD_ORG_ID).toBe('org_project'); + }); + + test('overwrites blank aliases', () => { + const env: Record = { + AGENTUITY_ORGID: '', + AGENTUITY_CLOUD_ORG_ID: ' ', + }; + applyDevOrgEnv(env, 'org_project'); + expect(env.AGENTUITY_ORGID).toBe('org_project'); + expect(env.AGENTUITY_CLOUD_ORG_ID).toBe('org_project'); + }); + + test('does nothing without a resolved org', () => { + const env: Record = {}; + applyDevOrgEnv(env, undefined); + expect(env).toEqual({}); + }); +});