Skip to content

Commit 93fe829

Browse files
test(server): cover owed PR watch checks across lifecycle changes
1 parent 72b8789 commit 93fe829

2 files changed

Lines changed: 158 additions & 0 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,43 @@ describe("evaluatePullRequestWatch", () => {
176176
assert.deepEqual(evaluatePullRequestWatch(green.next, botDone, noRemarks).changes, []);
177177
});
178178

179+
it("reports an owed non-required failure once after the required notice", () => {
180+
const required = { ...check("test", "success"), required: true };
181+
const early = detail({ checks: [required, check("e2e", "pending")] });
182+
const first = evaluatePullRequestWatch(watch(), early, noRemarks);
183+
assert.deepEqual(first.changes, [{ kind: "checks-passed", count: 1, required: true }]);
184+
const failed = detail({ checks: [required, check("e2e", "failure")] });
185+
const failure = evaluatePullRequestWatch(first.next, failed, noRemarks);
186+
assert.deepEqual(failure.changes, [
187+
{ kind: "checks-failed", failed: [check("e2e", "failure")] },
188+
]);
189+
const repeated = evaluatePullRequestWatch(failure.next, failed, noRemarks);
190+
assert.deepEqual(repeated.changes, []);
191+
const recovered = detail({ checks: [required, check("e2e", "success")] });
192+
const final = evaluatePullRequestWatch(repeated.next, recovered, noRemarks);
193+
assert.deepEqual(final.changes, [{ kind: "checks-passed", count: 2, required: false }]);
194+
assert.deepEqual(evaluatePullRequestWatch(final.next, recovered, noRemarks).changes, []);
195+
});
196+
197+
it("clears old-head owed checks when a new head is pushed", () => {
198+
const required = { ...check("test", "success"), required: true };
199+
const early = detail({ checks: [required, check("e2e", "pending")] });
200+
const first = evaluatePullRequestWatch(watch(), early, noRemarks);
201+
assert.deepEqual(first.next.owedChecks, ["e2e"]);
202+
const unreadHead = detail({ headSha: "bbbbbbbbbb", checks: [] });
203+
const unread = evaluatePullRequestWatch(first.next, unreadHead, noRemarks);
204+
assert.deepEqual(unread.changes, []);
205+
assert.deepEqual(unread.next.owedChecks, []);
206+
const pushed = detail({ ...unreadHead, checks: [required] });
207+
const newHead = evaluatePullRequestWatch(unread.next, pushed, noRemarks);
208+
assert.deepEqual(newHead.changes, [{ kind: "checks-passed", count: 1, required: true }]);
209+
assert.deepEqual(newHead.next.owedChecks, []);
210+
const lateResult = detail({ ...pushed, checks: [required, check("e2e", "success")] });
211+
const final = evaluatePullRequestWatch(newHead.next, lateResult, noRemarks);
212+
assert.deepEqual(final.changes, []);
213+
assert.deepEqual(evaluatePullRequestWatch(final.next, lateResult, noRemarks).changes, []);
214+
});
215+
179216
// regression: #16208 PR watches burned GitHub's rate limit and gave up
180217
it("does not report passed again for a new passed check where none is required", () => {
181218
const first = evaluatePullRequestWatch(

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

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,127 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
26222622
}),
26232623
);
26242624

2625+
it.effect("finishes owed checks once after pending sweeps, a restart, and a re-watch", () =>
2626+
Effect.gen(function* () {
2627+
const orchestrator = yield* Orchestrator.OrchestratorV2;
2628+
const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
2629+
const threadId = ThreadId.make("runtime-pull-request-watch-owed");
2630+
const projectId = ProjectId.make("pr-watch-owed-project");
2631+
yield* seedProject({
2632+
projectId,
2633+
title: "Watch owed",
2634+
workspaceRoot: "/workspace/watch-owed",
2635+
defaultModelSelection: null,
2636+
createdAt: "2026-10-01T00:00:00.000Z",
2637+
});
2638+
yield* orchestrator.dispatch({
2639+
type: "thread.create",
2640+
createdBy: "user",
2641+
creationSource: "web",
2642+
commandId: CommandId.make("pr-watch-owed-create"),
2643+
threadId,
2644+
projectId,
2645+
title: "Watch owed",
2646+
modelSelection,
2647+
runtimeMode: "full-access",
2648+
interactionMode: "default",
2649+
branch: null,
2650+
worktreePath: null,
2651+
});
2652+
const watch = (on: boolean, id: string) =>
2653+
orchestrator.dispatch({
2654+
type: "thread.pull-request.watch",
2655+
commandId: CommandId.make(`pr-watch-owed-${id}`),
2656+
threadId,
2657+
host: "github.com",
2658+
repository: "pingdotgg/t3code",
2659+
number: 12,
2660+
watching: on,
2661+
link: { url: "https://github.com/pingdotgg/t3code/pull/12", source: "agent" },
2662+
});
2663+
yield* watch(true, "start");
2664+
2665+
let remainingStatus: "pending" | "success" = "pending";
2666+
const host = Layer.mergeAll(
2667+
NodeServices.layer,
2668+
Layer.mock(PullRequestService.PullRequestService)({
2669+
detail: () =>
2670+
Effect.sync(() => ({
2671+
...watchedPullRequestDetail({
2672+
projectId,
2673+
number: 12,
2674+
at: "2026-10-02T12:00:00.000Z",
2675+
}),
2676+
headSha: "ad70160aaa",
2677+
checks: ["lint", "test"].map((name) => ({
2678+
name,
2679+
status: name === "test" ? remainingStatus : ("success" as const),
2680+
description: null,
2681+
url: null,
2682+
required: name === "lint",
2683+
})),
2684+
})),
2685+
activity: () =>
2686+
Effect.succeed({
2687+
comments: [],
2688+
commentCount: 0,
2689+
commentsTruncated: false,
2690+
reviewThreads: [],
2691+
commits: [],
2692+
}),
2693+
}),
2694+
);
2695+
const summaries = Effect.map(
2696+
orchestrator.getThreadRecords(threadId, ["messages"]),
2697+
({ messages }) => messages.flatMap((message) => message.notification?.summary ?? []),
2698+
);
2699+
2700+
const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2701+
yield* reactor.sweep;
2702+
yield* worker.drain();
2703+
yield* TestClock.adjust("10 minutes");
2704+
yield* reactor.sweep;
2705+
yield* worker.drain();
2706+
assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2707+
2708+
assert.deepEqual(
2709+
(yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks,
2710+
["test"],
2711+
);
2712+
// The fresh reactor reloads the nonempty obligation from the persisted watch.
2713+
const restarted = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
2714+
yield* restarted.sweep;
2715+
yield* worker.drain();
2716+
assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2717+
2718+
// A new watch on the same pull request knows what the last one told.
2719+
yield* watch(false, "stop");
2720+
yield* watch(true, "again");
2721+
yield* restarted.sweep;
2722+
yield* worker.drain();
2723+
assert.deepEqual(yield* summaries, ["#12: checks passed"]);
2724+
2725+
assert.deepEqual(
2726+
(yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks,
2727+
["test"],
2728+
);
2729+
remainingStatus = "success";
2730+
yield* TestClock.adjust("10 minutes");
2731+
yield* restarted.sweep;
2732+
yield* worker.drain();
2733+
assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]);
2734+
yield* TestClock.adjust("10 minutes");
2735+
yield* restarted.sweep;
2736+
yield* worker.drain();
2737+
assert.deepEqual(yield* summaries, ["#12: checks passed", "#12: checks passed"]);
2738+
assert.deepEqual(
2739+
(yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch?.owedChecks,
2740+
[],
2741+
);
2742+
yield* watch(false, "end");
2743+
}),
2744+
);
2745+
26252746
// regression: #21155 watching a pull request again repeated news the thread already got
26262747
it.effect("a watch that ends on the comment limit keeps what its last pass saw", () =>
26272748
Effect.gen(function* () {

0 commit comments

Comments
 (0)