mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-18 23:51:40 +00:00
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:
parent
83ecccf4ad
commit
3884e1a884
2 changed files with 17 additions and 3 deletions
|
|
@ -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", {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue