Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

pullRequestWatch.test.ts

1,050 lines44.6 KB

1import {
2 type PullRequestCheck,
3 PullRequestComment,
4 ThreadPullRequestWatch,
5} from "@t3tools/contracts";
6import { assert, describe, it } from "@effect/vitest";
7​
8import {
9 PULL_REQUEST_WATCH_WAKE_LIMIT,
10 evaluatePullRequestWatch as evaluate,
11 pullRequestWatchEndMessage,
12 pullRequestWatchMessage,
13} from "./pullRequestWatch.ts";
14​
15// These cases read the head once or at one moment, so the no-checks notice never comes due.
16const evaluatePullRequestWatch = (
17 ...args: Parameters<typeof evaluate> extends [...infer Head, number] ? Head : never
18) => evaluate(...args, 0);
19​
20const STARTED = "2026-10-02T12:00:00.000Z";
21​
22const watch = (overrides: Partial<ThreadPullRequestWatch> = {}): ThreadPullRequestWatch => ({
23 startedAt: STARTED,
24 headSha: null,
25 failedChecks: [],
26 passed: false,
27 passedChecks: [],
28 remarksThrough: STARTED,
29 remarkIds: [],
30 conflicting: false,
31 wakes: 0,
32 ...overrides,
33});
34​
35const run = (id: number) => `https://github.com/o/r/actions/runs/${id}`;
36​
37const check = (name: string, status: PullRequestCheck["status"]): PullRequestCheck => ({
38 name,
39 status,
40 description: null,
41 url: `https://ci.example/${name}`,
42});
43​
44type Detail = Parameters<typeof evaluatePullRequestWatch>[1];
45​
46const capabilities = (checksAlwaysReport: boolean): Detail["capabilities"] => ({
47 diff: true,
48 comment: true,
49 actions: [],
50 mergeMethods: [],
51 search: false,
52 review: { inlineComment: false, reply: false, resolve: false, verdicts: [] },
53 reviewers: { request: false, listCandidates: false },
54 checksAlwaysReport,
55});
56​
57const detail = (overrides: Partial<Detail> = {}): Detail => ({
58 capabilities: capabilities(true),
59 headSha: "aaaaaaaaaa",
60 checks: [check("lint", "success"), check("test", "pending")],
61 mergeability: "mergeable",
62 viewer: "agent-user",
63 author: { login: "agent-user", name: null, avatarUrl: null },
64 ...overrides,
65});
66​
67const remark = (
68 login: string,
69 createdAt: string,
70 body = "Please rename this.",
71): PullRequestComment => ({
72 id: `${login}-${createdAt}`,
73 kind: "review-comment",
74 author: { login, name: null, avatarUrl: null },
75 body,
76 createdAt,
77 url: `https://github.com/o/r/pull/1#${login}`,
78 path: "src/index.ts",
79 reviewState: null,
80});
81​
82const noRemarks: ReadonlyArray<PullRequestComment> = [];
83​
84describe("evaluatePullRequestWatch", () => {
85 it.each(["pending", "success"] as const)(
86 "reports a required rebase once with %s CI",
87 (status) => {
88 const blocked = detail({
89 mergeability: "unknown",
90 rebaseRequired: true,
91 checks: [check("test", status)],
92 });
93 const first = evaluatePullRequestWatch(watch(), blocked, noRemarks);
94 assert.include(
95 first.changes.map((change) => change.kind),
96 "needs-rebase",
97 );
98 assert.deepEqual(evaluatePullRequestWatch(first.next, blocked, noRemarks).changes, []);
99 const unknown = evaluatePullRequestWatch(
100 first.next,
101 { ...blocked, rebaseRequired: undefined },
102 noRemarks,
103 );
104 assert.deepEqual(evaluatePullRequestWatch(unknown.next, blocked, noRemarks).changes, []);
105 const clean = evaluatePullRequestWatch(
106 first.next,
107 { ...blocked, rebaseRequired: false },
108 noRemarks,
109 );
110 assert.deepEqual(evaluatePullRequestWatch(clean.next, blocked, noRemarks).changes, [
111 { kind: "needs-rebase" },
112 ]);
113 assert.include(
114 evaluatePullRequestWatch(
115 first.next,
116 { ...blocked, headSha: "bbbbbbbbbb" },
117 noRemarks,
118 ).changes.map((change) => change.kind),
119 "needs-rebase",
120 );
121 },
122 );
123​
124 it.each([false, true])("baselines already-passed checks (required: %s)", (required) => {
125 const green = detail({ checks: [{ ...check("test", "success"), required }] });
126 const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, noRemarks);
127 assert.deepEqual(baseline.changes, []);
128 assert.equal(baseline.next.headSha, green.headSha);
129 assert.isTrue(baseline.next.passed);
130 assert.deepEqual(baseline.next.passedChecks, ["test"]);
131 assert.isFalse(baseline.exhausted);
132 assert.deepEqual(evaluatePullRequestWatch(baseline.next, green, noRemarks).changes, []);
133​
134 const pending = evaluatePullRequestWatch(
135 baseline.next,
136 detail({ checks: [{ ...check("test", "pending"), required }] }),
137 noRemarks,
138 );
139 assert.deepEqual(pending.changes, []);
140 const failed = evaluatePullRequestWatch(
141 pending.next,
142 detail({ checks: [{ ...check("test", "failure"), required }] }),
143 noRemarks,
144 );
145 assert.equal(failed.changes[0]?.kind, "checks-failed");
146 const passed = evaluatePullRequestWatch(failed.next, green, noRemarks);
147 assert.deepEqual(passed.changes, [{ kind: "checks-passed", count: 1, required }]);
148 assert.deepEqual(
149 evaluatePullRequestWatch(passed.next, { ...green, headSha: "bbbbbbbbbb" }, noRemarks).changes,
150 [{ kind: "checks-passed", count: 1, required }],
151 );
152 });
153​
154 it("baselines existing failures and conflicts, then reports new ones", () => {
155 const broken = detail({
156 checks: [check("lint", "failure"), check("test", "pending")],
157 mergeability: "conflicting",
158 rebaseRequired: true,
159 });
160 const baseline = evaluatePullRequestWatch(
161 watch({ awaitingBaseline: "all" }),
162 broken,
163 noRemarks,
164 );
165 assert.deepEqual(baseline.changes, []);
166 assert.deepEqual(baseline.next.failedChecks, ["lint"]);
167 assert.isFalse(baseline.next.passed);
168 assert.isTrue(baseline.next.conflicting);
169 assert.isTrue(baseline.next.rebaseRequired);
170 assert.deepEqual(evaluatePullRequestWatch(baseline.next, broken, noRemarks).changes, []);
171​
172 const failed = evaluatePullRequestWatch(
173 baseline.next,
174 { ...broken, checks: [check("lint", "failure"), check("test", "failure")] },
175 noRemarks,
176 );
177 assert.deepEqual(failed.changes, [
178 { kind: "checks-failed", failed: [check("test", "failure")] },
179 ]);
180 const clean = evaluatePullRequestWatch(
181 failed.next,
182 detail({ rebaseRequired: false }),
183 noRemarks,
184 );
185 assert.deepEqual(clean.changes, []);
186 assert.deepEqual(evaluatePullRequestWatch(clean.next, broken, noRemarks).changes, [
187 { kind: "checks-failed", failed: [check("lint", "failure")] },
188 { kind: "conflicting" },
189 { kind: "needs-rebase" },
190 ]);
191 });
192​
193 it("baselines checks already awaiting approval", () => {
194 const gated = detail({ checks: [{ ...check("CI", "action-required"), url: run(1) }] });
195 const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), gated, noRemarks);
196 assert.deepEqual(baseline.changes, []);
197 assert.deepEqual(evaluatePullRequestWatch(baseline.next, gated, noRemarks).changes, []);
198 });
199​
200 it("reports remarks after the watch started while baselining checks and conflicts", () => {
201 const green = detail({
202 checks: [check("test", "success")],
203 mergeability: "conflicting",
204 });
205 const comments = [
206 remark("reviewer", "2026-10-02T11:00:00Z"),
207 remark("reviewer", "2026-10-02T12:06:00Z"),
208 ];
209 const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, comments);
210 assert.deepEqual(baseline.changes, [{ kind: "remarks", remarks: [comments[1]!] }]);
211 assert.isTrue(baseline.next.passed);
212 assert.isTrue(baseline.next.conflicting);
213 assert.equal(baseline.next.wakes, 1);
214 assert.deepEqual(evaluatePullRequestWatch(baseline.next, green, comments).changes, []);
215 });
216​
217 it("reports a failure once the head SHA appears after a baseline without one", () => {
218 const waiting = evaluatePullRequestWatch(
219 watch({ awaitingBaseline: "all" }),
220 detail({ headSha: undefined, checks: [check("test", "pending")] }),
221 noRemarks,
222 );
223 assert.deepEqual(waiting.changes, []);
224 const failed = evaluatePullRequestWatch(
225 waiting.next,
226 detail({ checks: [check("test", "failure")] }),
227 noRemarks,
228 );
229 assert.deepEqual(failed.changes, [
230 { kind: "checks-failed", failed: [check("test", "failure")] },
231 ]);
232 });
233​
234 it("keeps a baseline taken without a head SHA once the SHA appears", () => {
235 const green = detail({ checks: [check("test", "success")] });
236 const baseline = evaluatePullRequestWatch(
237 watch({ awaitingBaseline: "all" }),
238 { ...green, headSha: undefined },
239 noRemarks,
240 );
241 const known = evaluatePullRequestWatch(baseline.next, green, noRemarks);
242 assert.deepEqual(known.changes, []);
243 assert.equal(known.next.headSha, green.headSha);
244 const unknown = evaluatePullRequestWatch(
245 known.next,
246 { ...green, headSha: undefined },
247 noRemarks,
248 );
249 assert.equal(unknown.next.headSha, green.headSha);
250 assert.deepEqual(
251 evaluatePullRequestWatch(unknown.next, { ...green, headSha: "bbbbbbbbbb" }, noRemarks)
252 .changes,
253 [{ kind: "checks-passed", count: 1, required: false }],
254 );
255 });
256​
257 it.each(["success", "failure"] as const)(
258 "reports %s on checks that appear after a first read without any",
259 (status) => {
260 const empty = evaluatePullRequestWatch(
261 watch({ awaitingBaseline: "all" }),
262 detail({ checks: [] }),
263 noRemarks,
264 );
265 assert.deepEqual(empty.changes, []);
266 assert.isUndefined(empty.next.awaitingBaseline);
267 assert.isTrue(empty.next.checksPending);
268 assert.deepEqual(
269 evaluatePullRequestWatch(empty.next, detail({ checks: [check("test", status)] }), noRemarks)
270 .changes,
271 status === "success"
272 ? [{ kind: "checks-passed", count: 1, required: false }]
273 : [{ kind: "checks-failed", failed: [check("test", "failure")] }],
274 );
275 },
276 );
277​
278 it("keeps the check baseline through a read whose approval lookup failed", () => {
279 const bot = check("bot", "success");
280 const unavailable = { ...check("Workflow approval status", "pending"), placeholder: true };
281 const partial = evaluatePullRequestWatch(
282 watch({ awaitingBaseline: "all" }),
283 detail({ checks: [bot, unavailable] }),
284 noRemarks,
285 );
286 assert.deepEqual(partial.changes, []);
287 assert.equal(partial.next.awaitingBaseline, "checks");
288 const approval = { ...check("CI", "action-required"), url: run(1) };
289 for (const checks of [[bot], [bot, approval]]) {
290 assert.deepEqual(
291 evaluatePullRequestWatch(partial.next, detail({ checks }), noRemarks).changes,
292 [],
293 );
294 }
295 });
296​
297 it("reports pending advisory checks finishing after a required-check baseline", () => {
298 const initial = detail({
299 checks: [{ ...check("test", "success"), required: true }, check("bot", "pending")],
300 });
301 const baseline = evaluatePullRequestWatch(
302 watch({ awaitingBaseline: "all" }),
303 initial,
304 noRemarks,
305 );
306 assert.deepEqual(baseline.changes, []);
307 const settled = evaluatePullRequestWatch(
308 baseline.next,
309 {
310 ...initial,
311 checks: [initial.checks[0]!, check("bot", "success")],
312 },
313 noRemarks,
314 );
315 assert.deepEqual(settled.changes, [{ kind: "checks-passed", count: 2, required: false }]);
316 assert.deepEqual(
317 evaluatePullRequestWatch(
318 settled.next,
319 {
320 ...initial,
321 checks: [initial.checks[0]!, check("bot", "success")],
322 },
323 noRemarks,
324 ).changes,
325 [],
326 );
327 });
328​
329 it("waits for workflow approval once, through reads that miss it, until the run finishes", () => {
330 const bot = check("bot", "success");
331 const approval = { ...check("CI", "action-required"), url: run(1) };
332 const gated = detail({ checks: [bot, approval] });
333 const first = evaluatePullRequestWatch(watch(), gated, noRemarks);
334 assert.deepEqual(first.changes, [{ kind: "checks-awaiting-approval", checks: [approval] }]);
335​
336 // GitHub's approval read can answer empty while the rest of the checks read fine.
337 const missing = evaluatePullRequestWatch(first.next, detail({ checks: [bot] }), noRemarks);
338 assert.deepEqual(missing.changes, []);
339 assert.isFalse(missing.next.passed);
340 assert.deepEqual(evaluatePullRequestWatch(missing.next, gated, noRemarks).changes, []);
341 const later = { ...check("Preview", "action-required"), url: run(2) };
342 assert.deepEqual(
343 evaluatePullRequestWatch(missing.next, detail({ checks: [bot, approval, later] }), noRemarks)
344 .changes,
345 [],
346 );
347 const unnamed = { ...check("Docs", "action-required"), url: null };
348 const named = detail({ checks: [bot, unnamed] });
349 const alone = evaluatePullRequestWatch(watch(), named, noRemarks);
350 assert.deepEqual(alone.changes, [{ kind: "checks-awaiting-approval", checks: [unnamed] }]);
351 const placeholder = { ...unnamed, name: "Workflow approval status", placeholder: true };
352 const unlisted = evaluatePullRequestWatch(
353 alone.next,
354 detail({ checks: [bot, placeholder] }),
355 noRemarks,
356 );
357 assert.deepEqual(unlisted.changes, []);
358 assert.isFalse(unlisted.next.passed);
359 assert.deepEqual(evaluatePullRequestWatch(unlisted.next, named, noRemarks).changes, []);
360 const dropped = evaluatePullRequestWatch(alone.next, detail({ checks: [bot] }), noRemarks);
361 assert.deepEqual(dropped.changes, []);
362 assert.isFalse(dropped.next.passed);
363 assert.deepEqual(dropped.next.awaitingApproval, [unnamed.name]);
364 assert.deepEqual(evaluatePullRequestWatch(dropped.next, named, noRemarks).changes, []);
365 const namedPending = evaluatePullRequestWatch(
366 dropped.next,
367 detail({
368 checks: [
369 { ...bot, required: true },
370 { ...unnamed, status: "pending" },
371 ],
372 }),
373 noRemarks,
374 );
375 assert.deepEqual(namedPending.changes, []);
376 assert.isFalse(namedPending.next.passed);
377 const namedDone = detail({ checks: [bot, { ...unnamed, status: "success" }] });
378 const namedFinished = evaluatePullRequestWatch(namedPending.next, namedDone, noRemarks);
379 assert.deepEqual(namedFinished.changes, [{ kind: "checks-passed", count: 2, required: false }]);
380 assert.deepEqual(namedFinished.next.awaitingApproval, []);
381 assert.deepEqual(
382 evaluatePullRequestWatch(namedFinished.next, namedDone, noRemarks).changes,
383 [],
384 );
385 const pushed = detail({ headSha: "bbbbbbbbbb", checks: [bot] });
386 assert.deepEqual(evaluatePullRequestWatch(missing.next, pushed, noRemarks).changes, [
387 { kind: "checks-passed", count: 1, required: false },
388 ]);
389​
390 // Approved, the run's jobs carry their own names under the run's URL.
391 const job = { ...check("lint", "success"), url: `${run(1)}/job/7` };
392 const pending = { ...check("test", "pending"), url: `${run(1)}/job/8` };
393 const required = { ...bot, required: true };
394 const running = evaluatePullRequestWatch(
395 missing.next,
396 detail({ checks: [required, job, pending] }),
397 noRemarks,
398 );
399 assert.deepEqual(running.changes, []);
400 assert.isFalse(running.next.passed);
401 assert.deepEqual(running.next.awaitingApproval, [run(1)]);
402 const overlap = evaluatePullRequestWatch(
403 running.next,
404 detail({ checks: [required, job, { ...pending, url: `${run(2)}/job/9` }] }),
405 noRemarks,
406 );
407 assert.deepEqual(overlap.changes, []);
408 assert.isFalse(overlap.next.passed);
409 assert.deepEqual(overlap.next.awaitingApproval, [run(1)]);
410 const unlinked = evaluatePullRequestWatch(
411 overlap.next,
412 detail({ checks: [required, job, { ...pending, url: null }] }),
413 noRemarks,
414 );
415 assert.deepEqual(unlinked.changes, []);
416 assert.isFalse(unlinked.next.passed);
417 assert.deepEqual(unlinked.next.awaitingApproval, [run(1)]);
418 const advisory = evaluatePullRequestWatch(
419 unlinked.next,
420 detail({ checks: [required, job, { ...pending, url: "https://ci.example/test" }] }),
421 noRemarks,
422 );
423 assert.deepEqual(advisory.changes, [{ kind: "checks-passed", count: 1, required: true }]);
424 assert.deepEqual(advisory.next.awaitingApproval, []);
425 const completed = detail({ checks: [required, job, { ...pending, status: "success" }] });
426 const finished = evaluatePullRequestWatch(unlinked.next, completed, noRemarks);
427 assert.deepEqual(finished.changes, [{ kind: "checks-passed", count: 1, required: true }]);
428 assert.deepEqual(finished.next.awaitingApproval, []);
429 assert.deepEqual(evaluatePullRequestWatch(finished.next, completed, noRemarks).changes, []);
430​
431 const done = evaluatePullRequestWatch(missing.next, detail({ checks: [bot, job] }), noRemarks);
432 assert.deepEqual(done.changes, [{ kind: "checks-passed", count: 2, required: false }]);
433 });
434​
435 it("does not pass or fail while the host cannot tell whether workflows await approval", () => {
436 const bot = check("bot", "success");
437 const unknown = {
438 ...check("Workflow approval status", "action-required"),
439 url: null,
440 placeholder: true,
441 };
442 const unread = evaluatePullRequestWatch(watch(), detail({ checks: [bot, unknown] }), noRemarks);
443 assert.deepEqual(unread.changes, []);
444 assert.isFalse(unread.next.passed);
445 const read = evaluatePullRequestWatch(unread.next, detail({ checks: [bot] }), noRemarks);
446 assert.deepEqual(read.changes, [{ kind: "checks-passed", count: 1, required: false }]);
447 const blocked = evaluatePullRequestWatch(
448 read.next,
449 detail({ checks: [{ ...bot, status: "pending" }, unknown] }),
450 noRemarks,
451 );
452 assert.isFalse(blocked.next.passed);
453 assert.deepEqual(
454 evaluatePullRequestWatch(blocked.next, detail({ checks: [bot] }), noRemarks).changes,
455 [{ kind: "checks-passed", count: 1, required: false }],
456 );
457 });
458​
459 it("reports each failure at once, even while another check never finishes", () => {
460 const bot = check("CodeRabbit", "pending");
461 const first = detail({ checks: [check("lint", "failure"), check("test", "pending"), bot] });
462 const lint = evaluatePullRequestWatch(watch(), first, noRemarks);
463 assert.deepEqual(lint.changes, [{ kind: "checks-failed", failed: [check("lint", "failure")] }]);
464 assert.deepEqual(evaluatePullRequestWatch(lint.next, first, noRemarks).changes, []);
465​
466 const second = detail({ checks: [check("lint", "failure"), check("test", "failure"), bot] });
467 const test = evaluatePullRequestWatch(lint.next, second, noRemarks);
468 assert.deepEqual(test.changes, [{ kind: "checks-failed", failed: [check("test", "failure")] }]);
469​
470 const rerun = evaluatePullRequestWatch(test.next, first, noRemarks);
471 assert.equal(evaluatePullRequestWatch(rerun.next, second, noRemarks).changes.length, 1);
472​
473 const pushed = detail({ ...second, headSha: "bbbbbbbbbb" });
474 assert.equal(evaluatePullRequestWatch(test.next, pushed, noRemarks).changes.length, 1);
475​
476 const approval = { ...check("CI", "action-required"), url: run(1) };
477 const gated = detail({ checks: [approval, check("lint", "failure")] });
478 assert.deepEqual(evaluatePullRequestWatch(watch(), gated, noRemarks).changes, [
479 { kind: "checks-failed", failed: [check("lint", "failure")] },
480 { kind: "checks-awaiting-approval", checks: [approval] },
481 ]);
482 });
483​
484 it("reports passed once the required checks pass, whatever the others do", () => {
485 const required = (name: string, status: PullRequestCheck["status"]) => ({
486 ...check(name, status),
487 required: true,
488 });
489 const green = detail({
490 checks: [required("test", "success"), required("lint", "success"), check("bot", "pending")],
491 });
492 const passed = evaluatePullRequestWatch(watch(), green, noRemarks);
493 assert.deepEqual(passed.changes, [{ kind: "checks-passed", count: 2, required: true }]);
494 assert.deepEqual(evaluatePullRequestWatch(passed.next, green, noRemarks).changes, []);
495​
496 const plain = detail({ checks: [check("test", "success"), check("bot", "pending")] });
497 assert.deepEqual(evaluatePullRequestWatch(watch(), plain, noRemarks).changes, []);
498 });
499​
500 it("reports passed again when a required check shows up already passed", () => {
501 const required = (name: string, status: PullRequestCheck["status"]) => ({
502 ...check(name, status),
503 required: true,
504 });
505 const tests = detail({
506 checks: [required("Tests", "success"), check("Smoke Tests", "pending")],
507 });
508 const first = evaluatePullRequestWatch(watch(), tests, noRemarks);
509 assert.deepEqual(first.changes, [{ kind: "checks-passed", count: 1, required: true }]);
510​
511 const gated = detail({
512 checks: [
513 required("Tests", "success"),
514 check("Smoke Tests", "success"),
515 required("Smoke Tests Gate", "success"),
516 ],
517 });
518 const second = evaluatePullRequestWatch(first.next, gated, noRemarks);
519 assert.deepEqual(second.changes, [{ kind: "checks-passed", count: 2, required: true }]);
520 assert.deepEqual(evaluatePullRequestWatch(second.next, gated, noRemarks).changes, []);
521​
522 const pending = detail({
523 checks: [required("Tests", "success"), required("Smoke Tests Gate", "pending")],
524 });
525 const waiting = evaluatePullRequestWatch(first.next, pending, noRemarks);
526 assert.deepEqual(waiting.changes, []);
527 assert.deepEqual(evaluatePullRequestWatch(waiting.next, gated, noRemarks).changes, [
528 { kind: "checks-passed", count: 2, required: true },
529 ]);
530 });
531​
532 // regression: #23712 required checks woke the agent early and the rest finishing never did
533 it("wakes again when the other checks finish after the required ones passed", () => {
534 const required = (name: string, status: PullRequestCheck["status"]) => ({
535 ...check(name, status),
536 required: true,
537 });
538 const early = detail({
539 checks: [required("test", "success"), check("e2e", "pending")],
540 });
541 const first = evaluatePullRequestWatch(watch(), early, noRemarks);
542 assert.deepEqual(first.changes, [{ kind: "checks-passed", count: 1, required: true }]);
543​
544 const done = detail({
545 checks: [required("test", "success"), check("e2e", "success")],
546 });
547 const final = evaluatePullRequestWatch(first.next, done, noRemarks);
548 assert.deepEqual(
549 final.changes.map((change) => change.kind),
550 ["checks-passed"],
551 );
552 assert.deepEqual(evaluatePullRequestWatch(final.next, done, noRemarks).changes, []);
553 // A later advisory job running and passing is not more news.
554 const botPending = detail({ checks: [...done.checks, check("bot", "pending")] });
555 const churn = evaluatePullRequestWatch(final.next, botPending, noRemarks);
556 assert.deepEqual(churn.changes, []);
557 const botDone = detail({ checks: [...done.checks, check("bot", "success")] });
558 assert.deepEqual(evaluatePullRequestWatch(churn.next, botDone, noRemarks).changes, []);
559​
560 // A pending check that turns required on the next read still finishes with one wake.
561 const promoted = detail({
562 checks: [required("test", "success"), required("e2e", "success")],
563 });
564 const gated = evaluatePullRequestWatch(first.next, promoted, noRemarks);
565 assert.deepEqual(gated.changes, [{ kind: "checks-passed", count: 2, required: true }]);
566 assert.deepEqual(evaluatePullRequestWatch(gated.next, promoted, noRemarks).changes, []);
567​
568 // Nothing else was pending when the required ones passed, so nothing more is owed.
569 const green = evaluatePullRequestWatch(watch(), done, noRemarks);
570 assert.deepEqual(green.changes, [{ kind: "checks-passed", count: 1, required: true }]);
571 assert.deepEqual(evaluatePullRequestWatch(green.next, botDone, noRemarks).changes, []);
572 });
573​
574 it("reports an owed non-required failure once after the required notice", () => {
575 const required = { ...check("test", "success"), required: true };
576 const early = detail({ checks: [required, check("e2e", "pending")] });
577 const first = evaluatePullRequestWatch(watch(), early, noRemarks);
578 assert.deepEqual(first.changes, [{ kind: "checks-passed", count: 1, required: true }]);
579 const failed = detail({ checks: [required, check("e2e", "failure")] });
580 const failure = evaluatePullRequestWatch(first.next, failed, noRemarks);
581 assert.deepEqual(failure.changes, [
582 { kind: "checks-failed", failed: [check("e2e", "failure")] },
583 ]);
584 const repeated = evaluatePullRequestWatch(failure.next, failed, noRemarks);
585 assert.deepEqual(repeated.changes, []);
586 const recovered = detail({ checks: [required, check("e2e", "success")] });
587 const final = evaluatePullRequestWatch(repeated.next, recovered, noRemarks);
588 assert.deepEqual(final.changes, [{ kind: "checks-passed", count: 2, required: false }]);
589 assert.deepEqual(evaluatePullRequestWatch(final.next, recovered, noRemarks).changes, []);
590 });
591​
592 it("clears old-head owed checks when a new head is pushed", () => {
593 const required = { ...check("test", "success"), required: true };
594 const early = detail({ checks: [required, check("e2e", "pending")] });
595 const first = evaluatePullRequestWatch(watch(), early, noRemarks);
596 assert.deepEqual(first.next.owedChecks, ["e2e"]);
597 const unreadHead = detail({ headSha: "bbbbbbbbbb", checks: [] });
598 const unread = evaluatePullRequestWatch(first.next, unreadHead, noRemarks);
599 assert.deepEqual(unread.changes, []);
600 assert.deepEqual(unread.next.owedChecks, []);
601 const pushed = detail({ ...unreadHead, checks: [required] });
602 const newHead = evaluatePullRequestWatch(unread.next, pushed, noRemarks);
603 assert.deepEqual(newHead.changes, [{ kind: "checks-passed", count: 1, required: true }]);
604 assert.deepEqual(newHead.next.owedChecks, []);
605 const lateResult = detail({ ...pushed, checks: [required, check("e2e", "success")] });
606 const final = evaluatePullRequestWatch(newHead.next, lateResult, noRemarks);
607 assert.deepEqual(final.changes, []);
608 assert.deepEqual(evaluatePullRequestWatch(final.next, lateResult, noRemarks).changes, []);
609 });
610​
611 // regression: #16208 PR watches burned GitHub's rate limit and gave up
612 it("does not report passed again for a new passed check where none is required", () => {
613 const first = evaluatePullRequestWatch(
614 watch(),
615 detail({ checks: [check("test", "success")] }),
616 noRemarks,
617 );
618 assert.deepEqual(first.changes, [{ kind: "checks-passed", count: 1, required: false }]);
619 const both = detail({ checks: [check("test", "success"), check("lint", "success")] });
620 assert.deepEqual(evaluatePullRequestWatch(first.next, both, noRemarks).changes, []);
621 });
622​
623 it("does not wake a watch saved before passed checks were recorded", () => {
624 const green = detail({ checks: [{ ...check("test", "success"), required: true }] });
625 const told = watch({ headSha: "aaaaaaaaaa", passed: true });
626 const saved = evaluatePullRequestWatch(told, green, noRemarks);
627 assert.deepEqual(saved.changes, []);
628 assert.deepEqual(saved.next.passedChecks, ["test"]);
629 });
630​
631 it("keeps remarks for a later pass when the conversation was not read whole", () => {
632 const comments = [remark("reviewer", "2026-10-02T12:06:00Z")];
633 const partial = evaluatePullRequestWatch(watch(), detail(), null);
634 assert.deepEqual(partial.changes, []);
635 assert.equal(
636 evaluatePullRequestWatch(partial.next, detail(), comments).changes[0]?.kind,
637 "remarks",
638 );
639 });
640​
641 it("reports a remark that shows up late with the same time as a reported one", () => {
642 const first = remark("reviewer", "2026-10-02T12:06:00Z");
643 const late = { ...remark("bot", "2026-10-02T12:06:00Z"), id: "late" };
644 const reported = evaluatePullRequestWatch(watch(), detail(), [first]);
645 const again = evaluatePullRequestWatch(reported.next, detail(), [first, late]);
646 assert.deepEqual(again.changes, [{ kind: "remarks", remarks: [late] }]);
647 assert.deepEqual(again.next.remarkIds, [first.id, "late"]);
648 });
649​
650 it("reports edits after the watermark once and counts them toward the wake limit", () => {
651 const old = remark("greptile[bot]", "2026-10-02T11:00:00Z");
652 const watching = watch({
653 headSha: "aaaaaaaaaa",
654 remarkIds: [old.id],
655 wakes: PULL_REQUEST_WATCH_WAKE_LIMIT - 1,
656 });
657 assert.deepEqual(evaluatePullRequestWatch(watching, detail(), [old]).changes, []);
658 const edited = { ...old, editedAt: "2026-10-02T12:06:00Z" };
659 const report = evaluatePullRequestWatch(watching, detail(), [edited]);
660 assert.deepEqual(report.changes, [{ kind: "remarks", remarks: [edited] }]);
661 assert.equal(report.next.remarksThrough, edited.editedAt);
662 assert.deepEqual(report.next.remarkIds, [old.id]);
663 assert.isTrue(report.exhausted);
664 assert.deepEqual(evaluatePullRequestWatch(report.next, detail(), [edited]).changes, []);
665 const late = { ...edited, id: "late" };
666 assert.deepEqual(evaluatePullRequestWatch(report.next, detail(), [edited, late]).changes, [
667 { kind: "remarks", remarks: [late] },
668 ]);
669 });
670​
671 it("wakes once per edit of a remark seen at the watermark, never for the agent's own", () => {
672 const seen = remark("ci-bot", "2026-10-10T19:52:40.000Z");
673 const watching = watch({
674 headSha: "aaaaaaaaaa",
675 remarksThrough: seen.createdAt,
676 remarkIds: [seen.id],
677 wakes: 2,
678 });
679 assert.deepEqual(evaluatePullRequestWatch(watching, detail(), [seen]).changes, []);
680 const edited = { ...seen, editedAt: "2026-10-10T20:04:50.000Z" };
681 const first = evaluatePullRequestWatch(watching, detail(), [edited]);
682 assert.deepEqual(first.changes, [{ kind: "remarks", remarks: [edited] }]);
683 assert.strictEqual(first.next.remarksThrough, edited.editedAt);
684 assert.deepEqual(evaluatePullRequestWatch(first.next, detail(), [edited]).changes, []);
685 const again = { ...seen, editedAt: "2026-10-10T20:05:50.000Z" };
686 const second = evaluatePullRequestWatch(first.next, detail(), [again]);
687 assert.deepEqual(second.changes, [{ kind: "remarks", remarks: [again] }]);
688 assert.deepEqual(evaluatePullRequestWatch(second.next, detail(), [again]).changes, []);
689 const own = { ...edited, author: { login: "agent-user", name: null, avatarUrl: null } };
690 assert.deepEqual(evaluatePullRequestWatch(watching, detail(), [own]).changes, []);
691 });
692​
693 it("does not treat a failed check read as a rerun", () => {
694 const failed = detail({ checks: [check("lint", "failure")] });
695 const reported = evaluatePullRequestWatch(watch(), failed, noRemarks);
696 assert.equal(reported.changes.length, 1);
697 const unreadable = evaluatePullRequestWatch(reported.next, detail({ checks: [] }), noRemarks);
698 assert.deepEqual(evaluatePullRequestWatch(unreadable.next, failed, noRemarks).changes, []);
699 });
700​
701 it("wakes for the pull request's author when the agent is someone else", () => {
702 const contributor = detail({ author: { login: "contributor", name: null, avatarUrl: null } });
703 const reply = remark("contributor", "2026-10-02T12:06:00Z");
704 assert.deepEqual(evaluatePullRequestWatch(watch(), contributor, [reply]).changes, [
705 { kind: "remarks", remarks: [reply] },
706 ]);
707 const noViewer = detail({ viewer: undefined, author: contributor.author });
708 assert.deepEqual(evaluatePullRequestWatch(watch(), noViewer, [reply]).changes, []);
709 });
710​
711 it("reports remarks from others once and never the agent's own", () => {
712 const comments = [
713 remark("agent-user", "2026-10-02T12:05:00Z", "Fixed in the latest push."),
714 remark("macroscope-app[bot]", "2026-10-02T12:06:00Z"),
715 remark("reviewer", "2026-10-02T11:00:00Z", "Older than the watch."),
716 ];
717 const report = evaluatePullRequestWatch(watch(), detail(), comments);
718 assert.deepEqual(report.changes, [{ kind: "remarks", remarks: [comments[1]!] }]);
719 assert.equal(report.next.remarksThrough, "2026-10-02T12:06:00Z");
720 assert.deepEqual(evaluatePullRequestWatch(report.next, detail(), comments).changes, []);
721 });
722​
723 it("cuts a long remark in the wake message without splitting an emoji", () => {
724 const body = `${"x".repeat(196)}🚀 and more`;
725 const report = evaluatePullRequestWatch(watch(), detail(), [
726 remark("reviewer", "2026-10-02T12:06:00Z", body),
727 ]);
728 const { text } = pullRequestWatchMessage({
729 number: 1,
730 url: "https://github.com/o/r/pull/1",
731 baseBranch: "main",
732 headSha: null,
733 report,
734 });
735 assert.isTrue(text.isWellFormed());
736 assert.include(text, `"${"x".repeat(196)}..."`);
737 });
738​
739 it.each([
740 [
741 "a bot's leading badge",
742 '<a href="https://app.coderabbit.ai/change-stack/o/r/pull/1?cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://coderabbit.ai/badge-dark.svg"><img alt="Severity > `Minor`" src="https://coderabbit.ai/badge.svg"></picture></a>\r\n\r\n_⚠️ Potential issue_ | _🟠 Major_\r\n\r\n**Guard the empty list.**',
743 "_⚠️ Potential issue_ | _🟠 Major_ **Guard the empty list.**",
744 ],
745 [
746 "tags in prose and a hidden comment",
747 "<!-- state -->\n<details>\n<summary>Why</summary>\n\n<p>Guard this</p>, then <br/>retry.\n</details>",
748 "Why Guard this , then retry.",
749 ],
750 [
751 "type arguments",
752 "Return Promise<void>, not Promise<A> or Vec<code>.",
753 "Return Promise<void>, not Promise<A> or Vec<code>.",
754 ],
755 [
756 "code spans and fences",
757 "Replace `<div>` with ``<span>``:\n~~~html\n<p>Done</p>\n~~~\r\nor\r\n```html\r\n<b>Done</b>\r\n```",
758 "Replace `<div>` with ``<span>``: ~~~html <p>Done</p> ~~~ or ```html <b>Done</b> ```",
759 ],
760 [
761 "indented code",
762 "Use this replacement:\n\n <div>\n <span>Ready</span>\n </div>\n\nKeep the <b>wrapper</b>.",
763 "Use this replacement: <div> <span>Ready</span> </div> Keep the wrapper .",
764 ],
765 ["an indented continuation of an HTML block", "<div>\n <span>Ready</span>\n</div>", "Ready"],
766 ])("quotes a remark's text without its HTML tags: %s", (_name, body, quoted) => {
767 const report = evaluatePullRequestWatch(watch(), detail(), [
768 remark("reviewer", "2026-10-02T12:06:00Z", body),
769 ]);
770 const { text } = pullRequestWatchMessage({
771 number: 1,
772 url: "https://github.com/o/r/pull/1",
773 baseBranch: "main",
774 headSha: null,
775 report,
776 });
777 assert.include(text, `: "${quoted}" `);
778 });
779​
780 it("reports a conflict once, until the branch is clean again", () => {
781 const conflicting = detail({ mergeability: "conflicting" });
782 const first = evaluatePullRequestWatch(watch(), conflicting, noRemarks);
783 assert.deepEqual(first.changes, [{ kind: "conflicting" }]);
784 const { headSha: _unreadHead, ...headUnread } = conflicting;
785 const unread = evaluatePullRequestWatch(first.next, headUnread, noRemarks);
786 assert.deepEqual(unread.changes, []);
787 assert.deepEqual(evaluatePullRequestWatch(unread.next, conflicting, noRemarks).changes, []);
788 const recomputing = evaluatePullRequestWatch(
789 first.next,
790 detail({ mergeability: "unknown" }),
791 noRemarks,
792 );
793 assert.deepEqual(
794 evaluatePullRequestWatch(recomputing.next, conflicting, noRemarks).changes,
795 [],
796 );
797 const clean = evaluatePullRequestWatch(first.next, detail(), noRemarks);
798 assert.deepEqual(evaluatePullRequestWatch(clean.next, conflicting, noRemarks).changes, [
799 { kind: "conflicting" },
800 ]);
801 const pushed = { headSha: "bbbbbbbbbb" };
802 const recomputed = evaluatePullRequestWatch(
803 first.next,
804 detail({ ...pushed, mergeability: "unknown" }),
805 noRemarks,
806 );
807 assert.deepEqual(
808 evaluatePullRequestWatch(
809 recomputed.next,
810 detail({ ...pushed, mergeability: "conflicting" }),
811 noRemarks,
812 ).changes,
813 [{ kind: "conflicting" }],
814 );
815 });
816​
817 it("reports each merge queue removal once while the head checks stay green", () => {
818 const green = detail({ checks: [check("test", "success")] });
819 const watching = evaluatePullRequestWatch(watch(), green, noRemarks).next;
820 const removed = (id: string, removedAt: string) =>
821 detail({ ...green, mergeQueueRemoval: { id, removedAt, reason: "Merge conflict" } });
822​
823 const dropped = removed("first", "2026-10-02T12:10:00Z");
824 const first = evaluatePullRequestWatch(watching, dropped, noRemarks);
825 assert.deepEqual(first.changes, [{ kind: "merge-queue-removed", reason: "Merge conflict" }]);
826 const wake = pullRequestWatchMessage({
827 number: 1,
828 url: "https://github.com/o/r/pull/1",
829 baseBranch: "main",
830 headSha: first.next.headSha,
831 report: first,
832 });
833 assert.deepEqual(wake.notification, {
834 source: { kind: "monitor" },
835 outcome: "failed",
836 summary: "#1: removed from merge queue",
837 });
838 assert.deepEqual(evaluatePullRequestWatch(first.next, dropped, noRemarks).changes, []);
839 // A read without queue news keeps the removal already told.
840 const quiet = evaluatePullRequestWatch(first.next, green, noRemarks);
841 assert.deepEqual(evaluatePullRequestWatch(quiet.next, dropped, noRemarks).changes, []);
842​
843 const again = removed("second", "2026-10-02T12:20:00Z");
844 assert.equal(evaluatePullRequestWatch(first.next, again, noRemarks).changes.length, 1);
845 const before = removed("before", "2026-10-02T11:00:00Z");
846 const baseline = evaluatePullRequestWatch(
847 watch({ headSha: watching.headSha, passed: true, passedChecks: watching.passedChecks }),
848 before,
849 noRemarks,
850 );
851 assert.deepEqual(baseline.changes, []);
852 for (const prior of [watching, baseline.next]) {
853 const skewed = evaluatePullRequestWatch(
854 prior,
855 removed("new", "2026-10-02T11:59:58Z"),
856 noRemarks,
857 );
858 assert.deepEqual(skewed.changes, [{ kind: "merge-queue-removed", reason: "Merge conflict" }]);
859 assert.deepEqual(
860 evaluatePullRequestWatch(skewed.next, removed("new", "2026-10-02T11:59:58Z"), noRemarks)
861 .changes,
862 [],
863 );
864 }
865 });
866​
867 it("reports a merge queue removal stamped in the second the watch started", () => {
868 const watching = watch({ startedAt: "2026-10-02T12:00:00.500Z" });
869 const removed = (removedAt: string) =>
870 detail({ mergeQueueRemoval: { id: "first", removedAt, reason: "CI failed" } });
871 assert.deepEqual(
872 evaluatePullRequestWatch(watching, removed("2026-10-02T12:00:00Z"), noRemarks).changes,
873 [{ kind: "merge-queue-removed", reason: "CI failed" }],
874 );
875 assert.deepEqual(
876 evaluatePullRequestWatch(watching, removed("2026-10-02T11:59:59Z"), noRemarks).changes,
877 [],
878 );
879 });
880​
881 it("stays quiet when the queue lets go of a pull request by merging it", () => {
882 const watching = evaluatePullRequestWatch(watch(), detail(), noRemarks).next;
883 const merging = detail({
884 mergeQueueRemoval: { id: "landed", removedAt: "2026-10-02T12:10:00Z", reason: "merged" },
885 });
886 const read = evaluatePullRequestWatch(watching, merging, noRemarks);
887 assert.deepEqual(read.changes, []);
888 assert.equal(read.next.mergeQueueRemovalId, "landed");
889 });
890​
891 it("does not spend the comment wake limit on check results", () => {
892 const tired = watch({ headSha: "aaaaaaaaaa", wakes: PULL_REQUEST_WATCH_WAKE_LIMIT - 1 });
893 const result = evaluatePullRequestWatch(
894 tired,
895 detail({ checks: [check("lint", "failure")] }),
896 noRemarks,
897 );
898 assert.isFalse(result.exhausted);
899 assert.equal(result.next.wakes, 0);
900 });
901​
902 it("stops after the wake limit unless the head moves", () => {
903 const comments = [remark("reviewer", "2026-10-02T12:10:00Z")];
904 const tired = watch({ headSha: "aaaaaaaaaa", wakes: PULL_REQUEST_WATCH_WAKE_LIMIT - 1 });
905 assert.isTrue(evaluatePullRequestWatch(tired, detail(), comments).exhausted);
906 const pushed = evaluatePullRequestWatch(tired, detail({ headSha: "cccccccccc" }), comments);
907 assert.isFalse(pushed.exhausted);
908 assert.equal(pushed.next.wakes, 1);
909 });
910​
911 const anHourLater = (
912 first: ThreadPullRequestWatch,
913 read: Detail,
914 ): ReadonlyArray<ReadonlyArray<string>> => {
915 const kinds: Array<ReadonlyArray<string>> = [];
916 let current = first;
917 for (let minute = 0; minute <= 60; minute += 10) {
918 const { changes, next } = evaluate(current, read, noRemarks, minute * 60_000);
919 kinds.push(changes.map((change) => change.kind));
920 current = next;
921 }
922 return kinds;
923 };
924​
925 it("does not tell a watch saved before the no-checks clock that its seen head has none", () => {
926 // Such a watch may have seen this head's checks pending, which records nothing.
927 const legacy = watch({ headSha: "aaaaaaaaaa" });
928 assert.isTrue(anHourLater(legacy, detail({ checks: [] })).every((kinds) => kinds.length === 0));
929 const pushed = anHourLater(legacy, detail({ headSha: "bbbbbbbbbb", checks: [] }));
930 assert.deepEqual(pushed.flat(), ["no-checks"]);
931 const unknown = detail({
932 checks: [{ ...check("Workflow approval status", "action-required"), placeholder: true }],
933 });
934 const fresh = watch({ awaitingBaseline: "all" });
935 assert.deepEqual(anHourLater(fresh, unknown).flat(), []);
936 const unread = evaluate(fresh, unknown, noRemarks, 0);
937 assert.deepEqual(
938 evaluate(unread.next, detail({ checks: [] }), noRemarks, 60 * 60_000).changes,
939 [{ kind: "no-checks", minutes: 60 }],
940 );
941 });
942​
943 it("starts the no-checks clock while a fresh watch awaits its baseline", () => {
944 assert.deepEqual(
945 anHourLater(watch({ awaitingBaseline: "all" }), detail({ checks: [] })).flat(),
946 ["no-checks"],
947 );
948 });
949​
950 it("never reports missing checks on a host where an empty list says nothing", () => {
951 const silent = detail({ capabilities: capabilities(false), checks: [] });
952 assert.isTrue(anHourLater(watch(), silent).every((kinds) => kinds.length === 0));
953 });
954​
955 it("counts checks as pending until every one, a review bot's included, has finished", () => {
956 const pending = (checks: ReadonlyArray<PullRequestCheck>, from = watch()) =>
957 evaluatePullRequestWatch(from, detail({ checks }), noRemarks).next.checksPending;
958 const ci = { ...check("test", "success"), required: true };
959 assert.isTrue(pending([ci, check("CodeRabbit", "pending")]));
960 assert.isFalse(pending([ci, check("CodeRabbit", "success")]));
961 assert.isFalse(pending([ci, check("CodeRabbit", "failure")]));
962 assert.isFalse(pending([ci, check("deploy", "action-required")]));
963 // A failed read keeps the last answer, as does one with only an unreadable approval check.
964 assert.isFalse(pending([], watch({ headSha: "aaaaaaaaaa", checksPending: false })));
965 const unreadable = { ...check("approvals", "action-required"), placeholder: true };
966 assert.isTrue(pending([unreadable], watch({ headSha: "aaaaaaaaaa", checksPending: true })));
967 });
968​
969 it("waits a while for a new head's checks on every host", () => {
970 const pushed = (checksAlwaysReport: boolean) =>
971 evaluatePullRequestWatch(
972 watch({ headSha: "aaaaaaaaaa", checksPending: false }),
973 detail({
974 headSha: "bbbbbbbbbb",
975 capabilities: capabilities(checksAlwaysReport),
976 checks: [],
977 }),
978 noRemarks,
979 ).next.checksPending;
980 assert.isTrue(pushed(true));
981 assert.isTrue(pushed(false));
982​
983 // Once the no-checks window passes, the watch stops waiting for them.
984 for (const checksAlwaysReport of [true, false]) {
985 let current = watch({ headSha: "aaaaaaaaaa" });
986 for (const minute of [0, 20]) {
987 current = evaluate(
988 current,
989 detail({
990 headSha: "bbbbbbbbbb",
991 capabilities: capabilities(checksAlwaysReport),
992 checks: [],
993 }),
994 noRemarks,
995 minute * 60_000,
996 ).next;
997 }
998 assert.isFalse(current.checksPending);
999 }
1000​
1001 // A watch with no answer waits on an empty list only while the no-checks clock runs.
1002 const unanswered = (checksAwaitedSince: string | null) =>
1003 evaluatePullRequestWatch(
1004 watch({ headSha: "bbbbbbbbbb", checksAwaitedSince }),
1005 detail({ headSha: "bbbbbbbbbb", checks: [] }),
1006 noRemarks,
1007 ).next.checksPending;
1008 assert.isFalse(unanswered(null));
1009 assert.isTrue(unanswered(STARTED));
1010 });
1011});
1012​
1013describe("pullRequestWatchEndMessage", () => {
1014 const url = "https://git.cafe/pingdotgg/t3code/pull/7";
1015 const end = (overrides: Partial<Parameters<typeof pullRequestWatchEndMessage>[0]["detail"]>) =>
1016 pullRequestWatchEndMessage({
1017 number: 7,
1018 url,
1019 detail: { state: "merged", baseBranch: "main", ...overrides },
1020 });
1021 const mergeCommitSha = "3b2f958603a51d8c42c4ede02eee7b8cb310b2d9";
1022​
1023 it("says how the pull request ended, with the merge commit and merger the host reports", () => {
1024 const merged = end({
1025 mergeCommitSha,
1026 mergedBy: { login: "juliusmarminge", name: null, avatarUrl: null },
1027 });
1028 assert.equal(
1029 merged.text,
1030 `Pull request #7 (${url}) was merged into main by juliusmarminge as 3b2f958, so T3 Code stopped watching it.`,
1031 );
1032 assert.deepEqual(merged.notification, {
1033 source: { kind: "monitor" },
1034 outcome: "completed",
1035 summary: "#7: merged, stopped watching",
1036 });
1037 // GitCafe reports a merge made on GitHub without who made it.
1038 assert.equal(
1039 end({ mergeCommitSha }).text,
1040 `Pull request #7 (${url}) was merged into main as 3b2f958, so T3 Code stopped watching it.`,
1041 );
1042​
1043 const closed = end({ state: "closed" });
1044 assert.equal(
1045 closed.text,
1046 `Pull request #7 (${url}) was closed without merging, so T3 Code stopped watching it. If it is reopened, call watch_pull_request to watch it again.`,
1047 );
1048 assert.equal(closed.notification.summary, "#7: closed, stopped watching");
1049 });
1050});