From 0837f1412151b89ed35caae2d0483c5d24342ce1 Mon Sep 17 00:00:00 2001 From: quality Date: Tue, 6 Oct 2026 16:51:24 -0400 Subject: [PATCH 1/2] test(bundle): drive the prow-commands alias canonicalization and unsupported-command arms through dist/index.js Adds __tests__/bundle/commandCanonicalization.test.ts: three issue_comment runs of the committed bundle against fakeGithub reach handleIssueComment.ts L86 (a configured /remove-help runs the /help module; duplicates collapse to one run) and L150 (a configured /foo_bar fails the run naming it, no api call). e2e lines 93.90 -> 96.34 %, branches 86.27 -> 90.19 %. Closes #356 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: quality --- .../bundle/commandCanonicalization.test.ts | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 __tests__/bundle/commandCanonicalization.test.ts diff --git a/__tests__/bundle/commandCanonicalization.test.ts b/__tests__/bundle/commandCanonicalization.test.ts new file mode 100644 index 0000000..00f145b --- /dev/null +++ b/__tests__/bundle/commandCanonicalization.test.ts @@ -0,0 +1,72 @@ +import type { FakeGithub } from './fakeGithub' +import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest' + +import { start } from './fakeGithub' +import { comment, helpersFor, repo, token } from './helpers' +import { runBundle } from './runBundle' + +vi.setConfig({ testTimeout: 30_000 }) + +// the `prow-commands` input's canonicalization in handleIssueComment: a Prow-style alias +// (/remove-help) names its canonical command's module, duplicates collapse to one run, and +// a configured name no module serves fails the run +describe('dist/index.js prow-commands canonicalization', () => { + const labelsRead = `GET ${repo}/labels?per_page=100` + const labelPost = `POST ${repo}/issues/1/labels` + let gh: FakeGithub + const { calls, expectCommandThenConfig } = helpersFor(() => gh) + + beforeAll(async () => { + gh = await start() + }) + afterEach(() => gh.reset()) + afterAll(() => gh.close()) + + function routeHelp() { + gh.route('GET', `${repo}/labels`, { status: 200, body: [{ name: 'help wanted' }] }) + gh.route('POST', `${repo}/issues/1/labels`, { status: 200, body: [] }) + } + + async function run(body: string, commands: string) { + return runBundle({ + eventName: 'issue_comment', + payload: comment(body), + inputs: { ...token, 'prow-commands': commands }, + apiUrl: gh.url, + }) + } + + it('a configured /remove-help alias runs the /help module: /help adds help wanted', async () => { + routeHelp() + + const result = await run('/help', '/remove-help') + + expect(result.status, result.stdout).toBe(0) + expect(result.errors).toEqual([]) + const posts = gh.requestsMatching('POST', /\/issues\/1\/labels$/) + expect(posts).toHaveLength(1) + expect(posts[0].body).toEqual({ labels: ['help wanted'] }) + expectCommandThenConfig([labelsRead, labelPost]) + }) + + it('/help, /remove-help and /HELP configured together collapse to a single /help run', async () => { + routeHelp() + + const result = await run('/help', '/help /remove-help /HELP') + + expect(result.status, result.stdout).toBe(0) + expect(result.errors).toEqual([]) + expect(gh.requestsMatching('POST', /\/issues\/1\/labels$/)).toHaveLength(1) + expectCommandThenConfig([labelsRead, labelPost]) + }) + + it('a configured command no module serves fails the run naming it and makes no api call', async () => { + const result = await run('/foo_bar', '/foo_bar') + + expect(result.status, result.stdout).toBe(1) + expect(result.errors).toEqual([ + 'TypeError: error handling issue comment: Error: could not execute /foo_bar. May not be supported - please refer to docs', + ]) + expect(calls()).toEqual([]) + }) +}) From f821b7ea99d28ecb9d90d83501d230e43362cdd8 Mon Sep 17 00:00:00 2001 From: quality Date: Wed, 7 Oct 2026 22:14:20 -0400 Subject: [PATCH 2/2] test(bundle): drop the duplicated alias-collapse case and check the unsupported-command error by fragment Signed-off-by: quality --- .../bundle/commandCanonicalization.test.ts | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/__tests__/bundle/commandCanonicalization.test.ts b/__tests__/bundle/commandCanonicalization.test.ts index 00f145b..42be15a 100644 --- a/__tests__/bundle/commandCanonicalization.test.ts +++ b/__tests__/bundle/commandCanonicalization.test.ts @@ -2,7 +2,7 @@ import type { FakeGithub } from './fakeGithub' import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest' import { start } from './fakeGithub' -import { comment, helpersFor, repo, token } from './helpers' +import { comment, configReads, helpersFor, repo, token } from './helpers' import { runBundle } from './runBundle' vi.setConfig({ testTimeout: 30_000 }) @@ -14,7 +14,7 @@ describe('dist/index.js prow-commands canonicalization', () => { const labelsRead = `GET ${repo}/labels?per_page=100` const labelPost = `POST ${repo}/issues/1/labels` let gh: FakeGithub - const { calls, expectCommandThenConfig } = helpersFor(() => gh) + const { calls, expectRequests } = helpersFor(() => gh) beforeAll(async () => { gh = await start() @@ -46,27 +46,15 @@ describe('dist/index.js prow-commands canonicalization', () => { const posts = gh.requestsMatching('POST', /\/issues\/1\/labels$/) expect(posts).toHaveLength(1) expect(posts[0].body).toEqual({ labels: ['help wanted'] }) - expectCommandThenConfig([labelsRead, labelPost]) - }) - - it('/help, /remove-help and /HELP configured together collapse to a single /help run', async () => { - routeHelp() - - const result = await run('/help', '/help /remove-help /HELP') - - expect(result.status, result.stdout).toBe(0) - expect(result.errors).toEqual([]) - expect(gh.requestsMatching('POST', /\/issues\/1\/labels$/)).toHaveLength(1) - expectCommandThenConfig([labelsRead, labelPost]) + expectRequests(configReads(), [labelsRead, labelPost]) }) it('a configured command no module serves fails the run naming it and makes no api call', async () => { const result = await run('/foo_bar', '/foo_bar') expect(result.status, result.stdout).toBe(1) - expect(result.errors).toEqual([ - 'TypeError: error handling issue comment: Error: could not execute /foo_bar. May not be supported - please refer to docs', - ]) + expect(result.errors).toHaveLength(1) + expect(result.errors[0]).toContain('could not execute /foo_bar') expect(calls()).toEqual([]) }) })