open-pstack 0.9.174 → 0.9.176
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE.md +4 -4
- package/package.json +1 -1
- package/plugin/.antigravity-plugin/plugin.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.github/plugin/plugin.json +1 -1
- package/plugin/.grok-plugin/plugin.json +1 -1
- package/plugin/.muse-plugin/plugin.json +1 -1
- package/plugin/hooks/agy-context.awk +12 -7
- package/plugin/hooks/session-start-agy-ignored.md +1 -0
- package/plugin/hooks/session-start.ps1 +23 -1
- package/plugin/hooks/session-start.sh +27 -5
- package/plugin/package.json +1 -1
- package/plugin/pi/index.ts +3 -2
- package/plugin/pi/prompt.ts +8 -3
- package/plugin/skills/poteto-mode/playbooks/worktree-cleanup.md +1 -1
- package/plugin/skills/poteto-mode/references/agy-tools.md +2 -2
- package/plugin/skills/poteto-mode/references/vibe-tools.md +1 -1
- package/plugin/skills/poteto-mode/scripts/.prettierignore +3 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/check-suites.ts +78 -1
- package/plugin/skills/poteto-mode/scripts/watch-pr/cloud-reader.test.ts +21 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/cloud-reader.ts +7 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +6 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/github.port.test.ts +286 -1
- package/plugin/skills/poteto-mode/scripts/watch-pr/github.ts +46 -25
- package/plugin/skills/poteto-mode/scripts/watch-pr/head-checks.ts +47 -1
- package/plugin/skills/poteto-mode/scripts/watch-pr/policy.port.test.ts +158 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/grafana-139602-cancelled-suites-beside-green.json +921 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/grafana-139606-approval-gated.json +82 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/grafana-139612-cancelled-check-beside-green.json +174 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/octocat-hello-world-34-no-checks.json +42 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/gh.ts +144 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/harness.ts +172 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/heads.json +73 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/record.ts +410 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/watch.ts +72 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay.port.test.ts +264 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/transport.test.ts +5 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/types.ts +2 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/workflow-runs.ts +58 -21
- package/plugin/skills/poteto-mode/scripts/worktree-audit.mjs +75 -6
- package/plugin/skills/setup-pstack/scripts/read-sheet.sh +6 -2
- package/plugin/vibe/ai.mistral.vibe/hooks.toml +12 -1
- package/plugin/vibe/plugin.json +1 -1
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import {
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import {
|
|
7
|
+
BETWEEN_JOBS_MS,
|
|
8
|
+
betweenJobsCheck,
|
|
9
|
+
parseSuiteRead,
|
|
10
|
+
} from "./check-suites.ts";
|
|
3
11
|
import { WatchDeadline } from "./deadline.ts";
|
|
4
12
|
import {
|
|
5
13
|
ChecksUnavailable,
|
|
@@ -265,6 +273,51 @@ describe("check suites no check read shows", () => {
|
|
|
265
273
|
expect(reported(fields)).toEqual([]);
|
|
266
274
|
});
|
|
267
275
|
|
|
276
|
+
it("beside reported checks, lists an unfinished Actions suite with runs for its check runs to decide", () => {
|
|
277
|
+
const running = (fields: Record<string, unknown>) =>
|
|
278
|
+
parseSuiteRead(pages(suite({ id: 7, ...fields })), head, "reported")
|
|
279
|
+
.runningActionsSuites;
|
|
280
|
+
expect(
|
|
281
|
+
running({
|
|
282
|
+
status: "in_progress",
|
|
283
|
+
conclusion: null,
|
|
284
|
+
latest_check_runs_count: 2,
|
|
285
|
+
})
|
|
286
|
+
).toEqual([{ id: 7, status: "in_progress" }]);
|
|
287
|
+
expect(
|
|
288
|
+
running({
|
|
289
|
+
status: "QUEUED",
|
|
290
|
+
conclusion: null,
|
|
291
|
+
latest_check_runs_count: 1,
|
|
292
|
+
})
|
|
293
|
+
).toEqual([{ id: 7, status: "queued" }]);
|
|
294
|
+
for (const fields of [
|
|
295
|
+
{ conclusion: "success", latest_check_runs_count: 2 },
|
|
296
|
+
{ status: "in_progress", conclusion: null },
|
|
297
|
+
{ status: null, conclusion: null, latest_check_runs_count: 1 },
|
|
298
|
+
{
|
|
299
|
+
status: "in_progress",
|
|
300
|
+
conclusion: null,
|
|
301
|
+
latest_check_runs_count: 1,
|
|
302
|
+
app: { slug: "external-ci", name: "External CI" },
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
status: "in_progress",
|
|
306
|
+
conclusion: null,
|
|
307
|
+
latest_check_runs_count: 1,
|
|
308
|
+
id: null,
|
|
309
|
+
},
|
|
310
|
+
])
|
|
311
|
+
expect(running(fields)).toEqual([]);
|
|
312
|
+
expect(
|
|
313
|
+
parseSuiteRead(
|
|
314
|
+
pages(suite({ id: 7, status: "in_progress", conclusion: null })),
|
|
315
|
+
head,
|
|
316
|
+
"no-checks"
|
|
317
|
+
).runningActionsSuites
|
|
318
|
+
).toEqual([]);
|
|
319
|
+
});
|
|
320
|
+
|
|
268
321
|
it("finds a gated suite on a later page", () => {
|
|
269
322
|
const twoPages = [
|
|
270
323
|
...pages(suite({ conclusion: "success" })),
|
|
@@ -345,6 +398,209 @@ describe("check suites no check read shows", () => {
|
|
|
345
398
|
});
|
|
346
399
|
});
|
|
347
400
|
|
|
401
|
+
describe("a workflow run between two of its jobs", () => {
|
|
402
|
+
const now = Date.parse("2026-12-04T03:00:00Z");
|
|
403
|
+
const ago = (seconds: number) => new Date(now - seconds * 1000).toISOString();
|
|
404
|
+
const runPages = (...runs: Record<string, unknown>[]) => [
|
|
405
|
+
{ total_count: runs.length, check_runs: runs },
|
|
406
|
+
];
|
|
407
|
+
const done = (seconds: number) => ({
|
|
408
|
+
status: "completed",
|
|
409
|
+
conclusion: "success",
|
|
410
|
+
completed_at: ago(seconds),
|
|
411
|
+
});
|
|
412
|
+
const running = { id: 9333, status: "in_progress" };
|
|
413
|
+
|
|
414
|
+
it("keeps a suite pending while its newest run finished within the window", () => {
|
|
415
|
+
expect(
|
|
416
|
+
betweenJobsCheck(running, runPages(done(400), done(5)), now)
|
|
417
|
+
).toEqual({
|
|
418
|
+
kind: "pending",
|
|
419
|
+
source: "check-suites",
|
|
420
|
+
name: "GitHub Actions check suite",
|
|
421
|
+
reportedState: "IN_PROGRESS",
|
|
422
|
+
description: "has not finished",
|
|
423
|
+
link: "",
|
|
424
|
+
workflow: "",
|
|
425
|
+
});
|
|
426
|
+
expect(
|
|
427
|
+
betweenJobsCheck(running, runPages(done(BETWEEN_JOBS_MS / 1000)), now)
|
|
428
|
+
).toMatchObject({ kind: "pending" });
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
// GitHub can leave a suite unfinished for weeks after its last run, as on
|
|
432
|
+
// grafana/grafana suite 107822784940.
|
|
433
|
+
it("reads no check from a suite whose runs all finished long ago", () => {
|
|
434
|
+
expect(
|
|
435
|
+
betweenJobsCheck(running, runPages(done(BETWEEN_JOBS_MS / 1000 + 1)), now)
|
|
436
|
+
).toBeNull();
|
|
437
|
+
expect(
|
|
438
|
+
betweenJobsCheck(running, runPages(done(30 * 24 * 3600)), now)
|
|
439
|
+
).toBeNull();
|
|
440
|
+
expect(betweenJobsCheck(running, runPages(), now)).toBeNull();
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
const started = (status: string, seconds: number) => ({
|
|
444
|
+
status,
|
|
445
|
+
completed_at: null,
|
|
446
|
+
started_at: ago(seconds),
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// In #634's race the next job is often created between the gh pr checks
|
|
450
|
+
// read and the check-runs read.
|
|
451
|
+
it("keeps a suite pending while its next job has just been created", () => {
|
|
452
|
+
for (const status of ["queued", "in_progress", "QUEUED"])
|
|
453
|
+
expect(
|
|
454
|
+
betweenJobsCheck(running, runPages(done(5), started(status, 1)), now)
|
|
455
|
+
).toMatchObject({ kind: "pending" });
|
|
456
|
+
expect(
|
|
457
|
+
betweenJobsCheck(running, runPages(done(4000), started("queued", 1)), now)
|
|
458
|
+
).toMatchObject({ kind: "pending" });
|
|
459
|
+
expect(
|
|
460
|
+
betweenJobsCheck(
|
|
461
|
+
running,
|
|
462
|
+
runPages(done(4000), started("in_progress", 4000)),
|
|
463
|
+
now
|
|
464
|
+
)
|
|
465
|
+
).toBeNull();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// gh does not list Copilot's code review, whose suite holds one run.
|
|
469
|
+
it("reads no check from a suite with no finished run", () => {
|
|
470
|
+
expect(
|
|
471
|
+
betweenJobsCheck(running, runPages(started("in_progress", 1)), now)
|
|
472
|
+
).toBeNull();
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it("fails closed on a check run it cannot date", () => {
|
|
476
|
+
for (const run of [
|
|
477
|
+
{ status: null },
|
|
478
|
+
{ status: "completed", completed_at: null },
|
|
479
|
+
{ status: "completed", completed_at: "yesterday" },
|
|
480
|
+
{ status: "queued", started_at: null },
|
|
481
|
+
{ status: "in_progress", started_at: "soon" },
|
|
482
|
+
])
|
|
483
|
+
expect(() => betweenJobsCheck(running, runPages(run), now)).toThrow(
|
|
484
|
+
/check run/
|
|
485
|
+
);
|
|
486
|
+
expect(() => betweenJobsCheck(running, [{}], now)).toThrow(/check_runs/);
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
// The stand-in from #634: gh lists a passed job from finished run 332 and a
|
|
490
|
+
// passed job from run 333, whose suite is still going. Each key of
|
|
491
|
+
// suiteRuns adds an in_progress suite with runs, whose check-runs read
|
|
492
|
+
// returns those pages, or fails when they are null.
|
|
493
|
+
const readHead = (suiteRuns: Record<number, unknown>) => {
|
|
494
|
+
const directory = mkdtempSync(join(tmpdir(), "watch-pr-between-jobs-"));
|
|
495
|
+
try {
|
|
496
|
+
const head = "a66c327af02be3cd643c1f0a163ee00967fbc6c0";
|
|
497
|
+
const suite = (
|
|
498
|
+
id: number,
|
|
499
|
+
status: string,
|
|
500
|
+
conclusion: string | null
|
|
501
|
+
) => ({
|
|
502
|
+
id,
|
|
503
|
+
head_sha: head,
|
|
504
|
+
status,
|
|
505
|
+
conclusion,
|
|
506
|
+
latest_check_runs_count: 1,
|
|
507
|
+
app: { slug: "github-actions", name: "GitHub Actions" },
|
|
508
|
+
});
|
|
509
|
+
const job = (name: string, run: number) => ({
|
|
510
|
+
name,
|
|
511
|
+
state: "SUCCESS",
|
|
512
|
+
bucket: "pass",
|
|
513
|
+
description: "",
|
|
514
|
+
workflow: "CI",
|
|
515
|
+
link: `https://github.com/owner/repo/actions/runs/${run}/job/1`,
|
|
516
|
+
});
|
|
517
|
+
const reply = (name: string, value: unknown) =>
|
|
518
|
+
writeFileSync(join(directory, name), JSON.stringify(value));
|
|
519
|
+
reply("checks.json", [job("lint", 332), job("Detect changes", 333)]);
|
|
520
|
+
const ids = Object.keys(suiteRuns).map(Number);
|
|
521
|
+
reply("suites.json", [
|
|
522
|
+
{
|
|
523
|
+
total_count: ids.length + 1,
|
|
524
|
+
check_suites: [
|
|
525
|
+
suite(9332, "completed", "success"),
|
|
526
|
+
...ids.map((id) => suite(id, "in_progress", null)),
|
|
527
|
+
],
|
|
528
|
+
},
|
|
529
|
+
]);
|
|
530
|
+
const cases = ids.map((id) => {
|
|
531
|
+
if (suiteRuns[id] === null)
|
|
532
|
+
return ` *check-suites/${id}/check-runs*) echo "HTTP 502: Bad Gateway" >&2; exit 1 ;;`;
|
|
533
|
+
reply(`runs-${id}.json`, suiteRuns[id]);
|
|
534
|
+
return ` *check-suites/${id}/check-runs*) cat '${directory}/runs-${id}.json' ;;`;
|
|
535
|
+
});
|
|
536
|
+
writeFileSync(
|
|
537
|
+
join(directory, "gh"),
|
|
538
|
+
`#!/bin/sh\ncase "$*" in\n "pr checks"*) cat '${directory}/checks.json' ;;\n${cases.join("\n")}\n *commits/${head}/check-suites*) cat '${directory}/suites.json' ;;\n *) echo "unexpected gh $*" >&2; exit 2 ;;\nesac\n`,
|
|
539
|
+
{ mode: 0o755 }
|
|
540
|
+
);
|
|
541
|
+
const program = `import { GhGitHubReader } from ${JSON.stringify(import.meta.dir + "/github.ts")};
|
|
542
|
+
import { WatchDeadline } from ${JSON.stringify(import.meta.dir + "/deadline.ts")};
|
|
543
|
+
import { resolveHeadChecks } from ${JSON.stringify(import.meta.dir + "/head-checks.ts")};
|
|
544
|
+
const reader = new GhGitHubReader(new WatchDeadline(0, Date.now), () => ${now});
|
|
545
|
+
try {
|
|
546
|
+
const read = await resolveHeadChecks(reader, { context: { owner: "owner", repo: "repo", number: 42 }, headRefOid: ${JSON.stringify(head)} });
|
|
547
|
+
console.log(JSON.stringify(read.checks.map((check) => check.kind + " " + check.name)));
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.log(JSON.stringify(error.failure));
|
|
550
|
+
}`;
|
|
551
|
+
const child = spawnSync(process.execPath, ["-e", program], {
|
|
552
|
+
encoding: "utf8",
|
|
553
|
+
timeout: 5000,
|
|
554
|
+
env: { ...process.env, PATH: directory + ":" + process.env.PATH },
|
|
555
|
+
});
|
|
556
|
+
expect({ status: child.status, stderr: child.stderr }).toEqual({
|
|
557
|
+
status: 0,
|
|
558
|
+
stderr: "",
|
|
559
|
+
});
|
|
560
|
+
return JSON.parse(child.stdout);
|
|
561
|
+
} finally {
|
|
562
|
+
rmSync(directory, { recursive: true, force: true });
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
const passed = ["passed lint", "passed Detect changes"];
|
|
567
|
+
const pending = [...passed, "pending GitHub Actions check suite"];
|
|
568
|
+
|
|
569
|
+
it("keeps the head pending through the real reader while the next job is due", () => {
|
|
570
|
+
expect(readHead({ 9333: runPages(done(5)) })).toEqual(pending);
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it("keeps the head pending through the real reader once the next job is queued", () => {
|
|
574
|
+
expect(readHead({ 9333: runPages(done(5), started("queued", 1)) })).toEqual(
|
|
575
|
+
pending
|
|
576
|
+
);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("reads the head clean through the real reader once the suite is stuck", () => {
|
|
580
|
+
expect(readHead({ 9333: runPages(done(30 * 24 * 3600)) })).toEqual(passed);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it("reads each unfinished suite, adding one pending check per suite between jobs", () => {
|
|
584
|
+
expect(
|
|
585
|
+
readHead({
|
|
586
|
+
9333: runPages(done(30 * 24 * 3600)),
|
|
587
|
+
9334: runPages(done(5)),
|
|
588
|
+
})
|
|
589
|
+
).toEqual(pending);
|
|
590
|
+
expect(
|
|
591
|
+
readHead({ 9333: runPages(done(5)), 9334: runPages(done(5)) })
|
|
592
|
+
).toEqual([...pending, "pending GitHub Actions check suite"]);
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it("fails the read with a retryable query failure when a check-runs read fails", () => {
|
|
596
|
+
expect(readHead({ 9333: null })).toMatchObject({
|
|
597
|
+
kind: "command-exit",
|
|
598
|
+
retryable: true,
|
|
599
|
+
code: 1,
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
});
|
|
603
|
+
|
|
348
604
|
describe("workflow runs identify current startup failures", () => {
|
|
349
605
|
const head = "a66c327af02be3cd643c1f0a163ee00967fbc6c0";
|
|
350
606
|
const run = (fields: Record<string, unknown> = {}) => ({
|
|
@@ -828,6 +1084,35 @@ it("reports a binary that cannot be spawned as a query failure that does not ret
|
|
|
828
1084
|
});
|
|
829
1085
|
});
|
|
830
1086
|
|
|
1087
|
+
// The check read can reach the workflow runs before any suite read, so their
|
|
1088
|
+
// read names the gh upgrade as the suite read does.
|
|
1089
|
+
it("asks for a newer gh when the workflow-run read meets one without --slurp", () => {
|
|
1090
|
+
const directory = mkdtempSync(join(tmpdir(), "watch-pr-old-gh-"));
|
|
1091
|
+
try {
|
|
1092
|
+
writeFileSync(
|
|
1093
|
+
join(directory, "gh"),
|
|
1094
|
+
"#!/bin/sh\necho 'unknown flag: --slurp' >&2\nexit 1\n",
|
|
1095
|
+
{ mode: 0o755 }
|
|
1096
|
+
);
|
|
1097
|
+
const program = `import { GhGitHubReader } from ${JSON.stringify(import.meta.dir + "/github.ts")};
|
|
1098
|
+
import { WatchDeadline } from ${JSON.stringify(import.meta.dir + "/deadline.ts")};
|
|
1099
|
+
const reader = new GhGitHubReader(new WatchDeadline(0, Date.now));
|
|
1100
|
+
await reader.workflowRunPages({ owner: "owner", repo: "repo", number: 42 }, "head").catch((error) => console.log(JSON.stringify(error.failure)));`;
|
|
1101
|
+
const child = spawnSync(process.execPath, ["-e", program], {
|
|
1102
|
+
encoding: "utf8",
|
|
1103
|
+
timeout: 2000,
|
|
1104
|
+
env: { ...process.env, PATH: directory + ":" + process.env.PATH },
|
|
1105
|
+
});
|
|
1106
|
+
expect(child.status).toBe(0);
|
|
1107
|
+
expect(JSON.parse(child.stdout)).toMatchObject({
|
|
1108
|
+
kind: "unsupported-gh",
|
|
1109
|
+
retryable: false,
|
|
1110
|
+
});
|
|
1111
|
+
} finally {
|
|
1112
|
+
rmSync(directory, { recursive: true, force: true });
|
|
1113
|
+
}
|
|
1114
|
+
});
|
|
1115
|
+
|
|
831
1116
|
describe("fast-path check mapping", () => {
|
|
832
1117
|
// gh's aggregate.go files every state it does not name into the pending
|
|
833
1118
|
// bucket, including completed conclusions.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
betweenJobsCheck,
|
|
2
3
|
parseSuiteRead,
|
|
3
4
|
suiteReadOf,
|
|
4
5
|
unsettledSuiteChecks,
|
|
6
|
+
type SuiteCheckEntry,
|
|
5
7
|
} from "./check-suites.ts";
|
|
6
8
|
import { baseRefTargetOid, text } from "./landing.ts";
|
|
7
9
|
import {
|
|
@@ -547,7 +549,10 @@ function graphqlArgs(
|
|
|
547
549
|
}
|
|
548
550
|
|
|
549
551
|
export class GhGitHubReader implements T.GitHubReader {
|
|
550
|
-
constructor(
|
|
552
|
+
constructor(
|
|
553
|
+
private readonly deadline: WatchDeadline,
|
|
554
|
+
private readonly now: () => number = Date.now
|
|
555
|
+
) {}
|
|
551
556
|
private run(argv: readonly [string, ...string[]]): Promise<CommandResult> {
|
|
552
557
|
return run(argv, this.deadline);
|
|
553
558
|
}
|
|
@@ -757,41 +762,57 @@ export class GhGitHubReader implements T.GitHubReader {
|
|
|
757
762
|
checksRead: T.CheckRead["kind"],
|
|
758
763
|
expectedApps: readonly string[]
|
|
759
764
|
): Promise<T.SuiteRead> {
|
|
760
|
-
const result = await this.
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
"--slurp",
|
|
765
|
-
`repos/${context.owner}/${context.repo}/commits/${head}/check-suites?per_page=100`,
|
|
766
|
-
]);
|
|
767
|
-
if (
|
|
768
|
-
result.code !== 0 &&
|
|
769
|
-
firstLine(result.stderr) === "unknown flag: --slurp"
|
|
770
|
-
)
|
|
771
|
-
throw new WatcherQueryError({
|
|
772
|
-
kind: "unsupported-gh",
|
|
773
|
-
retryable: false,
|
|
774
|
-
detail: "gh api rejected --slurp. Upgrade GitHub CLI to 2.48 or later.",
|
|
775
|
-
});
|
|
776
|
-
const parsed = parseSuiteRead(
|
|
765
|
+
const result = await this.slurp(
|
|
766
|
+
`repos/${context.owner}/${context.repo}/commits/${head}/check-suites?per_page=100`
|
|
767
|
+
);
|
|
768
|
+
const read = parseSuiteRead(
|
|
777
769
|
commandJson(result, "gh api check-suites"),
|
|
778
770
|
head,
|
|
779
771
|
checksRead,
|
|
780
772
|
expectedApps
|
|
781
773
|
);
|
|
774
|
+
const betweenJobs: SuiteCheckEntry[] = [];
|
|
775
|
+
for (const suite of read.runningActionsSuites) {
|
|
776
|
+
const path = `repos/${context.owner}/${context.repo}/check-suites/${suite.id}/check-runs?filter=latest&per_page=100`;
|
|
777
|
+
const check = betweenJobsCheck(
|
|
778
|
+
suite,
|
|
779
|
+
commandJson(
|
|
780
|
+
await this.slurp(path),
|
|
781
|
+
`gh api --paginate --slurp ${path}`
|
|
782
|
+
),
|
|
783
|
+
this.now()
|
|
784
|
+
);
|
|
785
|
+
if (check !== null) betweenJobs.push({ suiteId: suite.id, check });
|
|
786
|
+
}
|
|
787
|
+
const parsed = { ...read, entries: [...read.entries, ...betweenJobs] };
|
|
782
788
|
if (parsed.startupFailureSuites.length === 0) return suiteReadOf(parsed);
|
|
783
|
-
const workflowPages = await this.
|
|
784
|
-
"gh",
|
|
785
|
-
"api",
|
|
786
|
-
"--paginate",
|
|
787
|
-
"--slurp",
|
|
788
|
-
`repos/${context.owner}/${context.repo}/actions/runs?head_sha=${head}&per_page=100`,
|
|
789
|
-
]);
|
|
789
|
+
const workflowPages = await this.workflowRunPages(context, head);
|
|
790
790
|
return mergeWorkflowRunChecks(
|
|
791
791
|
parsed,
|
|
792
792
|
resolveWorkflowRunChecks(workflowPages, parsed, head)
|
|
793
793
|
);
|
|
794
794
|
}
|
|
795
|
+
async workflowRunPages(context: T.PrContext, head: string): Promise<unknown> {
|
|
796
|
+
const path = `repos/${context.owner}/${context.repo}/actions/runs?head_sha=${head}&per_page=100`;
|
|
797
|
+
return commandJson(
|
|
798
|
+
await this.slurp(path),
|
|
799
|
+
`gh api --paginate --slurp ${path}`
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
// gh before 2.48 has no --slurp, which every paginated REST read here uses.
|
|
803
|
+
private async slurp(path: string): Promise<CommandResult> {
|
|
804
|
+
const result = await this.run(["gh", "api", "--paginate", "--slurp", path]);
|
|
805
|
+
if (
|
|
806
|
+
result.code !== 0 &&
|
|
807
|
+
firstLine(result.stderr) === "unknown flag: --slurp"
|
|
808
|
+
)
|
|
809
|
+
throw new WatcherQueryError({
|
|
810
|
+
kind: "unsupported-gh",
|
|
811
|
+
retryable: false,
|
|
812
|
+
detail: "gh api rejected --slurp. Upgrade GitHub CLI to 2.48 or later.",
|
|
813
|
+
});
|
|
814
|
+
return result;
|
|
815
|
+
}
|
|
795
816
|
}
|
|
796
817
|
|
|
797
818
|
export { unsettledSuiteChecks };
|
|
@@ -2,10 +2,12 @@ import { resolveChecks } from "./github.ts";
|
|
|
2
2
|
import type { LandingRevision } from "./landing.ts";
|
|
3
3
|
import {
|
|
4
4
|
nonEmpty,
|
|
5
|
+
type Check,
|
|
5
6
|
type CheckRead,
|
|
6
7
|
type GitHubReader,
|
|
7
8
|
type SuiteApp,
|
|
8
9
|
} from "./types.ts";
|
|
10
|
+
import { replacedRunIds } from "./workflow-runs.ts";
|
|
9
11
|
|
|
10
12
|
// No check read shows a suite with no runs, such as a fork workflow waiting for
|
|
11
13
|
// maintainer approval, so the head's suites are read before its CI counts as
|
|
@@ -15,7 +17,11 @@ export async function resolveHeadChecks(
|
|
|
15
17
|
facts: Pick<LandingRevision, "context" | "headRefOid">,
|
|
16
18
|
expectedApps: readonly string[] = []
|
|
17
19
|
): Promise<CheckRead & { readonly queuedWithoutRuns: readonly SuiteApp[] }> {
|
|
18
|
-
const read = await
|
|
20
|
+
const read = await withoutReplacedCancels(
|
|
21
|
+
reader,
|
|
22
|
+
facts,
|
|
23
|
+
await resolveChecks(reader, facts.context)
|
|
24
|
+
);
|
|
19
25
|
if (
|
|
20
26
|
read.checks.some(
|
|
21
27
|
(check) => check.kind === "failed" || check.kind === "pending"
|
|
@@ -35,3 +41,43 @@ export async function resolveHeadChecks(
|
|
|
35
41
|
? { ...read, checks: [...read.checks, ...checks], queuedWithoutRuns }
|
|
36
42
|
: { kind: "reported", source: "check-suites", checks, queuedWithoutRuns };
|
|
37
43
|
}
|
|
44
|
+
|
|
45
|
+
const RUN_ID = /\/actions\/runs\/(\d+)(?:\/|$)/;
|
|
46
|
+
const cancelledRunId = (check: Check): number | null => {
|
|
47
|
+
if (check.kind !== "failed" || check.reportedState !== "CANCELLED")
|
|
48
|
+
return null;
|
|
49
|
+
const match = RUN_ID.exec(check.link);
|
|
50
|
+
return match === null ? null : Number(match[1]);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// gh lists a job of a cancelled workflow run when no job of a later run has
|
|
54
|
+
// its name, as when the run was cancelled before its matrix expanded. A later
|
|
55
|
+
// run of the same workflow and event on the head that finished, by succeeding
|
|
56
|
+
// or failing to start, replaces it, and its own checks then decide. A
|
|
57
|
+
// cancelled check that is not shown to be replaced stays failed. When another
|
|
58
|
+
// check failed, the verdict is already decided and the runs go unread.
|
|
59
|
+
async function withoutReplacedCancels(
|
|
60
|
+
reader: GitHubReader,
|
|
61
|
+
facts: Pick<LandingRevision, "context" | "headRefOid">,
|
|
62
|
+
read: CheckRead
|
|
63
|
+
): Promise<CheckRead> {
|
|
64
|
+
if (
|
|
65
|
+
read.kind !== "reported" ||
|
|
66
|
+
read.checks.every((check) => cancelledRunId(check) === null) ||
|
|
67
|
+
read.checks.some(
|
|
68
|
+
(check) => check.kind === "failed" && cancelledRunId(check) === null
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
return read;
|
|
72
|
+
const replaced = replacedRunIds(
|
|
73
|
+
await reader.workflowRunPages(facts.context, facts.headRefOid),
|
|
74
|
+
facts.headRefOid
|
|
75
|
+
);
|
|
76
|
+
const checks = nonEmpty(
|
|
77
|
+
read.checks.filter((check) => {
|
|
78
|
+
const runId = cancelledRunId(check);
|
|
79
|
+
return runId === null || !replaced.has(runId);
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
return checks === null ? read : { ...read, checks };
|
|
83
|
+
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { fakeReader, failedCheck, pendingCheck } from "./fakes.test-helper.ts";
|
|
12
12
|
import { unsettledSuiteChecks } from "./github.ts";
|
|
13
13
|
import type {
|
|
14
|
+
Check,
|
|
14
15
|
GitHubReader,
|
|
15
16
|
NonEmpty,
|
|
16
17
|
PollingOptions,
|
|
@@ -877,6 +878,163 @@ describe("check suites that no check read shows", () => {
|
|
|
877
878
|
});
|
|
878
879
|
});
|
|
879
880
|
|
|
881
|
+
// grafana/grafana PR 139612 at 8c63a54b, read on 2026-12-03: gh pr checks
|
|
882
|
+
// listed a Bundle size job cancelled before its matrix expanded, so no job of
|
|
883
|
+
// the later, passing Bundle size run shares its name. Both runs are workflow
|
|
884
|
+
// 342766777 on pull_request.
|
|
885
|
+
describe("a cancelled check from a run a later run replaced", () => {
|
|
886
|
+
const head = "8c63a54b5334bc97775bbfcfe858424434ff2d1f";
|
|
887
|
+
const jobLink = (run: number, job: number) =>
|
|
888
|
+
`https://github.com/grafana/grafana/actions/runs/${run}/job/${job}`;
|
|
889
|
+
const cancelled = {
|
|
890
|
+
kind: "failed",
|
|
891
|
+
name: "Build ${{ matrix.target }} frontend",
|
|
892
|
+
reportedState: "CANCELLED",
|
|
893
|
+
description: "",
|
|
894
|
+
link: jobLink(47100668579, 144370325863),
|
|
895
|
+
workflow: "Bundle size",
|
|
896
|
+
} as const;
|
|
897
|
+
const rebuilt = {
|
|
898
|
+
kind: "passed",
|
|
899
|
+
name: "Build pr frontend",
|
|
900
|
+
reportedState: "SUCCESS",
|
|
901
|
+
description: "",
|
|
902
|
+
link: jobLink(47139247402, 144371788751),
|
|
903
|
+
workflow: "Bundle size",
|
|
904
|
+
} as const;
|
|
905
|
+
const run = (
|
|
906
|
+
id: number,
|
|
907
|
+
suite: number,
|
|
908
|
+
createdAt: string,
|
|
909
|
+
conclusion: string | null
|
|
910
|
+
) => ({
|
|
911
|
+
id,
|
|
912
|
+
workflow_id: 342766777,
|
|
913
|
+
check_suite_id: suite,
|
|
914
|
+
event: "pull_request",
|
|
915
|
+
head_sha: head,
|
|
916
|
+
status: conclusion === null ? "in_progress" : "completed",
|
|
917
|
+
conclusion,
|
|
918
|
+
created_at: createdAt,
|
|
919
|
+
name: "Bundle size",
|
|
920
|
+
});
|
|
921
|
+
const first = run(
|
|
922
|
+
47100668579,
|
|
923
|
+
127381116871,
|
|
924
|
+
"2026-12-03T11:56:06Z",
|
|
925
|
+
"cancelled"
|
|
926
|
+
);
|
|
927
|
+
const second = run(
|
|
928
|
+
47139247402,
|
|
929
|
+
127486757905,
|
|
930
|
+
"2026-12-03T15:29:54Z",
|
|
931
|
+
"success"
|
|
932
|
+
);
|
|
933
|
+
const read = async (
|
|
934
|
+
checks: readonly Check[],
|
|
935
|
+
workflowRuns: readonly unknown[]
|
|
936
|
+
) => {
|
|
937
|
+
const reader = fakeReader({
|
|
938
|
+
facts: { headRefOid: head },
|
|
939
|
+
fastPath: { kind: "checks", checks: checks as [Check, ...Check[]] },
|
|
940
|
+
commitRollups: [{ oid: head, state: "SUCCESS" }],
|
|
941
|
+
workflowRuns,
|
|
942
|
+
});
|
|
943
|
+
const snapshot = await readSnapshot({
|
|
944
|
+
reader,
|
|
945
|
+
context: context(40),
|
|
946
|
+
pendingHistory: "include",
|
|
947
|
+
allowDraft: false,
|
|
948
|
+
});
|
|
949
|
+
return { snapshot, calls: reader.calls };
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
it("drops it when a later run of the same workflow and event succeeded", async () => {
|
|
953
|
+
const { snapshot, calls } = await read(
|
|
954
|
+
[cancelled, rebuilt],
|
|
955
|
+
[second, first]
|
|
956
|
+
);
|
|
957
|
+
expect(snapshot).toMatchObject({ ci: { kind: "ci-clean" } });
|
|
958
|
+
expect(calls).toContain(`workflowRunPages:${head}`);
|
|
959
|
+
expect(calls).toContain(`unsettledSuites:${head}:reported`);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
// gh lists only the jobs a run has started, so a running replacement can
|
|
963
|
+
// show nothing but passes between one job and the next.
|
|
964
|
+
it("keeps it failed while the later run is still running", async () => {
|
|
965
|
+
const running = {
|
|
966
|
+
...rebuilt,
|
|
967
|
+
kind: "pending",
|
|
968
|
+
reportedState: "IN_PROGRESS",
|
|
969
|
+
} as const;
|
|
970
|
+
for (const checks of [
|
|
971
|
+
[cancelled, running],
|
|
972
|
+
[cancelled, rebuilt],
|
|
973
|
+
])
|
|
974
|
+
expect(
|
|
975
|
+
(
|
|
976
|
+
await read(checks, [
|
|
977
|
+
{ ...second, status: "in_progress", conclusion: null },
|
|
978
|
+
first,
|
|
979
|
+
])
|
|
980
|
+
).snapshot
|
|
981
|
+
).toMatchObject({ ci: { kind: "ci-failing", failed: [cancelled] } });
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
it("keeps it failed, and reads no runs, when another check failed", async () => {
|
|
985
|
+
const failing = failedCheck();
|
|
986
|
+
const { snapshot, calls } = await read(
|
|
987
|
+
[cancelled, rebuilt, failing],
|
|
988
|
+
[second, first]
|
|
989
|
+
);
|
|
990
|
+
expect(snapshot).toMatchObject({
|
|
991
|
+
ci: { kind: "ci-failing", failed: [cancelled, failing] },
|
|
992
|
+
});
|
|
993
|
+
expect(calls.filter((call) => call.startsWith("workflowRunPages"))).toEqual(
|
|
994
|
+
[]
|
|
995
|
+
);
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it("keeps it failed when no later run replaced it", async () => {
|
|
999
|
+
for (const runs of [
|
|
1000
|
+
[first],
|
|
1001
|
+
[{ ...second, conclusion: "cancelled" }, first],
|
|
1002
|
+
[{ ...second, event: "push" }, first],
|
|
1003
|
+
])
|
|
1004
|
+
expect((await read([cancelled, rebuilt], runs)).snapshot).toMatchObject({
|
|
1005
|
+
ci: { kind: "ci-failing", failed: [cancelled] },
|
|
1006
|
+
});
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
it("keeps it failed when its run is not one of the head's runs", async () => {
|
|
1010
|
+
const { snapshot } = await read([cancelled, rebuilt], [second]);
|
|
1011
|
+
expect(snapshot).toMatchObject({
|
|
1012
|
+
ci: { kind: "ci-failing", failed: [cancelled] },
|
|
1013
|
+
});
|
|
1014
|
+
});
|
|
1015
|
+
|
|
1016
|
+
it("keeps it failed, and reads no runs, when its link names no run", async () => {
|
|
1017
|
+
const unlinked = { ...cancelled, link: "" };
|
|
1018
|
+
const { snapshot, calls } = await read(
|
|
1019
|
+
[unlinked, rebuilt],
|
|
1020
|
+
[second, first]
|
|
1021
|
+
);
|
|
1022
|
+
expect(snapshot).toMatchObject({
|
|
1023
|
+
ci: { kind: "ci-failing", failed: [unlinked] },
|
|
1024
|
+
});
|
|
1025
|
+
expect(calls.filter((call) => call.startsWith("workflowRunPages"))).toEqual(
|
|
1026
|
+
[]
|
|
1027
|
+
);
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
it("reads no runs when no check was cancelled", async () => {
|
|
1031
|
+
const { calls } = await read([rebuilt, failedCheck()], [second, first]);
|
|
1032
|
+
expect(calls.filter((call) => call.startsWith("workflowRunPages"))).toEqual(
|
|
1033
|
+
[]
|
|
1034
|
+
);
|
|
1035
|
+
});
|
|
1036
|
+
});
|
|
1037
|
+
|
|
880
1038
|
describe("apps named with --expect-app", () => {
|
|
881
1039
|
const queuedSuite = (slug: string, name: string) => ({
|
|
882
1040
|
head_sha: "head",
|