Skip to content

Commit f543e4f

Browse files
Ben ThomasCopilot
authored andcommitted
fix(hub): close hidden review threads
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 03bbe57 commit f543e4f

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

‎hub/server/domains/review-comments/review-comments.db.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,65 @@ describe("review comments", () => {
392392
expect(resolvedAgain.resolvedBy).toEqual(secondReviewer)
393393
})
394394

395+
it("rejects every mutation after the prototype becomes hidden", async () => {
396+
const repository = await createRepository()
397+
const { prototype, build } = await createReviewablePrototype(
398+
repository.id,
399+
"prototype/checkout",
400+
)
401+
const author = await createUser("mona", "Mona")
402+
const reviewer = await createUser("hubot", "Hubot")
403+
const service = createTestReviewService()
404+
const thread = await service.createThread({
405+
repositoryId: repository.id,
406+
prototypeId: prototype.id,
407+
buildNumber: build.number,
408+
body: "Hide this branch.",
409+
anchor,
410+
actor: author,
411+
})
412+
await prisma.prototype.update({
413+
where: { id: prototype.id },
414+
data: { branchDeletedAt: new Date("2026-11-16T00:00:00Z") },
415+
})
416+
417+
await expect(
418+
service.createReply({
419+
repositoryId: repository.id,
420+
prototypeId: prototype.id,
421+
threadId: thread.id,
422+
body: "Reply",
423+
actor: reviewer,
424+
}),
425+
).rejects.toMatchObject({ code: "not_found" })
426+
await expect(
427+
service.editComment({
428+
repositoryId: repository.id,
429+
prototypeId: prototype.id,
430+
commentId: thread.root.id,
431+
body: "Edited",
432+
actor: author,
433+
}),
434+
).rejects.toMatchObject({ code: "not_found" })
435+
await expect(
436+
service.deleteComment({
437+
repositoryId: repository.id,
438+
prototypeId: prototype.id,
439+
commentId: thread.root.id,
440+
actor: author,
441+
}),
442+
).rejects.toMatchObject({ code: "not_found" })
443+
await expect(
444+
service.setResolution({
445+
repositoryId: repository.id,
446+
prototypeId: prototype.id,
447+
threadId: thread.id,
448+
resolved: true,
449+
actor: reviewer,
450+
}),
451+
).rejects.toMatchObject({ code: "not_found" })
452+
})
453+
395454
it("captures one complete repository snapshot and rejects removed repositories", async () => {
396455
const capturedAt = new Date("2026-11-13T18:00:00Z")
397456
const repository = await createRepository("team/snapshot")

‎hub/server/repositories/review-comments/create-review-comment-repository/index.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,35 @@ interface Actor {
1212

1313
type AuthorizeMutation = (transaction: Prisma.TransactionClient) => Promise<boolean>
1414

15+
function reviewablePrototypeWhere(
16+
repositoryId: string,
17+
prototypeId: string,
18+
defaultBranch: string,
19+
): Prisma.PrototypeWhereInput {
20+
return {
21+
id: prototypeId,
22+
repositoryId,
23+
registeredAt: { not: null },
24+
branchDeletedAt: null,
25+
replica: false,
26+
branchName: { notIn: [defaultBranch, "replica/install-workflow"] },
27+
}
28+
}
29+
1530
async function findStoredThread(
1631
transaction: Prisma.TransactionClient,
1732
repositoryId: string,
1833
prototypeId: string,
1934
threadId: string,
35+
defaultBranch: string,
2036
) {
2137
return transaction.reviewThread.findFirst({
2238
where: {
2339
id: threadId,
2440
repositoryId,
2541
prototypeId,
2642
repository: { removedAt: null },
43+
prototype: reviewablePrototypeWhere(repositoryId, prototypeId, defaultBranch),
2744
},
2845
include: reviewThreadInclude,
2946
})
@@ -34,12 +51,14 @@ async function findStoredThreadByPublicId(
3451
repositoryId: string,
3552
prototypeId: string,
3653
threadId: number,
54+
defaultBranch: string,
3755
) {
3856
return transaction.reviewThread.findFirst({
3957
where: {
4058
repositoryId,
4159
prototypeId,
4260
repository: { removedAt: null },
61+
prototype: reviewablePrototypeWhere(repositoryId, prototypeId, defaultBranch),
4362
comments: { some: { publicId: threadId, rootId: null } },
4463
},
4564
include: reviewThreadInclude,
@@ -159,11 +178,17 @@ export function createReviewCommentRepository(database: Database) {
159178
if (!(await input.authorize(transaction))) {
160179
return { ok: false, reason: "session_invalid" }
161180
}
181+
const repository = await transaction.repository.findFirst({
182+
where: { id: input.repositoryId, removedAt: null },
183+
select: { defaultBranch: true },
184+
})
185+
if (!repository) return { ok: false, reason: "repository_not_found" }
162186
const thread = await findStoredThreadByPublicId(
163187
transaction,
164188
input.repositoryId,
165189
input.prototypeId,
166190
input.threadId,
191+
repository.defaultBranch,
167192
)
168193
if (!thread) return { ok: false, reason: "thread_not_found" }
169194
const root = thread.comments.find((comment) => comment.rootId === null)
@@ -191,6 +216,7 @@ export function createReviewCommentRepository(database: Database) {
191216
input.repositoryId,
192217
input.prototypeId,
193218
thread.id,
219+
repository.defaultBranch,
194220
)
195221
return stored ? { ok: true, value: stored } : { ok: false, reason: "thread_not_found" }
196222
},
@@ -211,13 +237,23 @@ export function createReviewCommentRepository(database: Database) {
211237
if (!(await input.authorize(transaction))) {
212238
return { ok: false, reason: "session_invalid" }
213239
}
240+
const repository = await transaction.repository.findFirst({
241+
where: { id: input.repositoryId, removedAt: null },
242+
select: { defaultBranch: true },
243+
})
244+
if (!repository) return { ok: false, reason: "repository_not_found" }
214245
const comment = await transaction.reviewComment.findFirst({
215246
where: {
216247
publicId: input.commentId,
217248
thread: {
218249
repositoryId: input.repositoryId,
219250
prototypeId: input.prototypeId,
220251
repository: { removedAt: null },
252+
prototype: reviewablePrototypeWhere(
253+
input.repositoryId,
254+
input.prototypeId,
255+
repository.defaultBranch,
256+
),
221257
},
222258
},
223259
select: {
@@ -250,6 +286,7 @@ export function createReviewCommentRepository(database: Database) {
250286
input.repositoryId,
251287
input.prototypeId,
252288
comment.threadId,
289+
repository.defaultBranch,
253290
)
254291
return stored ? { ok: true, value: stored } : { ok: false, reason: "thread_not_found" }
255292
},
@@ -269,13 +306,23 @@ export function createReviewCommentRepository(database: Database) {
269306
if (!(await input.authorize(transaction))) {
270307
return { ok: false, reason: "session_invalid" }
271308
}
309+
const repository = await transaction.repository.findFirst({
310+
where: { id: input.repositoryId, removedAt: null },
311+
select: { defaultBranch: true },
312+
})
313+
if (!repository) return { ok: false, reason: "repository_not_found" }
272314
const comment = await transaction.reviewComment.findFirst({
273315
where: {
274316
publicId: input.commentId,
275317
thread: {
276318
repositoryId: input.repositoryId,
277319
prototypeId: input.prototypeId,
278320
repository: { removedAt: null },
321+
prototype: reviewablePrototypeWhere(
322+
input.repositoryId,
323+
input.prototypeId,
324+
repository.defaultBranch,
325+
),
279326
},
280327
},
281328
select: {
@@ -306,6 +353,7 @@ export function createReviewCommentRepository(database: Database) {
306353
input.repositoryId,
307354
input.prototypeId,
308355
comment.threadId,
356+
repository.defaultBranch,
309357
)
310358
return stored ? { ok: true, value: stored } : { ok: false, reason: "thread_not_found" }
311359
},
@@ -326,11 +374,17 @@ export function createReviewCommentRepository(database: Database) {
326374
if (!(await input.authorize(transaction))) {
327375
return { ok: false, reason: "session_invalid" }
328376
}
377+
const repository = await transaction.repository.findFirst({
378+
where: { id: input.repositoryId, removedAt: null },
379+
select: { defaultBranch: true },
380+
})
381+
if (!repository) return { ok: false, reason: "repository_not_found" }
329382
const thread = await findStoredThreadByPublicId(
330383
transaction,
331384
input.repositoryId,
332385
input.prototypeId,
333386
input.threadId,
387+
repository.defaultBranch,
334388
)
335389
if (!thread) return { ok: false, reason: "thread_not_found" }
336390
const alreadyDesired = input.resolved
@@ -368,6 +422,7 @@ export function createReviewCommentRepository(database: Database) {
368422
input.repositoryId,
369423
input.prototypeId,
370424
thread.id,
425+
repository.defaultBranch,
371426
)
372427
return stored ? { ok: true, value: stored } : { ok: false, reason: "thread_not_found" }
373428
},

0 commit comments

Comments
 (0)