Skip to content

fix(test): fix CI hang, auth guard tests, and PR #610 test rewrite#616

Merged
betegon merged 1 commit into
mainfrom
fix/ci-hang-and-auth-guard-tests
Mar 31, 2026
Merged

fix(test): fix CI hang, auth guard tests, and PR #610 test rewrite#616
betegon merged 1 commit into
mainfrom
fix/ci-hang-and-auth-guard-tests

Conversation

@betegon

@betegon betegon commented Mar 31, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the CI unit test hang and ~200 test failures caused by three merged PRs (#610, #611). Supersedes #612 with a cleaner approach.

1. CI Hang — telemetry beforeExit handler leak

initSentry(false) in test afterEach hooks never cleaned up the beforeExit handler registered by a prior initSentry(true) call — the removal was gated on client?.getOptions().enabled. SDK-internal handlers from enableLogs and sendClientReports also accumulated on re-init.

Fix (src/lib/telemetry.ts):

  • Close previous Sentry client before re-init (Sentry.getClient()?.close(0))
  • Move handler removal outside the enabled guard
  • Gate enableLogs and sendClientReports on enabled (not just libraryMode)
  • Snapshot and clean up ProcessSession beforeExit listeners in telemetry.test.ts

2. Auth guard test failures (PR #611)

buildCommand now calls getAuthConfig() before every command. Tests had no auth token.

Fix:

  • Set fake SENTRY_AUTH_TOKEN in test/preload.ts (blocked by global fetch mock)
  • Add auth: false to all 34 buildCommand calls in command.test.ts
  • Save/clear/restore SENTRY_AUTH_TOKEN in 9 test files that verify unauthenticated behavior
  • Add getAuthConfig mock + resolveOrgProjectFromArg mock in log/list tests

3. Dead code tests (PR #610)

PR #610 moved org resolution and DSN detection from createSentryProject to wizard-runner's resolvePreSpinnerOptions. Tests that exercised those flows through handleLocalOp hit the new !options.org guard.

Fix: Rewrote 15 tests to call resolveOrgSlug and detectExistingProject directly, plus 2 new tests for createSentryProject's existing-project check. No test coverage lost.

4. Mtime test flakiness

Replaced Bun.sleep(10) with explicit utimes() calls in dsn-cache and project-root-cache tests for deterministic mtime differences on Linux CI.

Test plan

  • bun test — 630 pass, 4 fail (pre-existing: 3 resolve-target timeouts from unmocked fetch, 1 log/list failure from missing generated api-schema.json)
  • bun run lint — clean (1 pre-existing warning)

Made with Cursor

@github-actions

github-actions Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

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


New Features ✨

  • (auth) Enforce auth by default in buildCommand by betegon in #611
  • (skill) Add eval framework to measure SKILL.md effectiveness by BYK in #602
  • (telemetry) Add seer.outcome span tag for Seer command metrics by BYK in #609
  • (upgrade) Show changelog summary during CLI upgrade by BYK in #594

Bug Fixes 🐛

Upgrade

  • Prevent spinner freeze during delta patch application by BYK in #608
  • Indent changelog, add emoji to heading, hide empty sections by BYK in #604

Other

  • (dashboard) Reject MRI queries with actionable tracemetrics guidance by BYK in #601
  • (init) Prompt/spinner ordering by betegon in #610
  • (skill) Avoid unnecessary auth, reinforce auto-detection, fix field examples by BYK in #599
  • 2 bug fixes — subcommand crash, negative span depth, pagination JSON parse by cursor in #607

Documentation 📚

  • (skill) Document dashboard widget constraints and deprecated datasets by BYK in #605
  • Fix documentation gaps and embed skill files at build time by cursor in #606

Internal Changes 🔧

  • Regenerate skill files and command docs by github-actions[bot] in 664362ca

🤖 This preview updates automatically when you update the PR.

Comment thread src/lib/telemetry.ts
// this, re-initializing the SDK (e.g., in tests) leaks setInterval handles
// that keep the event loop alive and prevent the process from exiting.
// close(0) removes listeners synchronously; we don't need to await the flush.
Sentry.getClient()?.close(0);

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.

Global client closed during reinitialization

Medium Severity

initSentry now unconditionally calls Sentry.getClient()?.close(0) before every init. In libraryMode, concurrent SDK invocations can close another in-flight invocation’s client, which can drop telemetry and invalidate active spans. It can also close a pre-existing process-wide Sentry client not created by this module.

Fix in Cursor Fix in Web

listener as (...args: unknown[]) => void
);
}
}

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.

Overbroad beforeExit listener cleanup

Low Severity

afterAll removes every beforeExit listener not present at file load, not just listeners created by this test. In shared test workers, this can unregister unrelated listeners added by other modules, causing cross-test interference and hard-to-reproduce failures.

Fix in Cursor Fix in Web

@betegon betegon force-pushed the fix/ci-hang-and-auth-guard-tests branch from f022b2a to d14e1cd Compare March 31, 2026 20:18
@github-actions

github-actions Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

129 passed | Total: 129 | 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 1349 uncovered lines.
❌ Project coverage is 95.46%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    95.73%    95.46%    -0.27%
==========================================
  Files          204       204         —
  Lines        29877     29738      -139
  Branches         0         0         —
==========================================
+ Hits         28601     28389      -212
- Misses        1276      1349       +73
- Partials         0         0         —

Generated by Codecov Action

Three independent issues caused CI to hang and ~200 tests to fail:

1. **CI hang (telemetry.ts)**: `beforeExit` handler removal was inside
   `if (client?.getOptions().enabled)`, so `initSentry(false)` in test
   afterEach hooks never cleaned up the handler from a prior
   `initSentry(true)`. Additionally, SDK-internal handlers from
   `enableLogs` and `sendClientReports` were never cleaned up on
   re-init. Fix: close previous client before re-init, move handler
   removal outside enabled guard, gate enableLogs/sendClientReports on
   `enabled`.

2. **Auth guard test failures (PR #611)**: `buildCommand` now requires
   auth by default. Fix: set fake SENTRY_AUTH_TOKEN in test preload,
   add `auth: false` to command.test.ts framework tests, save/clear/
   restore env token in auth-specific tests.

3. **Dead code tests (PR #610)**: `createSentryProject` no longer does
   org resolution (moved to wizard-runner's `resolvePreSpinnerOptions`).
   Fix: rewrite 15 tests to call `resolveOrgSlug` and
   `detectExistingProject` directly instead of through `handleLocalOp`.

Also fixes mtime test flakiness by replacing `Bun.sleep(10)` with
explicit `utimes()` calls in dsn-cache and project-root-cache tests.

Made-with: Cursor
@betegon betegon force-pushed the fix/ci-hang-and-auth-guard-tests branch from d14e1cd to 8c2dc2f Compare March 31, 2026 20:29

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

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

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

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

"my-org/my-project"
)
).rejects.not.toThrow(ValidationError);
resolveOrgProjectSpy.mockRestore();

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.

Spy cleanup skipped on assertion failure

Low Severity

The test creates resolveOrgProjectSpy and restores it only at the end of the happy path. If an assertion throws before mockRestore(), the mock remains active and can affect later tests in test/commands/log/list.test.ts, causing cascading failures and misleading CI results.

Fix in Cursor Fix in Web

@betegon betegon merged commit 44d604c into main Mar 31, 2026
23 of 25 checks passed
@betegon betegon deleted the fix/ci-hang-and-auth-guard-tests branch March 31, 2026 20:49
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