Skip to content
TypeScript

fix(forgejo): wake PR watches for edited comments (#18120)

Marc Went74e5bd22a96b
diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.forgejoComments.test.ts b/apps/server/src/orchestration-v2/pullRequestWatch.forgejoComments.test.ts
new file mode 100644
index 00000000000..53a77e178c5
--- /dev/null
+++ b/apps/server/src/orchestration-v2/pullRequestWatch.forgejoComments.test.ts
@@ -0,0 +1,80 @@
+import type { ThreadPullRequestWatch } from "@t3tools/contracts";
+import { assert, describe, it } from "@effect/vitest";
+import * as Schema from "effect/Schema";
+import {
+ ForgejoComment,
+ forgejoComment,
+} from "@t3tools/source-control-forgejo/server/forgejoPullRequestJson";
+
+import { evaluatePullRequestWatch } from "./pullRequestWatch.ts";
+
+const decodeForgejoComment = Schema.decodeSync(ForgejoComment);
+
+describe("Forgejo comment watch boundary", () => {
+ const createdAt = "2026-10-10T19:52:40Z";
+ const editedAt = "2026-10-10T20:04:50Z";
+ const seen = {
+ startedAt: "2026-10-02T12:00:00.000Z",
+ headSha: "aaaaaaaaaa",
+ failedChecks: [],
+ passed: false,
+ passedChecks: [],
+ remarksThrough: "2026-10-10T19:52:40.000Z",
+ remarkIds: ["29061"],
+ conflicting: false,
+ wakes: 2,
+ } satisfies ThreadPullRequestWatch;
+ const finalDetail = {
+ headSha: seen.headSha,
+ checks: [],
+ mergeability: "mergeable",
+ viewer: "agent-user",
+ author: { login: "agent-user", name: null, avatarUrl: null },
+ } satisfies Parameters<typeof evaluatePullRequestWatch>[1];
+ const decodedComment = (updatedAt: string | null | undefined) =>
+ forgejoComment(
+ decodeForgejoComment({
+ id: 29061,
+ body: "Performance: five rounds complete",
+ user: { login: "forgejo-actions" },
+ created_at: createdAt,
+ ...(updatedAt === undefined ? {} : { updated_at: updatedAt }),
+ }),
+ );
+
+ it.each([undefined, null, createdAt, "2026-10-10T19:52:40.000Z"])(
+ "does not wake for an unchanged comment with updated_at %s",
+ (updatedAt) => {
+ const comment = decodedComment(updatedAt);
+ assert.isUndefined(comment.editedAt);
+ assert.deepEqual(evaluatePullRequestWatch(seen, finalDetail, [comment]).changes, []);
+ },
+ );
+
+ it("wakes once for the edit of an already-seen benchmark comment", () => {
+ const finalComment = decodedComment(editedAt);
+ assert.strictEqual(finalComment.editedAt, "2026-10-10T20:04:50.000Z");
+ assert.isUndefined(decodedComment(createdAt).editedAt);
+ const completed = evaluatePullRequestWatch(seen, finalDetail, [finalComment]);
+ assert.deepEqual(completed.changes, [{ kind: "remarks", remarks: [finalComment] }]);
+ assert.strictEqual(completed.next.remarksThrough, "2026-10-10T20:04:50.000Z");
+ assert.deepEqual(
+ evaluatePullRequestWatch(completed.next, finalDetail, [finalComment]).changes,
+ [],
+ );
+ assert.deepEqual(
+ evaluatePullRequestWatch(seen, finalDetail, [decodedComment(createdAt)]).changes,
+ [],
+ );
+ const secondEdit = decodedComment("2026-10-10T20:05:50Z");
+ const second = evaluatePullRequestWatch(completed.next, finalDetail, [secondEdit]);
+ assert.deepEqual(second.changes, [{ kind: "remarks", remarks: [secondEdit] }]);
+ assert.deepEqual(evaluatePullRequestWatch(second.next, finalDetail, [secondEdit]).changes, []);
+ assert.deepEqual(
+ evaluatePullRequestWatch(seen, finalDetail, [
+ { ...finalComment, author: { login: "agent-user", name: null, avatarUrl: null } },
+ ]).changes,
+ [],
+ );
+ });
+});
diff --git a/packages/source-control-forgejo/src/server/forgejoPullRequestJson.ts b/packages/source-control-forgejo/src/server/forgejoPullRequestJson.ts
index 44d56688222..345ccdfea3d 100644
--- a/packages/source-control-forgejo/src/server/forgejoPullRequestJson.ts
+++ b/packages/source-control-forgejo/src/server/forgejoPullRequestJson.ts
@@ -68,6 +68,7 @@ export const ForgejoComment = Schema.Struct({
body: Schema.String,
user: Schema.NullOr(ForgejoUser),
created_at: Schema.String,
+ updated_at: Schema.optional(Schema.NullOr(Schema.String)),
html_url: Schema.optional(Schema.String),
});
export const ForgejoReview = Schema.Struct({
@@ -149,12 +150,15 @@ export function forgejoChangeRequest(pr: typeof ForgejoPullRequest.Type) {
}
export function forgejoComment(comment: typeof ForgejoComment.Type): PullRequestComment {
+ const createdAt = toIsoUtc(comment.created_at);
+ const editedAt = comment.updated_at == null ? undefined : toIsoUtc(comment.updated_at);
return {
id: String(comment.id),
kind: "issue-comment",
author: forgejoActor(comment.user),
body: comment.body,
- createdAt: toIsoUtc(comment.created_at),
+ createdAt,
+ ...(editedAt === undefined || editedAt === createdAt ? {} : { editedAt }),
url: comment.html_url || null,
path: null,
reviewState: null,