Skip to content

fix(cli): return org slug, not display name, from org resolution#1232

Merged
John-David Dalton (jdalton) merged 1 commit intomainfrom
fix/cli-org-prompt-slug
Apr 21, 2026
Merged

fix(cli): return org slug, not display name, from org resolution#1232
John-David Dalton (jdalton) merged 1 commit intomainfrom
fix/cli-org-prompt-slug

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 18, 2026

The bug

Orgs whose display name differs from the slug (most obviously, names with spaces like "Example Org Ltd" vs slug example-org-ltd) produced broken API URLs when the CLI picked the org automatically or prompted the user to pick one:

GET /v0/orgs/Example%20Org%20Ltd/full-scans   → 404
GET /v0/orgs/example-org-ltd/full-scans       → 200

Two call sites were returning .name when they should have been returning .slug.

Fix

commands/scan/suggest-org-slug.mts — interactive prompt. Visible label and description still use the friendlier display name; the choice value now carries the slug. User sees "Example Org Ltd", we route with "example-org-ltd".

commands/ci/fetch-default-org-slug.mts — CI auto-resolve. No longer reads .name from the first org; uses .slug. Also dropped the Object.keys(organizations)[0] indirection since fetchOrganization already returns an array via Object.values.

Tests

  • Added regression guards in both test files exercising the name/slug-differ pattern with a dummy "Example Org Ltd" / example-org-ltd fixture.
  • Fixed the pre-existing fetches from API test in fetch-default-org-slug.test.mts — it mocked organizations as a dict but the real shape is an array, and asserted the buggy display-name return value. Now asserts slug.
  • Renamed returns error when organization has no namereturns error when organization has no slug with a matching mock payload. The new defensive check guards against a missing slug, not a missing name.

Test plan

  • pnpm run type clean
  • pnpm --filter @socketsecurity/cli run test:unit — 339 files / 5106 tests pass
  • pnpm run build:cli succeeds
  • CI green

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7f39ca3. Configure here.

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7f39ca3. Configure here.

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7f39ca3. Configure here.

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7f39ca3. Configure here.

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7f39ca3. Configure here.

@jdalton
Copy link
Copy Markdown
Contributor Author

Cursor (@cursor) review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7f39ca3. Configure here.

Comment thread packages/cli/src/commands/ci/fetch-default-org-slug.mts Outdated
navayla777-dotcom

This comment was marked as abuse.

Copy link
Copy Markdown

@billxinli Bill Li (billxinli) left a comment

Choose a reason for hiding this comment

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

LGTM, just a question about the inline comment

Orgs whose display name differs from the slug (e.g. a name with
spaces like "Example Org Ltd" vs slug "example-org-ltd") produced
broken API URLs like `/v0/orgs/Example%20Org%20Ltd/full-scans`
that 404'd. The CLI returned `.name` in two paths where it should
have returned `.slug`.

Fixed both call sites:

  * commands/scan/suggest-org-slug.mts — interactive prompt now
    uses the display name for the visible label/description but
    sets the choice `value` to the slug. User sees the friendly
    name, API calls route by slug.

  * commands/ci/fetch-default-org-slug.mts — CI auto-resolve no
    longer reads `.name` from the first org. Uses `.slug`. Also
    simplified iteration: fetchOrganization already returns an
    array via Object.values, so the previous
    Object.keys(organizations)[0] indirection was meaningless.

Tests:
  * Added regression coverage in both test files for the
    name-differs-from-slug case using the dummy "Example Org Ltd"
    fixture.
  * Fixed the pre-existing "fetches from API" test in
    fetch-default-org-slug.test.mts — it mocked organizations as
    a dict but the real shape is an array, and asserted the buggy
    display-name return value. Now asserts slug.
  * Renamed "returns error when organization has no name" to
    "returns error when organization has no slug" with a matching
    mock payload — the new defensive check guards against missing
    slug, not missing name.
@jdalton John-David Dalton (jdalton) merged commit f479f27 into main Apr 21, 2026
13 checks passed
@jdalton John-David Dalton (jdalton) deleted the fix/cli-org-prompt-slug branch April 21, 2026 22:41
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.

3 participants