Skip to content

Commit dcd8e70

Browse files
authored
fix: isolate multiregion 403 tests from env-var auth tokens (#514)
Follow-up to PR #512. Addresses [Sentry bot review](#512 (comment)): the 403 enrichment tests depend on `isEnvTokenActive()` returning false (OAuth path), but would flake if `SENTRY_AUTH_TOKEN` is set in CI. Save and restore the env vars in beforeEach/afterEach.
1 parent df25473 commit dcd8e70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/lib/api-client.multiregion.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ import { useTestConfigDir } from "../helpers.js";
2323

2424
useTestConfigDir("test-multiregion-");
2525
let originalFetch: typeof globalThis.fetch;
26+
let savedAuthToken: string | undefined;
27+
let savedSentryToken: string | undefined;
2628

2729
beforeEach(async () => {
2830
// Save original fetch
2931
originalFetch = globalThis.fetch;
3032

33+
// Isolate from env-var auth tokens so isEnvTokenActive() returns false.
34+
// Without this, tests for 403 enrichment would flake when CI sets
35+
// SENTRY_AUTH_TOKEN (the error message changes based on token source).
36+
savedAuthToken = process.env.SENTRY_AUTH_TOKEN;
37+
savedSentryToken = process.env.SENTRY_TOKEN;
38+
delete process.env.SENTRY_AUTH_TOKEN;
39+
delete process.env.SENTRY_TOKEN;
40+
3141
// Set up auth token (manual token, no refresh)
3242
await setAuthToken("test-token");
3343

@@ -38,6 +48,14 @@ beforeEach(async () => {
3848
afterEach(() => {
3949
// Restore original fetch
4050
globalThis.fetch = originalFetch;
51+
52+
// Restore env vars
53+
if (savedAuthToken !== undefined) {
54+
process.env.SENTRY_AUTH_TOKEN = savedAuthToken;
55+
}
56+
if (savedSentryToken !== undefined) {
57+
process.env.SENTRY_TOKEN = savedSentryToken;
58+
}
4159
});
4260

4361
/**

0 commit comments

Comments
 (0)