Skip to content

fix(cli): publish the resolved dev org under every org env alias - #1624

Open
VihaanAgarwal wants to merge 1 commit into
agentuity:mainfrom
VihaanAgarwal:fix/dev-org-env-aliases
Open

fix(cli): publish the resolved dev org under every org env alias#1624
VihaanAgarwal wants to merge 1 commit into
agentuity:mainfrom
VihaanAgarwal:fix/dev-org-env-aliases

Conversation

@VihaanAgarwal

@VihaanAgarwal VihaanAgarwal commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What broke

The org id travels under three env var names (AGENTUITY_ORGID, AGENTUITY_ORG_ID, AGENTUITY_CLOUD_ORG_ID) and consumers read different subsets: pi reads all of them, coder-tui reads AGENTUITY_ORGID and AGENTUITY_CLOUD_ORG_ID, and the docs point apps at AGENTUITY_CLOUD_ORG_ID. agentuity dev injects only AGENTUITY_ORGID, so an app reading either of the other names never sees the org that dev resolved, and a stale inherited AGENTUITY_ORG_ID from the developer's shell wins silently. That is the remaining bug from #1611 after the project-first resolution landed in #1508.

Fix

Extract the injection into applyDevOrgEnv, which publishes the resolved org under all three aliases, keeping the existing guard per name: a value the developer already set (non-blank) is never overwritten, matching the current behavior for AGENTUITY_ORGID. The pi org switcher already writes all the aliases when switching orgs, so this brings dev in line with that precedent.

The issue also suggests warning when an inherited alias disagrees with the resolved org. Left that out to keep this to one concern; happy to follow up if wanted.

Tests

Added applyDevOrgEnv cases to test/cmd/dev/org-id.test.ts: all aliases published, developer-set aliases preserved individually, blank aliases overwritten, no-op without a resolved org. bun test test/ in packages/cli: 775 pass (the one failure, upgrade version mismatch, is present on clean main). Format, lint, typecheck, build all green.

Fixes #1611

Summary by CodeRabbit

  • Bug Fixes
    • Improved development environment configuration by consistently setting the resolved organization ID across supported environment variable aliases.
    • Preserved existing non-empty environment values while replacing blank values.
    • Ensured no environment changes occur when an organization ID is unavailable.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The dev command now publishes a resolved organization ID through multiple AGENTUITY_* aliases while preserving nonblank existing values. Tests cover population, preservation, blank values, and undefined IDs.

Dev organization environment propagation

Layer / File(s) Summary
Organization environment alias helper
packages/cli/src/cmd/dev/index.ts, packages/cli/test/cmd/dev/org-id.test.ts
Adds applyDevOrgEnv and tests alias population, preservation, blank-value replacement, and no-op behavior.
Dev command integration
packages/cli/src/cmd/dev/index.ts
The dev handler resolves the organization ID and applies it across supported environment aliases.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The PR injects the resolved org ID into all three requested aliases and preserves existing non-blank values, matching #1611's core requirements.
Out of Scope Changes check ✅ Passed The changes stay focused on dev org env alias handling and matching tests, with no unrelated functionality added.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/cli/test/cmd/dev/org-id.test.ts (1)

62-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover preservation for every alias independently.

This test only pre-populates AGENTUITY_ORG_ID; it does not verify preservation of AGENTUITY_ORGID or AGENTUITY_CLOUD_ORG_ID. Add table-driven cases for all three aliases so a regression in one alias cannot pass unnoticed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/test/cmd/dev/org-id.test.ts` around lines 62 - 70, Expand the
test around applyDevOrgEnv to use table-driven cases that independently
pre-populate AGENTUITY_ORGID, AGENTUITY_ORG_ID, and AGENTUITY_CLOUD_ORG_ID, then
assert each existing alias value is preserved while unset aliases receive
org_project.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/cli/test/cmd/dev/org-id.test.ts`:
- Around line 62-70: Expand the test around applyDevOrgEnv to use table-driven
cases that independently pre-populate AGENTUITY_ORGID, AGENTUITY_ORG_ID, and
AGENTUITY_CLOUD_ORG_ID, then assert each existing alias value is preserved while
unset aliases receive org_project.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ae1d1cca-8f42-4da6-9697-73bc4b2840ae

📥 Commits

Reviewing files that changed from the base of the PR and between 70ddfa5 and 5679739.

📒 Files selected for processing (2)
  • packages/cli/src/cmd/dev/index.ts
  • packages/cli/test/cmd/dev/org-id.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (18)
  • GitHub Check: Native install (macOS)
  • GitHub Check: Linux distro install smoke
  • GitHub Check: Native install (Linux)
  • GitHub Check: Bun version checks
  • GitHub Check: Installer scenarios
  • GitHub Check: Windows WSL CLI Smoke Test
  • GitHub Check: Build
  • GitHub Check: Pack & Upload
  • GitHub Check: Service Client Smoke Tests
  • GitHub Check: Queue CLI Tests (node)
  • GitHub Check: Package Installation & Usage Test (node)
  • GitHub Check: Queue CLI Tests (bun)
  • GitHub Check: Postgres SSL Integration Test
  • GitHub Check: Package Installation & Usage Test (bun)
  • GitHub Check: Testing Apps (local tests)
  • GitHub Check: Framework Demo Tests
  • GitHub Check: Migrate Chain (v1 → v2 → v3)
  • GitHub Check: OSV Scanner PR
⚠️ CI failures not shown inline (2)

GitHub Actions: Gitleaks Scan / 0_Gitleaks Secret Scan.txt: fix(cli): publish the resolved dev org under every org env alias

Conclusion: failure

View job details

##[group]Run gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7
 env:
   GITHUB_***REDACTED***
   GITLEAKS_LICENSE:
 ##[endgroup]
 (node:2418) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
 (Use `node --trace-deprecation ...` to show where the warning was created)
 (node:2418) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
 [agentuity] is an organization. License key is required.
 ##[error]🛑 missing gitleaks license. Go grab one at gitleaks.io and store it as a GitHub Secret named GITLEAKS_LICENSE. For more info about the recent breaking update, see [here](https://github.com/gitleaks/gitleaks-action#-announcement).

GitHub Actions: Gitleaks Scan / Gitleaks Secret Scan: fix(cli): publish the resolved dev org under every org env alias

Conclusion: failure

View job details

##[group]Run gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7
 env:
   GITHUB_***REDACTED***
   GITLEAKS_LICENSE:
 ##[endgroup]
 (node:2418) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
 (Use `node --trace-deprecation ...` to show where the warning was created)
 (node:2418) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
 [agentuity] is an organization. License key is required.
 ##[error]🛑 missing gitleaks license. Go grab one at gitleaks.io and store it as a GitHub Secret named GITLEAKS_LICENSE. For more info about the recent breaking update, see [here](https://github.com/gitleaks/gitleaks-action#-announcement).
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Run bun run format using Biome with tabs (width 3), single quotes, semicolons, lineWidth 100, and trailingCommas es5

Files:

  • packages/cli/test/cmd/dev/org-id.test.ts
  • packages/cli/src/cmd/dev/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript in strict mode with ESNext target and bundler moduleResolution
Use StructuredError from @agentuity/core for error handling

Files:

  • packages/cli/test/cmd/dev/org-id.test.ts
  • packages/cli/src/cmd/dev/index.ts
**/packages/*/test/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/packages/*/test/**/*.{ts,tsx}: Place tests in test/ folder parallel to src/ directory, never inside src/ or under __tests__/
Import from ../src/ in test files
Use @agentuity/test-utils for shared mocks in tests

Files:

  • packages/cli/test/cmd/dev/org-id.test.ts
packages/cli/src/cmd/**/index.ts

📄 CodeRabbit inference engine (packages/cli/AGENTS.md)

packages/cli/src/cmd/**/index.ts: Each command must be a directory in src/cmd/ with an index.ts entry point
Always define interfaces for command options using Zod schemas; never use any for type safety

Files:

  • packages/cli/src/cmd/dev/index.ts
packages/cli/src/**/*.ts

📄 CodeRabbit inference engine (packages/cli/AGENTS.md)

packages/cli/src/**/*.ts: Use tui.* helpers for formatted output (header, info, success, warning, error, table, progress)
Use ctx.logger for logging; logger.fatal() logs and exits with code 1
Use await readFile(p, 'utf-8') and await writeFile(p, content) from node:fs/promises for file I/O
Import pathExists from node-compat/fs for file existence checks instead of using Node's built-in
Do not use Bun globals (Bun.file, Bun.spawn, Bun.color, Bun.stringWidth, etc.) in production source code; tsconfig.json type checking enforces this
Imports must use explicit .ts extensions for relative paths (e.g., from './foo.ts', not from './foo'); TypeScript's rewriteRelativeImportExtensions will rewrite them to .js in output
Always check isJSONMode() for machine-readable output in command handlers
Use requireAuth(ctx) or optionalAuth(ctx) for authenticated commands

Files:

  • packages/cli/src/cmd/dev/index.ts
🧠 Learnings (3)
📚 Learning: 2025-12-21T00:31:41.858Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 274
File: packages/cli/src/cmd/build/vite/server-bundler.ts:12-41
Timestamp: 2025-12-21T00:31:41.858Z
Learning: In Bun runtime, BuildMessage and ResolveMessage are global types and are not exported from the bun module. Do not import { BuildMessage } from 'bun' or similar; these types are available globally and should be used without import. This applies to all TypeScript files that target the Bun runtime within the repository.

Applied to files:

  • packages/cli/test/cmd/dev/org-id.test.ts
  • packages/cli/src/cmd/dev/index.ts
📚 Learning: 2026-02-21T02:05:57.982Z
Learnt from: jhaynie
Repo: agentuity/sdk PR: 1010
File: packages/drizzle/test/proxy.test.ts:594-603
Timestamp: 2026-02-21T02:05:57.982Z
Learning: Do not rely on StructuredError from agentuity/core in test files or simple error handling paths. In tests and straightforward error handling, use plain Error objects to represent failures, reserving StructuredError for more complex error scenarios in application logic.

Applied to files:

  • packages/cli/test/cmd/dev/org-id.test.ts
📚 Learning: 2026-02-17T14:23:15.448Z
Learnt from: potofpie
Repo: agentuity/sdk PR: 974
File: packages/cli/src/cmd/git/account/list.ts:39-40
Timestamp: 2026-02-17T14:23:15.448Z
Learning: In the Agentuity CLI framework (packages/cli), when a subcommand declares requires: { auth: true }, the framework will automatically call requireAuth() before invoking the handler. Do not call requireAuth(ctx) manually inside command handlers. This applies to all TypeScript command files under packages/cli/src, including paths like packages/cli/src/cmd/git/account/list.ts.

Applied to files:

  • packages/cli/src/cmd/dev/index.ts
🔇 Additional comments (3)
packages/cli/src/cmd/dev/index.ts (2)

71-88: LGTM!


196-203: LGTM!

packages/cli/test/cmd/dev/org-id.test.ts (1)

2-2: LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agentuity dev injects the wrong org env

1 participant