Skip to content

Commit 171fec9

Browse files
fix(server): only GitHub watches report a head with no checks
A watch saved before the no-checks clock may have seen its head's checks pending, so its clock now starts at the next push instead of inferring none were ever seen. Azure DevOps reports no checks because it cannot read pipelines, so the notice is limited to GitHub; other hosts keep their existing check, conflict, and comment semantics. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3ab3b83 commit 171fec9

3 files changed

Lines changed: 55 additions & 19 deletions

File tree

‎apps/server/src/orchestration-v2/pullRequestWatch.forgejoComments.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ThreadPullRequestWatch } from "@t3tools/contracts";
1+
import { SourceControlProviderKind, type ThreadPullRequestWatch } from "@t3tools/contracts";
22
import { assert, describe, it } from "@effect/vitest";
33
import * as Schema from "effect/Schema";
44
import {
@@ -30,6 +30,7 @@ describe("Forgejo comment watch boundary", () => {
3030
wakes: 2,
3131
} satisfies ThreadPullRequestWatch;
3232
const finalDetail = {
33+
provider: SourceControlProviderKind.make("forgejo"),
3334
headSha: seen.headSha,
3435
checks: [],
3536
mergeability: "mergeable",

‎apps/server/src/orchestration-v2/pullRequestWatch.test.ts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type {
2-
PullRequestCheck,
1+
import {
2+
SourceControlProviderKind,
3+
type PullRequestCheck,
34
PullRequestComment,
45
ThreadPullRequestWatch,
56
} from "@t3tools/contracts";
@@ -40,6 +41,7 @@ const check = (name: string, status: PullRequestCheck["status"]): PullRequestChe
4041
type Detail = Parameters<typeof evaluatePullRequestWatch>[1];
4142

4243
const detail = (overrides: Partial<Detail> = {}): Detail => ({
44+
provider: SourceControlProviderKind.make("github"),
4345
headSha: "aaaaaaaaaa",
4446
checks: [check("lint", "success"), check("test", "pending")],
4547
mergeability: "mergeable",
@@ -260,4 +262,34 @@ describe("evaluatePullRequestWatch", () => {
260262
assert.isFalse(pushed.exhausted);
261263
assert.equal(pushed.next.wakes, 1);
262264
});
265+
266+
const anHourLater = (
267+
first: ThreadPullRequestWatch,
268+
read: Detail,
269+
): ReadonlyArray<ReadonlyArray<string>> => {
270+
const kinds: Array<ReadonlyArray<string>> = [];
271+
let current = first;
272+
for (let minute = 0; minute <= 60; minute += 10) {
273+
const { changes, next } = evaluate(current, read, noRemarks, minute * 60_000);
274+
kinds.push(changes.map((change) => change.kind));
275+
current = next;
276+
}
277+
return kinds;
278+
};
279+
280+
it("does not tell a watch saved before the no-checks clock that its seen head has none", () => {
281+
// Such a watch may have seen this head's checks pending, which records nothing.
282+
const legacy = watch({ headSha: "aaaaaaaaaa" });
283+
assert.isTrue(anHourLater(legacy, detail({ checks: [] })).every((kinds) => kinds.length === 0));
284+
const pushed = anHourLater(legacy, detail({ headSha: "bbbbbbbbbb", checks: [] }));
285+
assert.deepEqual(pushed.flat(), ["no-checks"]);
286+
});
287+
288+
it("never reports missing checks on a host whose checks it cannot read", () => {
289+
const azure = detail({
290+
provider: SourceControlProviderKind.make("azure-devops"),
291+
checks: [],
292+
});
293+
assert.isTrue(anHourLater(watch(), azure).every((kinds) => kinds.length === 0));
294+
});
263295
});

‎apps/server/src/orchestration-v2/pullRequestWatch.ts‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as DateTime from "effect/DateTime";
1212
* this only stops a chatty bot looping an agent that is replying to it.
1313
*/
1414
export const PULL_REQUEST_WATCH_WAKE_LIMIT = 10;
15-
/** Checks usually register within a minute of a push, so a head still without any is news. */
15+
/** How long a GitHub head may go without any check before the agent is told none reported. */
1616
export const PULL_REQUEST_WATCH_NO_CHECKS_MS = 15 * 60_000;
1717
const LISTED_ITEMS = 10;
1818
const SNIPPET_LENGTH = 200;
@@ -36,7 +36,10 @@ const isFailedCheck = (check: PullRequestCheck) =>
3636

3737
export function evaluatePullRequestWatch(
3838
watch: ThreadPullRequestWatch,
39-
detail: Pick<PullRequestDetail, "headSha" | "checks" | "mergeability" | "viewer" | "author">,
39+
detail: Pick<
40+
PullRequestDetail,
41+
"provider" | "headSha" | "checks" | "mergeability" | "viewer" | "author"
42+
>,
4043
remarks: ReadonlyArray<PullRequestComment> | null,
4144
now: number,
4245
): PullRequestWatchReport {
@@ -70,20 +73,20 @@ export function evaluatePullRequestWatch(
7073
}
7174

7275
// Only a head never read with checks waits for them: an empty read after checks were seen is
73-
// the failed read above. Watches saved before this field fall back to what they recorded.
74-
const nowIso = DateTime.formatIso(DateTime.makeUnsafe(now));
75-
const awaitedBefore = headMoved
76-
? nowIso
77-
: watch.checksAwaitedSince !== undefined
78-
? watch.checksAwaitedSince
79-
: watch.passed || watch.failedChecks.length > 0
80-
? null
81-
: nowIso;
82-
let checksAwaitedSince = detail.checks.length > 0 ? null : awaitedBefore;
83-
const awaitedMs = checksAwaitedSince === null ? 0 : now - Date.parse(checksAwaitedSince);
84-
if (awaitedMs >= PULL_REQUEST_WATCH_NO_CHECKS_MS) {
85-
changes.push({ kind: "no-checks", minutes: Math.round(awaitedMs / 60_000) });
86-
checksAwaitedSince = null;
76+
// the failed read above. A watch saved before this field may have seen pending checks on its
77+
// head, so its clock starts only at the next push. Other hosts can lack a checks API (Azure
78+
// DevOps pipelines), where an empty list says nothing, so only GitHub waits.
79+
let checksAwaitedSince = watch.checksAwaitedSince;
80+
if (detail.provider === "github") {
81+
const awaitedBefore = headMoved
82+
? DateTime.formatIso(DateTime.makeUnsafe(now))
83+
: (watch.checksAwaitedSince ?? null);
84+
checksAwaitedSince = detail.checks.length > 0 ? null : awaitedBefore;
85+
const awaitedMs = checksAwaitedSince === null ? 0 : now - Date.parse(checksAwaitedSince);
86+
if (awaitedMs >= PULL_REQUEST_WATCH_NO_CHECKS_MS) {
87+
changes.push({ kind: "no-checks", minutes: Math.round(awaitedMs / 60_000) });
88+
checksAwaitedSince = null;
89+
}
8790
}
8891

8992
const own = (detail.viewer ?? detail.author?.login)?.toLowerCase();

0 commit comments

Comments
 (0)