fix(tests): filter PostHog telemetry from fetch mocks to fix flaky tests

Two tests (hetzner-cov and digitalocean-token) failed consistently in the
full suite because telemetry.test.ts enables PostHog telemetry via the
shared module singleton, and those async fetch calls leak into other test
files' globalThis.fetch mocks, incrementing callCount and shifting mock
response order.

Fix: filter non-test URLs in affected mocks so telemetry calls get a
benign response without affecting callCount.

Agent: test-engineer
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
B 2026-04-24 14:48:34 +00:00
parent 83ecccf4ad
commit 3884e1a884
2 changed files with 17 additions and 3 deletions

View file

@ -90,8 +90,12 @@ describe("doApi 401 OAuth recovery", () => {
state.token = "expired-token";
let callCount = 0;
globalThis.fetch = mock((url: string | URL | Request) => {
callCount++;
const urlStr = String(url);
// Ignore background telemetry calls (PostHog) that leak from other test files
if (!urlStr.includes("digitalocean")) {
return Promise.resolve(new Response("ok"));
}
callCount++;
// First call: the actual API call returning 401
if (callCount === 1) {
return Promise.resolve(
@ -147,7 +151,12 @@ describe("doApi 401 OAuth recovery", () => {
state.token = "expired-token";
_testHelpers.recovering401 = true;
let callCount = 0;
globalThis.fetch = mock(() => {
globalThis.fetch = mock((url: string | URL | Request) => {
const urlStr = String(url);
// Ignore background telemetry calls (PostHog) that leak from other test files
if (!urlStr.includes("digitalocean")) {
return Promise.resolve(new Response("ok"));
}
callCount++;
return Promise.resolve(
new Response("Unauthorized", {

View file

@ -586,7 +586,12 @@ describe("hetzner/createServer", () => {
},
};
let callCount = 0;
global.fetch = mock(() => {
global.fetch = mock((url: string | URL | Request) => {
const urlStr = String(url instanceof Request ? url.url : url);
// Ignore background telemetry calls (PostHog) that leak from other test files
if (!urlStr.includes("hetzner.cloud")) {
return Promise.resolve(new Response("ok"));
}
callCount++;
if (callCount <= 1) {
// Token validation