You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(test): fix CI hang, auth guard tests, and PR #610 test rewrite (#616)
## 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](https://cursor.com)
0 commit comments