From eaa4589e070be1de89fc58dd4a3a7c27674bc572 Mon Sep 17 00:00:00 2001 From: "paseo-bot[bot]" <266920839+paseo-bot[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 22:42:42 +0000 Subject: [PATCH] fix(server): keep GitHub check details when a job log fails (#11509) A job log is optional context. Keep the annotations and failed jobs available when GitHub CLI cannot return one of the logs. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> --- .../src/services/github-service.test.ts | 57 +++++++++++++++++++ .../server/src/services/github-service.ts | 19 ++++--- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/packages/server/src/services/github-service.test.ts b/packages/server/src/services/github-service.test.ts index 49dc412d14..7e1928aa5d 100644 --- a/packages/server/src/services/github-service.test.ts +++ b/packages/server/src/services/github-service.test.ts @@ -2920,6 +2920,63 @@ describe("ForgeService", () => { }); }); + it("keeps check details and other job logs when one failed job log is unavailable", async () => { + const repoPath = "repos/acme/repo"; + const failedJob = { status: "completed", conclusion: "failure" }; + const responses = new Map([ + [`${repoPath}/check-runs/12`, { id: 12, name: "CI", ...failedJob }], + [ + `${repoPath}/check-runs/12/annotations?per_page=20`, + [{ path: "src/index.ts", message: "Type error" }], + ], + [ + `${repoPath}/actions/runs/34/jobs?per_page=100`, + { + jobs: [ + { id: 56, name: "typecheck", ...failedJob }, + { id: 57, name: "lint", ...failedJob }, + ], + }, + ], + ]); + const service = createGitHubService({ + resolveGhPath: async () => "/usr/bin/gh", + resolveRepoHost: async () => null, + runner: async (args) => { + const endpoint = args[1]; + if (endpoint === `${repoPath}/actions/jobs/56/logs`) { + throw new GitHubCommandError({ + args, + cwd: "/repo", + exitCode: 1, + stderr: "the response contains terminal escape sequences", + }); + } + if (endpoint === `${repoPath}/actions/jobs/57/logs`) { + return { stdout: "Lint failed", stderr: "" }; + } + return { stdout: JSON.stringify(responses.get(endpoint)), stderr: "" }; + }, + }); + + const details = await service.getCheckDetails({ + cwd: "/repo", + repoOwner: "acme", + repoName: "repo", + checkRunId: 12, + workflowRunId: 34, + }); + + expect(details.annotations).toEqual([ + expect.objectContaining({ path: "src/index.ts", message: "Type error" }), + ]); + expect(details.failedJobs).toMatchObject([ + { jobId: 56, name: "typecheck", conclusion: "failure" }, + { jobId: 57, name: "lint", conclusion: "failure", logTail: "Lint failed" }, + ]); + expect(details.failedJobs[0]?.logTail).toBeUndefined(); + }); + it("fetches GitHub check details with capped failed job log tails and reuses cached logs", async () => { const longLog = Array.from({ length: 220 }, (_, index) => `line ${index + 1}`).join("\n"); const runner = createRunner([ diff --git a/packages/server/src/services/github-service.ts b/packages/server/src/services/github-service.ts index 0d5e71d5bb..4f2d1bc911 100644 --- a/packages/server/src/services/github-service.ts +++ b/packages/server/src/services/github-service.ts @@ -2593,15 +2593,14 @@ export function createGitHubService(options: CreateGitHubServiceOptions = {}): G run, cache: checkLogTailCache, }); - truncated ||= log.logTruncated; + truncated ||= log?.logTruncated ?? false; failedJobs.push({ jobId: job.jobId, name: job.name, status: job.status, conclusion: job.conclusion, url: job.url, - logTail: log.logTail, - logTruncated: log.logTruncated, + ...log, }); } } @@ -4263,7 +4262,7 @@ async function getCachedCheckLogTail(input: { job: CheckFailedJob & { completedAt?: string }; run: (args: string[], options: GitHubCommandRunnerOptions) => Promise; cache: Map; -}): Promise<{ logTail: string; logTruncated: boolean }> { +}): Promise<{ logTail: string; logTruncated: boolean } | undefined> { const key = `${input.job.jobId}:${input.job.completedAt ?? ""}`; const cached = input.cache.get(key); if (cached) { @@ -4272,11 +4271,13 @@ async function getCachedCheckLogTail(input: { return cached; } - const capped = capCheckLogTail( - await input.run(["api", `${input.repoPath}/actions/jobs/${input.job.jobId}/logs`], { - cwd: input.cwd, - }), - ); + const log = await input + .run(["api", `${input.repoPath}/actions/jobs/${input.job.jobId}/logs`], { cwd: input.cwd }) + .catch(() => undefined); + if (log === undefined) { + return undefined; + } + const capped = capCheckLogTail(log); input.cache.set(key, capped); while (input.cache.size > CHECK_LOG_TAIL_CACHE_MAX_ENTRIES) { const oldestKey = input.cache.keys().next().value;