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>
This commit is contained in:
paseo-bot[bot]
2026-11-30 22:42:42 +00:00
committed by GitHub
parent 4c480c9afe
commit eaa4589e07
2 changed files with 67 additions and 9 deletions
@@ -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<string, unknown>([
[`${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([
+10 -9
View File
@@ -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<string>;
cache: Map<string, { logTail: string; logTruncated: boolean }>;
}): 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;