Skip to content

Commit 7c6aac4

Browse files
committed
debug: add fetch logging to failing CI tests
1 parent 2d33279 commit 7c6aac4

File tree

1 file changed

+42
-11
lines changed

1 file changed

+42
-11
lines changed

test/commands/issue/utils.test.ts

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,17 @@ describe("resolveOrgAndIssueId", () => {
306306
);
307307
await clearProjectAliases();
308308

309+
const fetchLog: string[] = [];
310+
309311
// @ts-expect-error - partial mock
310312
globalThis.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
311313
const req = new Request(input, init);
312314
const url = req.url;
315+
fetchLog.push(`FETCH: ${req.method} ${url}`);
313316

314317
// getUserRegions - return empty regions to use fallback path
315318
if (url.includes("/users/me/regions/")) {
319+
fetchLog.push(" → matched: /users/me/regions/");
316320
return new Response(JSON.stringify({ regions: [] }), {
317321
status: 200,
318322
headers: { "Content-Type": "application/json" },
@@ -325,6 +329,7 @@ describe("resolveOrgAndIssueId", () => {
325329
!url.includes("/projects/") &&
326330
!url.includes("/issues/")
327331
) {
332+
fetchLog.push(" → matched: listOrganizations");
328333
return new Response(
329334
JSON.stringify([{ id: "1", slug: "my-org", name: "My Org" }]),
330335
{
@@ -336,6 +341,7 @@ describe("resolveOrgAndIssueId", () => {
336341

337342
// listProjects for my-org
338343
if (url.includes("organizations/my-org/projects/")) {
344+
fetchLog.push(" → matched: listProjects for my-org");
339345
return new Response(
340346
JSON.stringify([
341347
{ id: "123", slug: "craft", name: "Craft", platform: "javascript" },
@@ -354,6 +360,7 @@ describe("resolveOrgAndIssueId", () => {
354360
}
355361

356362
if (url.includes("organizations/my-org/issues/CRAFT-G")) {
363+
fetchLog.push(" → matched: issue CRAFT-G");
357364
return new Response(
358365
JSON.stringify({
359366
id: "777888999",
@@ -372,19 +379,25 @@ describe("resolveOrgAndIssueId", () => {
372379
);
373380
}
374381

382+
fetchLog.push(" → NO MATCH (returning 404)");
375383
return new Response(JSON.stringify({ detail: "Not found" }), {
376384
status: 404,
377385
});
378386
};
379387

380-
const result = await resolveOrgAndIssueId({
381-
issueArg: "craft-g",
382-
cwd: getConfigDir(),
383-
command: "explain",
384-
});
388+
try {
389+
const result = await resolveOrgAndIssueId({
390+
issueArg: "craft-g",
391+
cwd: getConfigDir(),
392+
command: "explain",
393+
});
385394

386-
expect(result.org).toBe("my-org");
387-
expect(result.issueId).toBe("777888999");
395+
expect(result.org).toBe("my-org");
396+
expect(result.issueId).toBe("777888999");
397+
} catch (error) {
398+
console.error("FETCH LOG:", fetchLog.join("\n"));
399+
throw error;
400+
}
388401
});
389402

390403
test("throws when project not found in any org", async () => {
@@ -461,13 +474,17 @@ describe("resolveOrgAndIssueId", () => {
461474

462475
await setOrgRegion("org2", DEFAULT_SENTRY_URL);
463476

477+
const fetchLog: string[] = [];
478+
464479
// @ts-expect-error - partial mock
465480
globalThis.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
466481
const req = new Request(input, init);
467482
const url = req.url;
483+
fetchLog.push(`FETCH: ${req.method} ${url}`);
468484

469485
// getUserRegions - return empty regions to use fallback path
470486
if (url.includes("/users/me/regions/")) {
487+
fetchLog.push(" → matched: /users/me/regions/");
471488
return new Response(JSON.stringify({ regions: [] }), {
472489
status: 200,
473490
headers: { "Content-Type": "application/json" },
@@ -480,6 +497,7 @@ describe("resolveOrgAndIssueId", () => {
480497
!url.includes("/projects/") &&
481498
!url.includes("/issues/")
482499
) {
500+
fetchLog.push(" → matched: listOrganizations");
483501
return new Response(
484502
JSON.stringify([
485503
{ id: "1", slug: "org1", name: "Org 1" },
@@ -494,6 +512,7 @@ describe("resolveOrgAndIssueId", () => {
494512

495513
// listProjects for org1 - has "common" project
496514
if (url.includes("organizations/org1/projects/")) {
515+
fetchLog.push(" → matched: listProjects for org1");
497516
return new Response(
498517
JSON.stringify([
499518
{
@@ -512,6 +531,7 @@ describe("resolveOrgAndIssueId", () => {
512531

513532
// listProjects for org2 - also has "common" project
514533
if (url.includes("organizations/org2/projects/")) {
534+
fetchLog.push(" → matched: listProjects for org2");
515535
return new Response(
516536
JSON.stringify([
517537
{ id: "456", slug: "common", name: "Common", platform: "python" },
@@ -523,18 +543,29 @@ describe("resolveOrgAndIssueId", () => {
523543
);
524544
}
525545

546+
fetchLog.push(" → NO MATCH (returning 404)");
526547
return new Response(JSON.stringify({ detail: "Not found" }), {
527548
status: 404,
528549
});
529550
};
530551

531-
await expect(
532-
resolveOrgAndIssueId({
552+
try {
553+
await resolveOrgAndIssueId({
533554
issueArg: "common-g",
534555
cwd: getConfigDir(),
535556
command: "explain",
536-
})
537-
).rejects.toThrow("multiple organizations");
557+
});
558+
// If we get here, the function didn't throw — log and fail
559+
console.error("FETCH LOG (no throw):", fetchLog.join("\n"));
560+
throw new Error("Expected resolveOrgAndIssueId to throw but it resolved");
561+
} catch (error: unknown) {
562+
const msg = error instanceof Error ? error.message : String(error);
563+
if (!msg.includes("multiple organizations")) {
564+
console.error("FETCH LOG (wrong error):", fetchLog.join("\n"));
565+
console.error("Actual error:", msg);
566+
}
567+
expect(msg).toContain("multiple organizations");
568+
}
538569
});
539570

540571
test("short suffix auth error (401) propagates", async () => {

0 commit comments

Comments
 (0)