Skip to content

fix: 3 bug fixes — test env isolation, event pagination, pagination crash guard#947

Draft
cursor[bot] wants to merge 3 commits intomainfrom
cursor/sentry-cli-bug-fixes-7969
Draft

fix: 3 bug fixes — test env isolation, event pagination, pagination crash guard#947
cursor[bot] wants to merge 3 commits intomainfrom
cursor/sentry-cli-bug-fixes-7969

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 11, 2026

Summary

Three independent bug fixes discovered through codebase analysis and test failure investigation.


1. fix(test): complete env isolation in terminalLink tests

Root cause: The withTTY helper in colors.test.ts only saved/restored SENTRY_PLAIN_OUTPUT and process.stdout.isTTY, but did not clear NO_COLOR or FORCE_COLOR. In CI environments (or any shell with NO_COLOR set), isPlainOutput() returns true at the NO_COLOR check before reaching the TTY fallback, causing terminalLink to return plain text.

Reproduction: Run NO_COLOR=1 bun test ./test/lib/formatters/colors.test.ts — two terminalLink TTY tests fail.

Fix: Save/restore NO_COLOR and FORCE_COLOR alongside SENTRY_PLAIN_OUTPUT in the withTTY helper.


2. fix(events): drop nextCursor when trimming listIssueEvents results

Root cause: listIssueEvents() auto-paginates through the API and trims results to limit. When trimming, it preserved nextCursor — but that cursor points to the next API page, skipping the un-trimmed tail of the current batch. This causes events to be lost during cursor-based pagination.

Reproduction: Call listIssueEvents with a limit smaller than the API page size for an issue with many events — subsequent -c next navigation skips events between the trim point and the next API page boundary.

Fix: Drop nextCursor when trimming, matching the existing correct behavior of listIssuesAllPages in issues.ts (lines 253-257).


3. fix(pagination): guard JSON.parse of cursor_stack against corrupt data

Root cause: getPaginationState() calls JSON.parse(row.cursor_stack) on data read from SQLite without a try/catch. If the stored JSON is corrupt (partial write, manual edit, incompatible migration), the CLI crashes with an unhandled SyntaxError.

Reproduction: Manually corrupt the cursor_stack column in the pagination_cursors table, then run any command with --cursor next.

Fix: Wrap JSON.parse in try/catch. On failure, log a debug message, delete the corrupt row, and return undefined — the user continues from a fresh first page instead of a hard crash.

Open in Web View Automation 

cursoragent and others added 3 commits May 11, 2026 12:13
The withTTY helper only saved/restored SENTRY_PLAIN_OUTPUT and isTTY,
but did not clear NO_COLOR or FORCE_COLOR. In environments where
NO_COLOR is set (e.g., CI), isPlainOutput() returns true before
reaching the TTY check, causing terminalLink to return plain text
and two tests to fail.

Save/restore NO_COLOR and FORCE_COLOR alongside SENTRY_PLAIN_OUTPUT
so the tests exercise the actual OSC 8 code path regardless of
the outer environment.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
When auto-paginating issue events and the accumulated results exceed
the requested limit, the function trimmed the array but preserved
nextCursor. That cursor points to the next API page, skipping the
untrimmed tail of the current batch — causing events to be lost
during cursor-based pagination.

Drop nextCursor when trimming, matching the existing behavior of
listIssuesAllPages in issues.ts which correctly returns no cursor
when results are trimmed.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
getPaginationState() calls JSON.parse on cursor_stack from SQLite
without a try/catch. If the stored JSON is corrupt (partial write,
manual edit, incompatible migration), the CLI crashes with an
unhandled SyntaxError instead of degrading gracefully.

Wrap JSON.parse in try/catch. On parse failure, log a debug message,
delete the corrupt row, and return undefined (treating it as no
saved state). This lets the user continue navigating from a fresh
first page rather than being stuck with a hard crash.

Co-authored-by: Miguel Betegón <miguelbetegongarcia@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊

6856 passed | Total: 6856 | 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 35.29%. Project has 14050 uncovered lines.
✅ Project coverage is 76.97%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/lib/db/pagination.ts 50.00% ⚠️ 6 Missing
src/lib/api/events.ts 0.00% ⚠️ 5 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    76.97%    76.97%        —%
==========================================
  Files          319       319         —
  Lines        60994     61003        +9
  Branches         0         0         —
==========================================
+ Hits         46947     46953        +6
- Misses       14047     14050        +3
- Partials         0         0         —

Generated by Codecov Action

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