From af3c92ba8f5bb3fe34bb70b316e178c05c83537a Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" Date: Sat, 26 Sep 2026 23:57:00 -0400 Subject: [PATCH] test(issueComment): cover the /check-required-labels sweep dedup and non-Error rejections in handleIssueComment Adds five dispatcher tests: the sweep skips checkRequiredLabels when the comment already ran /check-required-labels, still runs it otherwise, a handler or sweep step rejecting with a non-Error value fails the run with the coerced message, and a command failure and a sweep failure are joined into one setFailed call. handleIssueComment.ts: 94.33% -> 100% branches. Signed-off-by: hivecommons-hive[bot] --- .../handleIssueComment.test.ts | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/__tests__/issueCommentTest/handleIssueComment.test.ts b/__tests__/issueCommentTest/handleIssueComment.test.ts index a84fb3fc..193a0588 100644 --- a/__tests__/issueCommentTest/handleIssueComment.test.ts +++ b/__tests__/issueCommentTest/handleIssueComment.test.ts @@ -760,3 +760,65 @@ describe('after a command ran', () => { expect(setFailed).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('could not merge pull request(s) #1')) }) }) + +describe('the sweep after a label-writing command', () => { + beforeEach(() => { + vi.spyOn(lgtm, 'lgtm').mockResolvedValue() + vi.spyOn(core, 'setFailed').mockImplementation(() => {}) + }) + + it('does not re-check required labels when the comment already ran /check-required-labels', async () => { + utils.setupActionsEnv('/lgtm /check-required-labels') + issueCommentEvent.comment.body = '/lgtm\n/check-required-labels' + + await handleIssueComment(new utils.MockContext(issueCommentEvent)) + + expect(requireMatchingLabel.checkRequiredLabels).toHaveBeenCalledTimes(1) + expect(tide.tideOnComment).toHaveBeenCalledTimes(1) + expect(core.setFailed).not.toHaveBeenCalled() + }) + + it('re-checks required labels when /check-required-labels is configured but not in the comment', async () => { + utils.setupActionsEnv('/lgtm /check-required-labels') + issueCommentEvent.comment.body = '/lgtm' + + await handleIssueComment(new utils.MockContext(issueCommentEvent)) + + expect(requireMatchingLabel.checkRequiredLabels).toHaveBeenCalledTimes(1) + expect(tide.tideOnComment).toHaveBeenCalledTimes(1) + expect(core.setFailed).not.toHaveBeenCalled() + }) + + it('fails the run when a command rejects with a non-Error value', async () => { + utils.setupActionsEnv('/lgtm') + issueCommentEvent.comment.body = '/lgtm' + vi.spyOn(lgtm, 'lgtm').mockRejectedValue('lgtm exploded') + + await handleIssueComment(new utils.MockContext(issueCommentEvent)) + + expect(core.setFailed).toHaveBeenCalledExactlyOnceWith(expect.stringContaining('error handling issue comment: Error: lgtm exploded')) + expect(tide.tideOnComment).toHaveBeenCalledTimes(1) + }) + + it('fails the run when a sweep step rejects with a non-Error value and still runs the later steps', async () => { + utils.setupActionsEnv('/lgtm') + issueCommentEvent.comment.body = '/lgtm' + vi.spyOn(requireMatchingLabel, 'checkRequiredLabels').mockRejectedValue('needs-kind exploded') + + await handleIssueComment(new utils.MockContext(issueCommentEvent)) + + expect(core.setFailed).toHaveBeenCalledExactlyOnceWith('Error: needs-kind exploded') + expect(tide.tideOnComment).toHaveBeenCalledTimes(1) + }) + + it('joins a command failure and a sweep failure into one message', async () => { + utils.setupActionsEnv('/lgtm') + issueCommentEvent.comment.body = '/lgtm' + vi.spyOn(lgtm, 'lgtm').mockRejectedValue(new Error('lgtm exploded')) + vi.spyOn(tide, 'tideOnComment').mockRejectedValue(new Error('tide exploded')) + + await handleIssueComment(new utils.MockContext(issueCommentEvent)) + + expect(core.setFailed).toHaveBeenCalledExactlyOnceWith('TypeError: error handling issue comment: Error: lgtm exploded; Error: tide exploded') + }) +})