Skip to content

AIT-263: derive customer/billing org from the active workspace, not /workspaces row[0] - #35

Merged
ord669 merged 3 commits into
mainfrom
ait-263-cli-org-derivation
Jul 24, 2026
Merged

AIT-263: derive customer/billing org from the active workspace, not /workspaces row[0]#35
ord669 merged 3 commits into
mainfrom
ait-263-cli-org-derivation

Conversation

@ord669

@ord669 ord669 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

customers new + customers list picked the org from the cross-org /workspaces union's row[0], which for a user in 2+ orgs is nondeterministic and 403s when it disagrees with the token's org (backend can() requires path-org == token-org). Extracts a shared resolveOrgPublicIdForWorkspace helper (from billing's local version, minus the row[0] fallback), uses it in customers new, scopes customers list to the active org, and refactors billing onto the shared helper.

AIT-263

Summary by CodeRabbit

  • Bug Fixes

    • Customer listings now show only customers belonging to the active workspace’s organization.
    • New customers are created in the active workspace’s organization, preventing cross-organization misrouting.
    • Billing actions consistently use the active workspace when determining the billing destination.
    • Improved validation messaging when the active workspace cannot be resolved.
  • Tests

    • Added regression coverage for stale active workspace handling and multi-organization customer creation.
    • Updated billing tests to mock billing flows deterministically while preserving helper behavior.

…kspaces row[0]

customers new + customers list picked the org from the cross-org /workspaces
union's row[0], which for a user in 2+ orgs is nondeterministic and 403s when
it disagrees with the token's org (backend can() requires path-org==token-org).
Extract a shared resolveOrgPublicIdForWorkspace helper (from billing's local
version, minus the row[0] fallback), use it in customers new, and scope
customers list to the active org. billing refactored onto the shared helper.

AIT-263
@ord669

ord669 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8c2013a0-2d42-433c-9fbe-b0d7d6a2fbb3

📥 Commits

Reviewing files that changed from the base of the PR and between 885274a and 4b6cbc9.

📒 Files selected for processing (1)
  • src/commands/__tests__/billing.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/commands/tests/billing.test.ts

📝 Walkthrough

Walkthrough

Customer and billing commands now resolve organization identifiers from the active workspace. Customer listing filters by active organization, customer creation targets the active organization, and billing commands share centralized workspace resolution.

Changes

Active Workspace Organization Scoping

Layer / File(s) Summary
Shared workspace organization resolution
src/commands/_helpers.ts
Adds a helper that resolves an organization public ID from /workspaces and raises a validation error when unavailable.
Customer command organization scoping
src/commands/customers.ts, src/__tests__/customers.test.ts
Customer listing and creation use the active workspace organization, with tests covering configured and stale workspace state plus multi-organization selection.
Billing organization resolution
src/commands/billing.ts, src/commands/__tests__/billing.test.ts
Billing management, status, and upgrade flows use the shared resolver; tests preserve other helper exports while overriding the workspace ID.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: using the active workspace instead of /workspaces row[0] for org derivation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ait-263-cli-org-derivation

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 30880194cf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/commands/customers.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/commands/customers.ts`:
- Around line 40-45: Validate that activeOrg is resolved after finding the
workspace and before filtering customers; when it is absent, throw the existing
shared ValidationError used by the workspace/organization resolver. Keep the
current customer filter unchanged for valid organizations and ensure unresolved
or malformed organization data cannot produce results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9b72bca9-e217-4923-9bb3-3c4e7bb3fcd7

📥 Commits

Reviewing files that changed from the base of the PR and between 8fd6751 and 3088019.

📒 Files selected for processing (5)
  • src/__tests__/customers.test.ts
  • src/commands/__tests__/billing.test.ts
  • src/commands/_helpers.ts
  • src/commands/billing.ts
  • src/commands/customers.ts

Comment thread src/commands/customers.ts
@ord669

ord669 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 885274af8f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/commands/__tests__/billing.test.ts
@ord669
ord669 merged commit 203c5d4 into main Jul 24, 2026
3 checks passed
@ord669
ord669 deleted the ait-263-cli-org-derivation branch July 24, 2026 12:37
ord669 added a commit that referenced this pull request Aug 12, 2026
…workspaces row[0] (#35)

* fix(cli): derive customer/billing org from active workspace, not /workspaces row[0]

customers new + customers list picked the org from the cross-org /workspaces
union's row[0], which for a user in 2+ orgs is nondeterministic and 403s when
it disagrees with the token's org (backend can() requires path-org==token-org).
Extract a shared resolveOrgPublicIdForWorkspace helper (from billing's local
version, minus the row[0] fallback), use it in customers new, and scope
customers list to the active org. billing refactored onto the shared helper.

AIT-263

* fix: customers list throws the actionable error when the active workspace cannot resolve an org

* test: complete the api/client partial mock with setWorkspaceContext
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.

1 participant