From 86a609fd2214b38a69e6363b95a1f1b48b32e1f2 Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" Date: Sat, 26 Sep 2026 21:55:31 -0400 Subject: [PATCH] test(auth): cover the getErrorDetails fallback branches for string, empty-object and bare Error rejections checkOrgMember, checkCollaborator and checkIssueComments route every caught error through getErrorDetails, but only the { status, message } shape was exercised. Add one rejection per fallback branch: a plain string (non-object), an empty object (no status, no message) and a bare Error (no status), asserting the exact core.warning text. Signed-off-by: hivecommons-hive[bot] --- __tests__/utils/auth.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/__tests__/utils/auth.test.ts b/__tests__/utils/auth.test.ts index 848feb10..9129cb7e 100644 --- a/__tests__/utils/auth.test.ts +++ b/__tests__/utils/auth.test.ts @@ -85,6 +85,18 @@ describe('checkOrgMember', () => { ) }) + it('warns with status=unknown when the rejection is a plain string', async () => { + const warningSpy = vi.spyOn(core, 'warning') + + vi.spyOn(octokit.orgs, 'checkMembershipForUser').mockRejectedValueOnce('socket hang up') + + await expect(checkOrgMember(octokit, context, 'some-user')).resolves.toBe(false) + + expect(warningSpy).toHaveBeenCalledWith( + 'encountered unexpected error: status=unknown, message=socket hang up', + ) + }) + it('is false when the payload has no repository', async () => { const noRepo = new utils.MockContext({}) @@ -134,6 +146,18 @@ describe('checkCollaborator', () => { expect.stringContaining('status=500'), ) }) + + it('warns with status=unknown when the rejection has neither status nor message', async () => { + const warningSpy = vi.spyOn(core, 'warning') + + vi.spyOn(octokit.repos, 'checkCollaborator').mockRejectedValueOnce({}) + + await expect(checkCollaborator(octokit, context, 'some-user')).resolves.toBe(false) + + expect(warningSpy).toHaveBeenCalledWith( + 'encountered unexpected error checking collaborator status: status=unknown, message=[object Object]', + ) + }) }) describe('checkIssueComments', () => { @@ -175,6 +199,18 @@ describe('checkIssueComments', () => { expect.stringContaining('status=500'), ) }) + + it('warns with status=unknown when the rejection is an Error without a status', async () => { + const warningSpy = vi.spyOn(core, 'warning') + + vi.spyOn(octokit.issues, 'listComments').mockRejectedValueOnce(new Error('network down')) + + await expect(checkIssueComments(octokit, context, 1, 'some-user')).resolves.toBe(false) + + expect(warningSpy).toHaveBeenCalledWith( + 'encountered unexpected error checking issue comments: status=unknown, message=network down', + ) + }) }) describe('checkCommenterAuth', () => {