open-pstack 0.9.174 → 0.9.175
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/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/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/scripts/.prettierignore +3 -0
- 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 +33 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/github.ts +25 -23
- 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/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/plugin.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"name": "octocat-hello-world-34-no-checks",
|
|
4
|
+
"owner": "octocat",
|
|
5
|
+
"repo": "Hello-World",
|
|
6
|
+
"pr": 34,
|
|
7
|
+
"head": "466b43dba94438a264452fea015a95c0217fb74f",
|
|
8
|
+
"property": "no-checks-and-no-suites",
|
|
9
|
+
"expected": {
|
|
10
|
+
"status": { "exitCode": 0, "kind": "STATUS", "ci": "ci-unreported" },
|
|
11
|
+
"watch": { "exitCode": 0, "kind": "READY", "detail": null, "failed": [] }
|
|
12
|
+
},
|
|
13
|
+
"because": "The repository runs no CI: gh pr checks says no checks were reported, the head has no rollup and no check suite, and no commit on the pull request ever reported one. One read cannot tell that from a head whose checks have not registered yet, so a status-only pass reports ci-unreported. A watch sees the same head again 60 seconds later, which confirms there are no checks. GitHub reports MERGEABLE and CLEAN, no review is required and no thread is open, so the watch ends READY."
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "grafana-139602-cancelled-suites-beside-green",
|
|
17
|
+
"owner": "grafana",
|
|
18
|
+
"repo": "grafana",
|
|
19
|
+
"pr": 139602,
|
|
20
|
+
"head": "d2ae7ba331660a4a5b160b12745973e64e7a3971",
|
|
21
|
+
"property": "cancelled-suite-beside-green-checks",
|
|
22
|
+
"expected": {
|
|
23
|
+
"status": { "exitCode": 0, "kind": "STATUS", "ci": "ci-failing" },
|
|
24
|
+
"watch": {
|
|
25
|
+
"exitCode": 4,
|
|
26
|
+
"kind": "BLOCKER",
|
|
27
|
+
"detail": "failing-checks",
|
|
28
|
+
"failed": [
|
|
29
|
+
"STARTUP_FAILURE: Auto-milestone workflow",
|
|
30
|
+
"STARTUP_FAILURE: External PR Notify Trigger workflow",
|
|
31
|
+
"STARTUP_FAILURE: PR automation workflow"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"because": "Every check gh pr checks lists passed or was skipped, and GitHub's rollup is SUCCESS. Two Actions suites concluded cancelled: Integration Tests and Build Go (matrix) were each cancelled and then succeeded in a later run on the same head, so the cancelled suites are replaced runs and must not be named as failures. Three other workflows (PR automation, Auto-milestone, External PR Notify Trigger) each have one run on the head, which concluded startup_failure with no check run and no later run. watch-pr counts a workflow that failed to start and was not run again as a failed check, because no check read shows it. So the verdict is a failing-checks blocker that names those three workflows and neither cancelled one."
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "grafana-139612-cancelled-check-beside-green",
|
|
39
|
+
"owner": "grafana",
|
|
40
|
+
"repo": "grafana",
|
|
41
|
+
"pr": 139612,
|
|
42
|
+
"head": "8c63a54b5334bc97775bbfcfe858424434ff2d1f",
|
|
43
|
+
"property": "cancelled-check-beside-green-checks",
|
|
44
|
+
"expected": {
|
|
45
|
+
"status": { "exitCode": 0, "kind": "STATUS", "ci": "ci-failing" },
|
|
46
|
+
"watch": {
|
|
47
|
+
"exitCode": 4,
|
|
48
|
+
"kind": "BLOCKER",
|
|
49
|
+
"detail": "failing-checks",
|
|
50
|
+
"failed": ["CANCELLED: Build ${{ matrix.target }} frontend"]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"because": "gh pr checks lists one cancelled check among the passing and skipped ones: a Bundle size job cancelled before its matrix expanded, so its name matches no later check and gh keeps it. This answer was recorded before the recorder kept each check's link, so the check names no run. watch-pr drops a cancelled check only when its link names a run that a later run of the same workflow and event on the head replaced, so here the check stays failed and the verdict is a failing-checks blocker that names it. The read stops there and never reaches the suites, where five workflows that failed to start would block as well. On 2026-12-03 the live answer carried the link to run 47100668579, which run 47139247402 of the same workflow and event replaced with a success, so a live read drops the check and goes on to the suites. The PR has since merged, so this fixture can't be refreshed to show that."
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "grafana-139606-approval-gated",
|
|
57
|
+
"owner": "grafana",
|
|
58
|
+
"repo": "grafana",
|
|
59
|
+
"pr": 139606,
|
|
60
|
+
"head": "6750dab797744e09f02ff1563e647fd7474b3c1f",
|
|
61
|
+
"property": "approval-gated-suites-beside-pending-checks",
|
|
62
|
+
"expected": {
|
|
63
|
+
"status": { "exitCode": 0, "kind": "STATUS", "ci": "ci-pending" },
|
|
64
|
+
"watch": {
|
|
65
|
+
"exitCode": 5,
|
|
66
|
+
"kind": "TIMEOUT",
|
|
67
|
+
"detail": "pending-checks",
|
|
68
|
+
"failed": []
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"because": "gh pr checks lists two pending commit statuses from policy-bot beside four passes, and no failure. watch-pr reads a head's suites only when no listed check failed or is pending, so it reports ci-pending and waits; the review-required gate is deferred while checks are pending. Nothing on a recorded head changes, so the watch polls until its deadline and ends TIMEOUT, waiting on pending checks. Open question, pinned here and not decided: 35 Actions suites on this head concluded action_required with no check run, which means a maintainer must approve the workflows. When no check is pending watch-pr reports that gate as a blocker at once, and here the pending statuses keep it from being read."
|
|
72
|
+
}
|
|
73
|
+
]
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
// Records, and refreshes, the replay corpus: for each head in heads.json it
|
|
2
|
+
// runs watch-pr against GitHub through the recording `gh` (gh.ts), which
|
|
3
|
+
// passes on reads only, and writes fixtures/<name>.json.
|
|
4
|
+
//
|
|
5
|
+
// bun watch-pr/replay/record.ts every head in heads.json
|
|
6
|
+
// bun watch-pr/replay/record.ts <name>... only these
|
|
7
|
+
//
|
|
8
|
+
// A fixture holds each answer once, cut down to the fields watch-pr parses,
|
|
9
|
+
// with review comment text and reviewer names removed. Beside the answers it
|
|
10
|
+
// holds `evidence`: the head's facts read straight from GitHub, which no
|
|
11
|
+
// watch-pr code touches.
|
|
12
|
+
// The `expected` verdict in heads.json is set by hand from that evidence.
|
|
13
|
+
//
|
|
14
|
+
// A fixture is written only when all of these hold, and the script exits 1
|
|
15
|
+
// otherwise:
|
|
16
|
+
// - No answer changed mid-run.
|
|
17
|
+
// - GitHub's answer names the recorded head as the PR's head (movedHead).
|
|
18
|
+
// - The evidence shows the head's `property`, the reason it is in the corpus.
|
|
19
|
+
// - The cut-down fixture replays to the verdict the live run gave.
|
|
20
|
+
// It then says whether that verdict is the `expected` one. When it is not,
|
|
21
|
+
// read the evidence it prints and set `expected` and `because` by hand.
|
|
22
|
+
import { spawnSync } from "node:child_process";
|
|
23
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
24
|
+
import { tmpdir } from "node:os";
|
|
25
|
+
import { delimiter, join } from "node:path";
|
|
26
|
+
import type { Fixture, LoggedCall, RecordedCall } from "./gh.ts";
|
|
27
|
+
import {
|
|
28
|
+
dig,
|
|
29
|
+
fixturePath,
|
|
30
|
+
ghOnPath,
|
|
31
|
+
heads,
|
|
32
|
+
movedHead,
|
|
33
|
+
outcomeOf,
|
|
34
|
+
runWatch,
|
|
35
|
+
type Head,
|
|
36
|
+
type Property,
|
|
37
|
+
} from "./harness.ts";
|
|
38
|
+
|
|
39
|
+
type Json = Record<string, unknown>;
|
|
40
|
+
const isObject = (value: unknown): value is Json =>
|
|
41
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
42
|
+
const pick = (value: unknown, keys: readonly string[]): Json =>
|
|
43
|
+
Object.fromEntries(
|
|
44
|
+
keys
|
|
45
|
+
.filter((name) => isObject(value) && name in value)
|
|
46
|
+
.map((name) => [name, (value as Json)[name]])
|
|
47
|
+
);
|
|
48
|
+
const rows = (pages: unknown, name: string): Json[] =>
|
|
49
|
+
(Array.isArray(pages) ? pages : []).flatMap((page) =>
|
|
50
|
+
isObject(page) && Array.isArray(page[name]) ? (page[name] as Json[]) : []
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const SUITE_FIELDS = [
|
|
54
|
+
"id",
|
|
55
|
+
"head_sha",
|
|
56
|
+
"status",
|
|
57
|
+
"conclusion",
|
|
58
|
+
"latest_check_runs_count",
|
|
59
|
+
];
|
|
60
|
+
const RUN_FIELDS = [
|
|
61
|
+
"id",
|
|
62
|
+
"workflow_id",
|
|
63
|
+
"check_suite_id",
|
|
64
|
+
"event",
|
|
65
|
+
"head_sha",
|
|
66
|
+
"status",
|
|
67
|
+
"conclusion",
|
|
68
|
+
"created_at",
|
|
69
|
+
"name",
|
|
70
|
+
];
|
|
71
|
+
const pruneSuites = (pages: unknown): unknown => [
|
|
72
|
+
{
|
|
73
|
+
check_suites: rows(pages, "check_suites").map((suite) => ({
|
|
74
|
+
...pick(suite, SUITE_FIELDS),
|
|
75
|
+
app: pick(suite.app, ["slug", "name"]),
|
|
76
|
+
})),
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
const pruneRuns = (pages: unknown): unknown => [
|
|
80
|
+
{
|
|
81
|
+
workflow_runs: rows(pages, "workflow_runs").map((run) =>
|
|
82
|
+
pick(run, RUN_FIELDS)
|
|
83
|
+
),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
// A review comment's text and its author's name are someone's, and no
|
|
87
|
+
// fixture needs them. watch-pr tells a review bot by a login that contains
|
|
88
|
+
// "bugbot" or is "cursor", so those two stay and every other login becomes
|
|
89
|
+
// "someone".
|
|
90
|
+
const reviewBot = (login: string): boolean =>
|
|
91
|
+
/bugbot/i.test(login) || login.toLowerCase() === "cursor";
|
|
92
|
+
const anonymous = (name: string, item: unknown): unknown =>
|
|
93
|
+
typeof item !== "string"
|
|
94
|
+
? withoutPeople(item)
|
|
95
|
+
: name === "body"
|
|
96
|
+
? ""
|
|
97
|
+
: name === "login" && !reviewBot(item)
|
|
98
|
+
? "someone"
|
|
99
|
+
: item;
|
|
100
|
+
const withoutPeople = (value: unknown): unknown =>
|
|
101
|
+
Array.isArray(value)
|
|
102
|
+
? value.map(withoutPeople)
|
|
103
|
+
: isObject(value)
|
|
104
|
+
? Object.fromEntries(
|
|
105
|
+
Object.entries(value).map(([name, item]) => [
|
|
106
|
+
name,
|
|
107
|
+
anonymous(name, item),
|
|
108
|
+
])
|
|
109
|
+
)
|
|
110
|
+
: value;
|
|
111
|
+
|
|
112
|
+
// One answer, cut down to what watch-pr parses out of it.
|
|
113
|
+
function prune(name: string, json: unknown): unknown {
|
|
114
|
+
if (name.startsWith("pr checks ") && Array.isArray(json))
|
|
115
|
+
return json.map((check) =>
|
|
116
|
+
pick(check, ["name", "state", "bucket", "workflow", "link"])
|
|
117
|
+
);
|
|
118
|
+
if (name.includes("/check-suites?")) return pruneSuites(json);
|
|
119
|
+
if (name.includes("/actions/runs?")) return pruneRuns(json);
|
|
120
|
+
if (name.startsWith("graphql ReviewThreads ")) return withoutPeople(json);
|
|
121
|
+
return json;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function parsed(text: string): unknown {
|
|
125
|
+
try {
|
|
126
|
+
return JSON.parse(text);
|
|
127
|
+
} catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// A read of GitHub that watch-pr may not have made, for the evidence.
|
|
133
|
+
function ghJson(gh: string, args: readonly string[]): unknown {
|
|
134
|
+
const result = spawnSync(gh, [...args], {
|
|
135
|
+
encoding: "utf8",
|
|
136
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
137
|
+
});
|
|
138
|
+
if (result.status !== 0)
|
|
139
|
+
throw new Error(
|
|
140
|
+
`gh ${args.join(" ")}: ${result.stderr.trim().split("\n")[0]}`
|
|
141
|
+
);
|
|
142
|
+
return JSON.parse(result.stdout);
|
|
143
|
+
}
|
|
144
|
+
const tally = (names: readonly string[]): Record<string, number> =>
|
|
145
|
+
Object.fromEntries(
|
|
146
|
+
[...new Set(names)]
|
|
147
|
+
.sort()
|
|
148
|
+
.map((name) => [name, names.filter((other) => other === name).length])
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
// The head's facts as GitHub states them: nothing here goes through watch-pr.
|
|
152
|
+
function evidenceOf(
|
|
153
|
+
head: Head,
|
|
154
|
+
gh: string,
|
|
155
|
+
calls: Readonly<Record<string, RecordedCall>>
|
|
156
|
+
): Json {
|
|
157
|
+
const answer = (prefix: string): RecordedCall | undefined =>
|
|
158
|
+
calls[Object.keys(calls).find((name) => name.startsWith(prefix)) ?? ""];
|
|
159
|
+
const facts = dig(
|
|
160
|
+
answer("graphql PullRequestFacts ")?.json,
|
|
161
|
+
"data",
|
|
162
|
+
"repository",
|
|
163
|
+
"pullRequest"
|
|
164
|
+
);
|
|
165
|
+
const commits = dig(
|
|
166
|
+
answer("graphql PrCommitStatuses ")?.json,
|
|
167
|
+
"data",
|
|
168
|
+
"repository",
|
|
169
|
+
"pullRequest",
|
|
170
|
+
"commits",
|
|
171
|
+
"nodes"
|
|
172
|
+
);
|
|
173
|
+
const threads = dig(
|
|
174
|
+
answer("graphql ReviewThreads ")?.json,
|
|
175
|
+
"data",
|
|
176
|
+
"repository",
|
|
177
|
+
"pullRequest",
|
|
178
|
+
"reviewThreads",
|
|
179
|
+
"nodes"
|
|
180
|
+
);
|
|
181
|
+
const checks = answer("pr checks ");
|
|
182
|
+
const listed = Array.isArray(checks?.json) ? (checks.json as Json[]) : [];
|
|
183
|
+
const repo = `repos/${head.owner}/${head.repo}`;
|
|
184
|
+
const suites = rows(
|
|
185
|
+
ghJson(gh, [
|
|
186
|
+
"api",
|
|
187
|
+
"--paginate",
|
|
188
|
+
"--slurp",
|
|
189
|
+
`${repo}/commits/${head.head}/check-suites?per_page=100`,
|
|
190
|
+
]),
|
|
191
|
+
"check_suites"
|
|
192
|
+
);
|
|
193
|
+
const runs = rows(
|
|
194
|
+
ghJson(gh, [
|
|
195
|
+
"api",
|
|
196
|
+
"--paginate",
|
|
197
|
+
"--slurp",
|
|
198
|
+
`${repo}/actions/runs?head_sha=${head.head}&per_page=100`,
|
|
199
|
+
]),
|
|
200
|
+
"workflow_runs"
|
|
201
|
+
);
|
|
202
|
+
const byWorkflow = Map.groupBy(
|
|
203
|
+
runs,
|
|
204
|
+
(run) => `${run.workflow_id}:${run.event}`
|
|
205
|
+
);
|
|
206
|
+
const histories = [...byWorkflow.values()]
|
|
207
|
+
.filter((history) =>
|
|
208
|
+
history.some(
|
|
209
|
+
(run) =>
|
|
210
|
+
run.conclusion === "cancelled" || run.conclusion === "startup_failure"
|
|
211
|
+
)
|
|
212
|
+
)
|
|
213
|
+
.map((history) => {
|
|
214
|
+
const ordered = history.toSorted((left, right) =>
|
|
215
|
+
String(left.created_at).localeCompare(String(right.created_at))
|
|
216
|
+
);
|
|
217
|
+
return `${ordered[0].name} (${ordered[0].event}): ${ordered.map((run) => run.conclusion ?? run.status).join(", then ")}`;
|
|
218
|
+
});
|
|
219
|
+
return {
|
|
220
|
+
pullRequest: pick(facts, [
|
|
221
|
+
"state",
|
|
222
|
+
"isDraft",
|
|
223
|
+
"mergeable",
|
|
224
|
+
"mergeStateStatus",
|
|
225
|
+
"reviewDecision",
|
|
226
|
+
]),
|
|
227
|
+
headRollup: Array.isArray(commits)
|
|
228
|
+
? (dig(commits.at(-1), "commit", "statusCheckRollup", "state") ?? null)
|
|
229
|
+
: "not read",
|
|
230
|
+
unresolvedThreads: Array.isArray(threads)
|
|
231
|
+
? threads.filter((thread) => !dig(thread, "isResolved")).length
|
|
232
|
+
: "not read",
|
|
233
|
+
checks:
|
|
234
|
+
checks?.code === 0 || listed.length > 0
|
|
235
|
+
? tally(listed.map((check) => String(check.bucket)))
|
|
236
|
+
: (checks?.stderr ?? "").trim().split("\n")[0],
|
|
237
|
+
checksNotPassing: listed
|
|
238
|
+
.filter((check) => !["pass", "skipping"].includes(String(check.bucket)))
|
|
239
|
+
.map(
|
|
240
|
+
(check) =>
|
|
241
|
+
`${check.bucket} ${check.state}: ${check.workflow ? `${check.workflow} / ` : ""}${check.name}`
|
|
242
|
+
),
|
|
243
|
+
suites: tally(
|
|
244
|
+
suites.map(
|
|
245
|
+
(suite) =>
|
|
246
|
+
`${dig(suite, "app", "slug")} ${suite.conclusion ?? suite.status}, ${Number(suite.latest_check_runs_count) > 0 ? "with" : "no"} check runs`
|
|
247
|
+
)
|
|
248
|
+
),
|
|
249
|
+
workflowsWithACancelledOrStartupFailedRun: histories.sort(),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const count = (evidence: Json, pattern: RegExp): number =>
|
|
254
|
+
Object.entries((evidence.suites ?? {}) as Record<string, number>)
|
|
255
|
+
.filter(([name]) => pattern.test(name))
|
|
256
|
+
.reduce((sum, [, n]) => sum + n, 0);
|
|
257
|
+
const bucket = (evidence: Json, name: string): number =>
|
|
258
|
+
isObject(evidence.checks) ? Number(evidence.checks[name] ?? 0) : 0;
|
|
259
|
+
|
|
260
|
+
// What the evidence must show for a head to stay in the corpus.
|
|
261
|
+
const PROPERTIES: Record<Property, (evidence: Json) => boolean> = {
|
|
262
|
+
"cancelled-suite-beside-green-checks": (evidence) =>
|
|
263
|
+
count(evidence, / cancelled, with check runs$/) > 0 &&
|
|
264
|
+
count(evidence, / success, with check runs$/) > 0 &&
|
|
265
|
+
bucket(evidence, "pass") > 0 &&
|
|
266
|
+
bucket(evidence, "fail") +
|
|
267
|
+
bucket(evidence, "cancel") +
|
|
268
|
+
bucket(evidence, "pending") ===
|
|
269
|
+
0,
|
|
270
|
+
"cancelled-check-beside-green-checks": (evidence) =>
|
|
271
|
+
bucket(evidence, "cancel") > 0 &&
|
|
272
|
+
bucket(evidence, "pass") > 0 &&
|
|
273
|
+
bucket(evidence, "fail") + bucket(evidence, "pending") === 0,
|
|
274
|
+
"approval-gated-suites-beside-pending-checks": (evidence) =>
|
|
275
|
+
count(evidence, / action_required, no check runs$/) > 0 &&
|
|
276
|
+
bucket(evidence, "pending") > 0,
|
|
277
|
+
"no-checks-and-no-suites": (evidence) =>
|
|
278
|
+
typeof evidence.checks === "string" &&
|
|
279
|
+
evidence.checks.startsWith("no checks reported on the ") &&
|
|
280
|
+
evidence.headRollup === null &&
|
|
281
|
+
Object.keys((evidence.suites ?? {}) as Json).length === 0,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// Objects and arrays that fit on one line stay on one, so a fixture reads as
|
|
285
|
+
// one check, suite, or run per line.
|
|
286
|
+
function format(value: unknown, indent = ""): string {
|
|
287
|
+
const flat = JSON.stringify(value);
|
|
288
|
+
if (
|
|
289
|
+
flat === undefined ||
|
|
290
|
+
flat.length <= 200 - indent.length ||
|
|
291
|
+
typeof value !== "object" ||
|
|
292
|
+
value === null
|
|
293
|
+
)
|
|
294
|
+
return flat;
|
|
295
|
+
const inner = `${indent} `;
|
|
296
|
+
const items = Array.isArray(value)
|
|
297
|
+
? value.map((item) => format(item, inner))
|
|
298
|
+
: Object.entries(value).map(
|
|
299
|
+
([name, item]) => `${JSON.stringify(name)}: ${format(item, inner)}`
|
|
300
|
+
);
|
|
301
|
+
const [open, close] = Array.isArray(value) ? "[]" : "{}";
|
|
302
|
+
return `${open}\n${items.map((item) => `${inner}${item}`).join(",\n")}\n${indent}${close}`;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// One live run of watch-pr with the recording gh first on PATH. The run keeps
|
|
306
|
+
// this process's environment, which holds gh's sign-in.
|
|
307
|
+
function recording(
|
|
308
|
+
bin: string,
|
|
309
|
+
transport: { readonly gh: string; readonly log: string },
|
|
310
|
+
head: Head
|
|
311
|
+
): ReturnType<typeof runWatch> {
|
|
312
|
+
const path = process.env.PATH ?? "";
|
|
313
|
+
process.env.PATH = `${ghOnPath(bin, transport)}${delimiter}${path}`;
|
|
314
|
+
try {
|
|
315
|
+
return runWatch(head);
|
|
316
|
+
} finally {
|
|
317
|
+
process.env.PATH = path;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function recordHead(head: Head, gh: string): string[] {
|
|
322
|
+
const problems: string[] = [];
|
|
323
|
+
const dir = mkdtempSync(join(tmpdir(), "watch-replay-record-"));
|
|
324
|
+
try {
|
|
325
|
+
const log = join(dir, "log.jsonl");
|
|
326
|
+
writeFileSync(log, "");
|
|
327
|
+
const live = outcomeOf(recording(join(dir, "record"), { gh, log }, head));
|
|
328
|
+
const calls: Record<string, RecordedCall> = {};
|
|
329
|
+
for (const line of readFileSync(log, "utf8").split("\n").filter(Boolean)) {
|
|
330
|
+
const call = JSON.parse(line) as LoggedCall;
|
|
331
|
+
const json = parsed(call.stdout);
|
|
332
|
+
const kept: RecordedCall = {
|
|
333
|
+
code: call.code,
|
|
334
|
+
...(json === undefined
|
|
335
|
+
? call.stdout === ""
|
|
336
|
+
? {}
|
|
337
|
+
: { stdout: call.stdout }
|
|
338
|
+
: { json: prune(call.request, json) }),
|
|
339
|
+
// gh's stderr matters only when it failed, and then by its first line.
|
|
340
|
+
...(call.code === 0
|
|
341
|
+
? {}
|
|
342
|
+
: { stderr: `${call.stderr.trim().split("\n")[0]}\n` }),
|
|
343
|
+
};
|
|
344
|
+
if (!(call.request in calls)) calls[call.request] = kept;
|
|
345
|
+
else if (JSON.stringify(calls[call.request]) !== JSON.stringify(kept))
|
|
346
|
+
problems.push(
|
|
347
|
+
`GitHub's answer changed while recording: ${call.request}: ${JSON.stringify(calls[call.request]).slice(0, 400)} then ${JSON.stringify(kept).slice(0, 400)}`
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
const moved = movedHead(head, calls);
|
|
351
|
+
if (moved !== null) problems.push(moved);
|
|
352
|
+
const evidence = evidenceOf(head, gh, calls);
|
|
353
|
+
console.log(`${head.name}: evidence\n${format(evidence, " ")}`);
|
|
354
|
+
console.log(`${head.name}: watch-pr decided ${JSON.stringify(live)}`);
|
|
355
|
+
if (!PROPERTIES[head.property](evidence))
|
|
356
|
+
problems.push(
|
|
357
|
+
`the evidence no longer shows "${head.property}", so this head has moved on. Pick another head for heads.json`
|
|
358
|
+
);
|
|
359
|
+
const fixture: Fixture & { readonly evidence: Json } = {
|
|
360
|
+
pr: `${head.owner}/${head.repo}#${head.pr}`,
|
|
361
|
+
head: head.head,
|
|
362
|
+
recorded: new Date().toISOString().slice(0, 10),
|
|
363
|
+
evidence,
|
|
364
|
+
calls,
|
|
365
|
+
};
|
|
366
|
+
const candidate = join(dir, "fixture.json");
|
|
367
|
+
writeFileSync(candidate, `${format(fixture)}\n`);
|
|
368
|
+
const replayed = outcomeOf(
|
|
369
|
+
runWatch(head, ghOnPath(join(dir, "replay"), { fixture: candidate }))
|
|
370
|
+
);
|
|
371
|
+
if (JSON.stringify(replayed) !== JSON.stringify(live))
|
|
372
|
+
problems.push(
|
|
373
|
+
`the cut-down fixture replays to ${JSON.stringify(replayed)}, not to the live verdict`
|
|
374
|
+
);
|
|
375
|
+
if (problems.length > 0) return problems;
|
|
376
|
+
writeFileSync(fixturePath(head.name), readFileSync(candidate, "utf8"));
|
|
377
|
+
console.log(`${head.name}: wrote ${fixturePath(head.name)}`);
|
|
378
|
+
if (JSON.stringify(live) !== JSON.stringify(head.expected))
|
|
379
|
+
problems.push(
|
|
380
|
+
`the verdict is not the expected ${JSON.stringify(head.expected)}. Read the evidence, then set expected and because in heads.json by hand`
|
|
381
|
+
);
|
|
382
|
+
return problems;
|
|
383
|
+
} finally {
|
|
384
|
+
rmSync(dir, { recursive: true, force: true });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const names = process.argv.slice(2);
|
|
389
|
+
const unknown = names.filter(
|
|
390
|
+
(name) => !heads().some((head) => head.name === name)
|
|
391
|
+
);
|
|
392
|
+
if (unknown.length > 0) {
|
|
393
|
+
console.error(`no such head in heads.json: ${unknown.join(", ")}`);
|
|
394
|
+
process.exit(64);
|
|
395
|
+
}
|
|
396
|
+
const gh = Bun.which("gh");
|
|
397
|
+
if (gh === null) {
|
|
398
|
+
console.error("record: gh is not on PATH");
|
|
399
|
+
process.exit(69);
|
|
400
|
+
}
|
|
401
|
+
let failed = false;
|
|
402
|
+
for (const head of heads().filter(
|
|
403
|
+
(item) => names.length === 0 || names.includes(item.name)
|
|
404
|
+
)) {
|
|
405
|
+
for (const problem of recordHead(head, gh)) {
|
|
406
|
+
failed = true;
|
|
407
|
+
console.error(`FAIL: ${head.name}: ${problem}`);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
process.exit(failed ? 1 : 0);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Runs watch-pr's own CLI over one pull request head, twice, and prints what
|
|
2
|
+
// it decided as one JSON object: a status-only read, then a watch that runs to
|
|
3
|
+
// its verdict. The reader is the one the CLI builds for itself, so every read
|
|
4
|
+
// goes through whichever `gh` is first on PATH. The clock never waits: a sleep
|
|
5
|
+
// moves its time forward, so a watch that would wait a minute to confirm a
|
|
6
|
+
// head with no checks, or poll until its timeout, ends at once.
|
|
7
|
+
//
|
|
8
|
+
// Usage: bun watch-pr/replay/watch.ts <owner> <repo> <pr> <head-sha>
|
|
9
|
+
import { main, type CliRuntime } from "../cli.ts";
|
|
10
|
+
import { CloudSessionReader, FallbackGitHubReader } from "../cloud-reader.ts";
|
|
11
|
+
import { WatchDeadline } from "../deadline.ts";
|
|
12
|
+
import { GhGitHubReader } from "../github.ts";
|
|
13
|
+
|
|
14
|
+
// A watch whose head never changes ends at this deadline with what it was
|
|
15
|
+
// waiting for. Three polls show that a wait is not a first sighting.
|
|
16
|
+
const WATCH_TIMEOUT_SECONDS = 180;
|
|
17
|
+
|
|
18
|
+
export interface Pass {
|
|
19
|
+
readonly exitCode: number;
|
|
20
|
+
readonly verdicts: readonly Record<string, unknown>[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function pass(argv: readonly string[], timeout: number): Promise<Pass> {
|
|
24
|
+
let now = 0;
|
|
25
|
+
const printed: string[] = [];
|
|
26
|
+
const deadline = new WatchDeadline(timeout, () => now);
|
|
27
|
+
const gh = new GhGitHubReader(deadline);
|
|
28
|
+
const runtime: CliRuntime = {
|
|
29
|
+
deadline,
|
|
30
|
+
reader: new FallbackGitHubReader(gh, new CloudSessionReader(deadline, gh)),
|
|
31
|
+
clock: {
|
|
32
|
+
now: () => now,
|
|
33
|
+
observedAt: () => new Date(0).toISOString(),
|
|
34
|
+
sleep: async (seconds) => {
|
|
35
|
+
now += seconds;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
stdout: (value) => printed.push(value),
|
|
39
|
+
stderr: (value) => process.stderr.write(value),
|
|
40
|
+
};
|
|
41
|
+
const exitCode = await main(argv, runtime);
|
|
42
|
+
const verdicts = printed
|
|
43
|
+
.join("")
|
|
44
|
+
.split("\n")
|
|
45
|
+
.filter((line) => line.trim() !== "")
|
|
46
|
+
.map((line) => JSON.parse(line) as Record<string, unknown>);
|
|
47
|
+
return { exitCode, verdicts };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const [owner, repo, pr, head] = process.argv.slice(2);
|
|
51
|
+
if (!owner || !repo || !pr || !head) {
|
|
52
|
+
console.error(
|
|
53
|
+
"usage: bun watch-pr/replay/watch.ts <owner> <repo> <pr> <head-sha>"
|
|
54
|
+
);
|
|
55
|
+
process.exit(64);
|
|
56
|
+
}
|
|
57
|
+
const target = ["--owner", owner, "--repo", repo, "--pr", pr, "--head", head];
|
|
58
|
+
const status = await pass(
|
|
59
|
+
[...target, "--status-only", "--max-query-errors", "1"],
|
|
60
|
+
0
|
|
61
|
+
);
|
|
62
|
+
const watch = await pass(
|
|
63
|
+
[
|
|
64
|
+
...target,
|
|
65
|
+
"--max-query-errors",
|
|
66
|
+
"1",
|
|
67
|
+
"--timeout",
|
|
68
|
+
String(WATCH_TIMEOUT_SECONDS),
|
|
69
|
+
],
|
|
70
|
+
WATCH_TIMEOUT_SECONDS
|
|
71
|
+
);
|
|
72
|
+
process.stdout.write(`${JSON.stringify({ status, watch })}\n`);
|