Skip to content

refactor(list): align all list commands to issue list standards#453

Merged
BYK merged 18 commits intomainfrom
refactor/align-list-commands
Mar 18, 2026
Merged

refactor(list): align all list commands to issue list standards#453
BYK merged 18 commits intomainfrom
refactor/align-list-commands

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 17, 2026

Summary

Aligns all list subcommands to the standards established by sentry issue list.

Key Changes

  1. sentry log list — trace-id as positional arg

    • Removed --trace flag entirely
    • Accept trace-id positionally: sentry log list <trace-id>, sentry log list <org>/<trace-id>
    • Added parseLogListArgs() with isTraceId() disambiguation (32-char hex → trace mode, otherwise project mode)
    • Added --period / -t flag (default 90d, trace mode auto-uses 14d)
    • JSON output now returns { data, hasMore } envelope instead of flat array
  2. withProgress spinner in all list commands

    • trace list, span list, trace logs, org list, trial list, project list
    • Added to org-list.ts framework so team list and repo list get spinners automatically
  3. JSON envelope alignment

    • trace logs now returns { data, hasMore } envelope
  4. Test improvements

    • Fixed pre-existing 5s timeout failures in dispatchOrgScopedList tests (missing resolveEffectiveOrg mock)
    • Complete rewrite of log/list.test.ts (49 tests)
    • Added isTraceId() tests to trace-id.test.ts

New helper

isTraceId(value: string): boolean — non-throwing check extracted from validateTraceId core logic. Used by log list for positional disambiguation.

Files changed (15)

File Change
src/lib/trace-id.ts Add isTraceId()
src/commands/log/list.ts Major: remove --trace, array positional, --period, withProgress, JSON envelope
src/commands/trace/list.ts Add withProgress
src/commands/span/list.ts Add withProgress
src/commands/trace/logs.ts Add withProgress + JSON envelope
src/commands/org/list.ts Add withProgress
src/commands/trial/list.ts Add withProgress
src/commands/project/list.ts Add withProgress
src/lib/org-list.ts Add withProgress to framework
test/ files Updated/new tests

betegon and others added 9 commits March 17, 2026 13:40
issue view with project-search format (e.g., `buybridge-5BS`) was
making 5 sequential HTTP calls totaling ~2.4s. The biggest overhead
was listOrganizations() (getUserRegions + listOrganizationsInRegion =
~800ms) inside findProjectsBySlug, even when DSN detection already
identified the project.

Two optimizations:

1. DSN-aware shortcut in resolveProjectSearch: after alias cache miss,
   check resolveFromDsn() for a matching project before falling back
   to findProjectsBySlug. Saves ~1200ms on cached runs, ~800ms first run.

2. Cached-orgs fast path in findProjectsBySlug: check org_regions
   cache before calling listOrganizations(). Saves ~800ms when org
   data is cached from any previous command.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add two targeted tests proving the performance optimizations work:

1. resolveIssue with project-search format uses DSN shortcut when
   the DSN-detected project matches, skipping the expensive
   listOrganizations() fan-out entirely.

2. findProjectsBySlug uses cached org_regions to skip
   getUserRegions() + listOrganizationsInRegion() when org data
   is already cached from a previous command.

Both tests verify the optimization by tracking HTTP requests and
asserting that /users/me/regions/ and /organizations/ are never
called.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. Narrow try/catch in resolveProjectSearch to only wrap resolveFromDsn().
   Previously getIssueByShortId errors (e.g. 404) were silently caught,
   causing a fallback to findProjectsBySlug which would duplicate the
   expensive short ID resolution call before failing with the same error.

2. Add comment explaining why the org_regions cache is expected to be
   complete when findProjectsBySlug runs: the project-search format's
   short suffix only comes from `sentry issue list` output, which
   already called listOrganizations() and populated all orgs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When the cached-orgs fast path finds no projects and falls through to
the full listOrganizations() path, avoid re-searching orgs that already
returned 404 by filtering them out with a Set lookup.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Instead of patching findProjectsBySlug with a per-callsite cache check,
move the caching into listOrganizations() so all 12 callers benefit:

- Add org_name column to org_regions table (schema v9)
- Split listOrganizations into cached + uncached variants:
  - listOrganizations() returns from SQLite cache when populated
  - listOrganizationsUncached() always hits the API (for org list,
    auth status, resolveEffectiveOrg)
- Add getCachedOrganizations() to db/regions.ts
- Simplify findProjectsBySlug back to single-path (no getAllOrgRegions
  fast-path needed — listOrganizations handles it)
- Update org list and auth status to use uncached variant
- Update resolveEffectiveOrg to use uncached (it explicitly refreshes)
getCachedOrganizations() now checks updated_at against a 7-day TTL.
Stale entries are ignored, forcing a fresh API fetch. This ensures
users who join new orgs see them within a bounded window without
needing to run --fresh or auth status.
- Self-hosted early return in listOrganizationsUncached now calls
  setOrgRegions before returning (Seer: cache was skipped)
- Add disableOrgCache() to db/regions.ts, called by applyFreshFlag
  so --fresh bypasses the org listing cache (BugBot: stale data)
- getCachedOrganizations returns empty when cache is disabled
- Add isTraceId() non-throwing boolean helper to trace-id.ts
- Rewrite log list: remove --trace flag, accept trace-id as positional
  arg (sentry log list <trace-id>, sentry log list <org>/<trace-id>),
  add --period/-t flag, JSON envelope { data, hasMore }
- Add withProgress spinner to all list commands: trace list, span list,
  trace logs, org list, trial list, project list, and org-list.ts
  framework (team/repo list get spinners automatically)
- Align trace logs JSON output to { data, hasMore } envelope
- Fix pre-existing 5s timeout failures in dispatchOrgScopedList tests
  by mocking resolveEffectiveOrg and withProgress
@github-actions
Copy link
Contributor

github-actions bot commented Mar 17, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • Improve error messages — fix ContextError/ResolutionError misuse by BYK in #456

Internal Changes 🔧

  • (list) Align all list commands to issue list standards by BYK in #453

🤖 This preview updates automatically when you update the PR.

@BYK BYK marked this pull request as ready for review March 17, 2026 23:51
…ommands

# Conflicts:
#	AGENTS.md
#	src/commands/org/list.ts
#	src/lib/api/organizations.ts
#	src/lib/db/regions.ts
#	src/lib/db/schema.ts
@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

Codecov Results 📊

116 passed | Total: 116 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1139 uncovered lines.
✅ Project coverage is 95.23%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
org-list.ts 95.74% ⚠️ 18 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.20%    95.23%    +0.03%
==========================================
  Files          175       175         —
  Lines        23729     23854      +125
  Branches         0         0         —
==========================================
+ Hits         22590     22715      +125
- Misses        1139      1139         —
- Partials         0         0         —

Generated by Codecov Action

…envelope

- Remove --trace flag usage from e2e tests, use positional trace-id
- Update JSON assertions to expect { data, hasMore } envelope
- Rename describe block from '--trace' to '(trace mode)'
BYK and others added 2 commits March 18, 2026 00:22
- Make --period flag optional (no default) to fix sentinel-value bug
  where explicit --period 90d was silently overridden to 14d in trace
  mode. Now undefined = not set, project mode defaults to 90d, trace
  mode defaults to 14d.
- Add json option to withProgress to suppress spinner in JSON mode,
  matching poll() behavior. Pass json: flags.json at all 19 call sites.
- parseLogListArgs now checks last arg for trace-id in 2+ arg case
  (e.g., 'sentry log list my-org <trace-id>')
- Move DEFAULT_PROJECT_PERIOD above JSDoc so it attaches correctly
  to executeSingleFetch
…ization

- All withProgress messages now show '(up to N)...' matching issue list
- Extract normalizeHexId() in hex-id.ts, use in both validateHexId and
  isTraceId to eliminate duplicated normalization logic
- validateTraceId now delegates through isTraceId's normalization path
Copy link

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@BYK BYK merged commit 629012c into main Mar 18, 2026
22 checks passed
@BYK BYK deleted the refactor/align-list-commands branch March 18, 2026 10:57
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.

2 participants