From 78d91751be281a14d39a426c0adb8040c778d297 Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:44:44 -0500 Subject: [PATCH] test(lgtm): pin that a reviewer's /lgtm on an issue whose author account is gone is applied The webhook schema allows issue.user to be null (a deleted account). The author guard in src/labels/lgtm.ts reads it through optional chaining; with the chaining dropped a reviewer's /lgtm on such an issue fails with a TypeError before any read, and no test noticed. The case fails on that mutant and passes on main. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- __tests__/label/lgtmGuards.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/__tests__/label/lgtmGuards.test.ts b/__tests__/label/lgtmGuards.test.ts index 1ae92ce0..701e722e 100644 --- a/__tests__/label/lgtmGuards.test.ts +++ b/__tests__/label/lgtmGuards.test.ts @@ -74,4 +74,27 @@ describe('/lgtm guards', () => { expect(debug).toHaveBeenCalledWith('could not find lgtm to remove') await expect(observeRemove.notCalled()).resolves.toBe('not called') }) + + // the webhook schema allows `issue.user: null` (a deleted account); a reviewer's /lgtm on + // such an issue is nobody's own and is applied, not refused or failed on reading the author + it('a /lgtm by a reviewer on an issue whose author account is gone is applied', async () => { + const payload = structuredClone(issueCommentEvent) + payload.comment.body = '/lgtm' + Object.assign(payload.issue, { user: null }) + const observeLabel = new utils.ObserveRequest() + const observeComment = new utils.ObserveRequest() + server.use( + http.get(`${utils.api}/orgs/Codertocat/members/Codertocat`, utils.mockResponse(204)), + http.get(`${utils.api}/repos/Codertocat/Hello-World/collaborators/Codertocat`, utils.mockResponse(404)), + http.get(`${utils.api}/repos/Codertocat/Hello-World/contents/OWNERS`, utils.mockResponse(404)), + utils.repoHasLabels(['lgtm']), + http.post(`${issue}/labels`, utils.mockResponse(200, null, observeLabel)), + http.post(`${issue}/comments`, utils.mockResponse(200, null, observeComment)), + ) + + await expect(lgtm(new utils.MockContext(payload))).resolves.toBeUndefined() + + expect(await observeLabel.body()).toEqual({ labels: ['lgtm'] }) + await expect(observeComment.notCalled()).resolves.toBe('not called') + }) })