Skip to content

Commit 3cabb41

Browse files
Ben ThomasCopilot
authored andcommitted
test(hub): preserve deleted review privacy
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 3c35f86 commit 3cabb41

4 files changed

Lines changed: 74 additions & 16 deletions

File tree

  • hub

‎hub/server/domains/learning/create-learning-job-processors/index.ts‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,29 @@ export function createLearningJobProcessors(environment: NodeJS.ProcessEnv, logg
188188
`learning-run-${queued.id}`,
189189
)
190190
}
191-
for (const comment of await listDeletedReviewComments(prisma)) {
192-
await enqueueRecoverableJob(
193-
queue,
194-
redactReviewCommentJob,
195-
{
196-
repositoryId: comment.thread.repositoryId,
197-
commentId: comment.publicId,
198-
actor: comment.learningRedactionActor ?? `human:${comment.authorLogin}`,
199-
},
200-
`learning-redact-${comment.thread.repositoryId}-${comment.publicId}`,
201-
)
202-
}
191+
let redactionCursor: { deletedAt: Date; id: string } | undefined
192+
do {
193+
const comments = await listDeletedReviewComments(prisma, {
194+
...(redactionCursor ? { after: redactionCursor } : {}),
195+
})
196+
for (const comment of comments) {
197+
await enqueueRecoverableJob(
198+
queue,
199+
redactReviewCommentJob,
200+
{
201+
repositoryId: comment.thread.repositoryId,
202+
commentId: comment.publicId,
203+
actor: comment.learningRedactionActor ?? `human:${comment.authorLogin}`,
204+
},
205+
`learning-redact-${comment.thread.repositoryId}-${comment.publicId}`,
206+
)
207+
}
208+
const last = comments.at(-1)
209+
redactionCursor =
210+
comments.length === 100 && last?.deletedAt
211+
? { deletedAt: last.deletedAt, id: last.id }
212+
: undefined
213+
} while (redactionCursor)
203214
for (const operation of await listLearningDecisionOperations(prisma)) {
204215
try {
205216
await reconcileLearningDecisionOperation(operation, {

‎hub/server/domains/learning/create-review-comment-learning-source/index.test.ts‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { describe, expect, it, vi } from "vitest"
2+
import type { RepositoryReviewSnapshot } from "../../review-comments/types"
23

34
const { capture } = vi.hoisted(() => ({ capture: vi.fn() }))
45
vi.mock("../../review-comments/capture-repository-review-snapshot/index.ts", () => ({
@@ -11,7 +12,7 @@ const repositoryId = "11111111-2222-4333-8444-555555555555"
1112
const prototypeId = "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa"
1213
const capturedAt = new Date("2026-11-13T10:00:00Z")
1314

14-
function snapshot() {
15+
function snapshot(): RepositoryReviewSnapshot {
1516
const author = {
1617
userId: "22222222-2222-4222-8222-222222222222",
1718
login: "mona",
@@ -24,10 +25,22 @@ function snapshot() {
2425
threads: [
2526
{
2627
id: 101,
28+
storageId: "77777777-7777-4777-8777-777777777777",
2729
repositoryId,
2830
prototype: { id: prototypeId, name: "Design", branch: "design" },
2931
buildNumber: 7,
30-
anchor: {},
32+
anchor: {
33+
schemaVersion: 1,
34+
kind: "element",
35+
route: { pathname: "/", search: "", hash: "" },
36+
selector: "#section",
37+
accessibleName: "Section",
38+
tagName: "section",
39+
selectedText: "",
40+
rect: { x: 0, y: 0, width: 100, height: 100 },
41+
viewport: { width: 1000, height: 800, scrollX: 0, scrollY: 0 },
42+
elementOffset: { x: 0, y: 0 },
43+
},
3144
activityVersion: 1,
3245
createdAt: capturedAt,
3346
updatedAt: capturedAt,
@@ -52,6 +65,29 @@ function snapshot() {
5265
}
5366

5467
describe("createReviewCommentLearningSource()", () => {
68+
it("keeps retained deleted bodies out of the package collection", async () => {
69+
const value = snapshot()
70+
value.threads[0]!.root = {
71+
...value.threads[0]!.root,
72+
body: null,
73+
deletedAt: capturedAt,
74+
}
75+
capture.mockResolvedValue(value)
76+
const source = createReviewCommentLearningSource({} as never, "https://hub.example.com")
77+
78+
const result = await source.captureCompleteSnapshot({ repositoryId })
79+
const collection = result.collection as {
80+
calls: Array<{
81+
result: { threads: Array<{ body: string | null; deletedAt: string | null }> }
82+
}>
83+
}
84+
85+
expect(collection.calls[0]?.result.threads[0]).toMatchObject({
86+
body: null,
87+
deletedAt: capturedAt.toISOString(),
88+
})
89+
})
90+
5591
it("resolves only evidence whose source and observed comment version match", async () => {
5692
const value = snapshot()
5793
capture.mockResolvedValue(value)

‎hub/server/repositories/review-comments/list-deleted-review-comments/index.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,28 @@ import type { Prisma } from "../../../generated/prisma/client.ts"
22

33
export function listDeletedReviewComments(
44
database: Pick<Prisma.TransactionClient, "reviewComment">,
5-
limit = 100,
5+
input: { after?: { deletedAt: Date; id: string }; limit?: number } = {},
66
) {
7+
const limit = input.limit ?? 100
78
return database.reviewComment.findMany({
89
where: {
910
deletedAt: { not: null },
1011
learningRedactedAt: null,
12+
...(input.after
13+
? {
14+
OR: [
15+
{ deletedAt: { gt: input.after.deletedAt } },
16+
{ deletedAt: input.after.deletedAt, id: { gt: input.after.id } },
17+
],
18+
}
19+
: {}),
1120
},
1221
orderBy: [{ deletedAt: "asc" }, { id: "asc" }],
1322
take: limit,
1423
select: {
1524
publicId: true,
25+
id: true,
26+
deletedAt: true,
1627
authorLogin: true,
1728
learningRedactionActor: true,
1829
thread: { select: { repositoryId: true } },

‎hub/test/database/learning-migration/index.db.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("learning migration", () => {
8181
await database.query(
8282
`INSERT INTO review_comments
8383
(id, thread_id, author_id, author_login, body, deleted_at)
84-
VALUES ($1, $2, $3, 'mona', NULL, clock_timestamp())`,
84+
VALUES ($1, $2, $3, 'mona', 'Retained deleted text', clock_timestamp())`,
8585
[commentId, threadId, userId],
8686
)
8787

0 commit comments

Comments
 (0)