From fec91a9153b11ad7b7617f69dc3b36d41c4ee6e1 Mon Sep 17 00:00:00 2001 From: quality Date: Sat, 3 Oct 2026 09:38:29 -0400 Subject: [PATCH] test(bundle): drive /approve cancel on a repository without OWNERS files through dist/index.js The legacy no-OWNERS path of src/issueComment/approve.ts (list reviews, dismiss the bot's latest APPROVED one) was only reached by unit mocks. One bundle case now runs it against the fake API and asserts the single dismissal of the last bot APPROVED review, its message, and that no review, label or comment is written. Signed-off-by: quality --- __tests__/bundle/bundle.test.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/__tests__/bundle/bundle.test.ts b/__tests__/bundle/bundle.test.ts index 3145a4ef..36036af5 100644 --- a/__tests__/bundle/bundle.test.ts +++ b/__tests__/bundle/bundle.test.ts @@ -643,6 +643,39 @@ describe('dist/index.js', () => { `POST ${repo}/pulls/1/reviews`, ], [`GET ${repo}/pulls/1`, ownersProbe, queueRead]) }) + + it('on a repository without OWNERS files /approve cancel dismisses the bot\'s latest APPROVED review and touches no label', async () => { + routeOwners({}, ['src/file1.txt']) + gh.route('GET', `/orgs/Codertocat/members/bob`, { status: 204 }) + gh.route('GET', `${repo}/pulls/1/reviews`, { + status: 200, + body: [ + { id: 10, user: bot, state: 'APPROVED' }, + { id: 11, user: { login: 'carol', type: 'User' }, state: 'APPROVED' }, + { id: 12, user: bot, state: 'APPROVED' }, + { id: 13, user: bot, state: 'DISMISSED' }, + ], + }) + gh.route('PUT', `${repo}/pulls/1/reviews/12/dismissals`, { status: 200, body: {} }) + + const result = await runApprove('/approve cancel', 'bob') + + expect(result.status, result.stdout).toBe(0) + expect(result.errors).toEqual([]) + const dismissals = gh.requestsMatching('PUT', /\/dismissals$/) + expect(dismissals).toHaveLength(1) + expect(dismissals[0].path).toBe(`${repo}/pulls/1/reviews/12/dismissals`) + expect(dismissals[0].body).toEqual({ message: 'Canceled through prow-github-actions by @bob' }) + expect(gh.requestsMatching('POST', /\/pulls\/1\/reviews$/)).toEqual([]) + expect(gh.requestsMatching('DELETE', /\/issues\/1\/labels\//)).toEqual([]) + expect(gh.requestsMatching('POST', /\/issues\/1\/comments$/)).toEqual([]) + expectCommandThenConfig([ + ...ownersReads, + ...membershipReads('bob'), + `GET ${repo}/pulls/1/reviews`, + `PUT ${repo}/pulls/1/reviews/12/dismissals`, + ], [`GET ${repo}/pulls/1`, ownersProbe, queueRead]) + }) }) describe('issue_comment trigger commands on a pull request', () => {