From b7ae47a6b7adf4cf4d87c90702abee5c4ce85581 Mon Sep 17 00:00:00 2001 From: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 08:01:02 -0400 Subject: [PATCH] test(harness): stop the unit suite's call-through @actions/core from emitting workflow commands setup.ts mocks @actions/core with spy: true, so the real implementation still runs and core.debug/info/warning/error/setFailed/setSecret write ::debug::, ::warning::, ::error:: and ::add-mask:: lines straight to process.stdout, bypassing vitest's console capture. Under GitHub Actions the runner parses them as workflow commands: the test:coverage step of a green build-test run (job 121828647038) contained 61 ##[warning] and 18 ##[error] lines and the check run carried ten failure and ten warning annotations, all test fixtures ("Codertocat is not a org member or collaborator", "status=500"), while ::add-mask::secret-key redacted a fixture string from the rest of the log and setFailed set process.exitCode inside the worker. Locally the same lines were ~3k of the ~12.8k lines a run printed, burying the one genuine warning in the output (a MaxListenersExceededWarning from @mswjs/interceptors in meow.test.ts). A second setup file re-installs a no-op implementation on the output functions before every test (mockReset: true restores the originals), keeping the spies tests assert on while dropping the writes. 191 files / 2473 tests pass unchanged and a full run now prints no :: line. Signed-off-by: quality <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- __tests__/setupQuietActionsCore.ts | 32 ++++++++++++++++++++++++++++++ vitest.config.mjs | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 __tests__/setupQuietActionsCore.ts diff --git a/__tests__/setupQuietActionsCore.ts b/__tests__/setupQuietActionsCore.ts new file mode 100644 index 00000000..53136ee7 --- /dev/null +++ b/__tests__/setupQuietActionsCore.ts @@ -0,0 +1,32 @@ +import * as core from '@actions/core' +import { beforeEach, vi } from 'vitest' + +// setup.ts mocks @actions/core with `spy: true`, so the real implementation still runs and +// its output functions write `::debug::`, `::warning::`, `::error::` and `::add-mask::` +// workflow commands straight to process.stdout (bypassing vitest's console capture). +// Under GitHub Actions the runner parses those lines: a green build-test run carried ten +// `failure` and ten `warning` annotations that were test fixtures, `::add-mask::` redacted +// fixture strings from the rest of the log, and `setFailed` set process.exitCode in the +// worker. Keep the spies — tests assert on the calls — but drop the writes. The +// implementation is reinstalled per test because `mockReset: true` restores the originals. +const outputFunctions = [ + 'debug', + 'info', + 'warning', + 'error', + 'notice', + 'setFailed', + 'setSecret', + 'setOutput', + 'exportVariable', + 'addPath', + 'saveState', + 'startGroup', + 'endGroup', + 'setCommandEcho', +] as const + +beforeEach(() => { + for (const name of outputFunctions) + vi.mocked(core[name]).mockImplementation(() => {}) +}) diff --git a/vitest.config.mjs b/vitest.config.mjs index ea259fb1..18590951 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -5,7 +5,7 @@ export default defineConfig({ environment: 'node', include: ['__tests__/**/*.test.ts'], globals: false, - setupFiles: ['__tests__/setup.ts'], + setupFiles: ['__tests__/setup.ts', '__tests__/setupQuietActionsCore.ts'], // Mirrors Jest's `clearMocks: true` + `resetMocks: true` + `restoreMocks: true`. // Note: Vitest's mockReset restores a spy's original implementation (Jest 29 // reset it to return undefined); the suite passes identically under both semantics.