rtk icon indicating copy to clipboard operation
rtk copied to clipboard

rtk vitest reports a failing run as green: suite-level failures dropped from the summary

Open jensechterling opened this issue 2 months ago • 2 comments

Summary

rtk vitest reports a failing run as fully green. When a test file fails to collect (import error, syntax error, failed top-level beforeAll), vitest counts it as a failed suite, not a failed test. RTK's summary reads only the test counts and ignores the suite counts, so the failure disappears from the output.

The exit code is correct (1), so the run is not silently green — but the human- and LLM-readable summary says FAIL (0), which is the opposite of the truth.

Reproduction

mkdir rtk-vitest-repro && cd rtk-vitest-repro
cat > package.json <<'JSON'
{ "name": "rtk-vitest-repro", "private": true, "type": "module",
  "devDependencies": { "vitest": "^2.1.0" } }
JSON
mkdir test
cat > test/passing.test.js <<'JS'
import { test, expect } from 'vitest'
test('a', () => { expect(1).toBe(1) })
test('b', () => { expect(2).toBe(2) })
JS
cat > test/broken.test.js <<'JS'
import { thing } from './does-not-exist.js'   // fails to collect
import { test } from 'vitest'
test('never runs', () => { thing() })
JS
npm install

Actual vs expected

Test Files Tests Exit
npx vitest run (ground truth) 1 failed | 1 passed (2) 2 passed (2) 1
rtk vitest run not reported PASS (2) FAIL (0) 1
$ rtk vitest run
PASS (2) FAIL (0)
[full output: "$HOME/Library/Application Support/rtk/tee/<ts>_vitest_run.log"]

PASS (2) FAIL (0) reads as a clean green run. The file that failed to collect is absent.

RTK has the correct numbers and drops them

RTK invokes vitest with a JSON reporter. Parsed from the tee log it wrote:

{
  "numTotalTestSuites": 2,
  "numPassedTestSuites": 1,
  "numFailedTestSuites": 1,
  "numTotalTests": 2,
  "numPassedTests": 2,
  "numFailedTests": 0,
  "success": false
}

numFailedTestSuites: 1 and success: false are both present and both ignored. The summary is derived from numPassedTests / numFailedTests only.

Secondary issue: the tee log is not a recovery path here

The tee log contains the raw JSON but not vitest's own Test Files / Tests summary lines (verified: 'Test Files' in log == False). So a user who notices the exit code and opens the log still does not get the readable summary back. For comparison, rtk grep's tee log does contain the full original output, which is the behaviour I'd expect.

Suggested fix

Include suite-level failures in the summary, and prefer the reporter's own success field over a count comparison. Something like:

PASS (2) FAIL (0)  SUITES 1 failed

or simply refuse to print a green-looking summary when success: false.

Why this matters

This is a real, reproducible case where an agent reading RTK's output concludes a test suite passed when it did not. On a real project (45 test files) the same bug rendered Test Files 3 failed | 42 passed as PASS (430) FAIL (0) — three files that never ran, invisible.

Note the contrast with #672 (pytest xfailed shown as failed), which was falsely alarming while its exit code was correct. This one is falsely reassuring, which is the more dangerous direction.

Environment

  • rtk 0.48.0 (Homebrew)
  • macOS 26.4.1, arm64
  • vitest 2.1.x, Node via npx

jensechterling avatar Sep 08 '26 07:09 jensechterling

Still present in rtk 0.51.0 (aarch64-apple-darwin) with vitest 4.1.11 on Node 24.16. A test file with an import that doesn't resolve, next to one passing file:

// broken.test.js
import { test } from 'vitest'
import './does-not-exist.js'
test('never runs', () => {})
$ npx vitest run
 FAIL  broken.test.js [ broken.test.js ]
 Test Files  1 failed | 1 passed (2)
      Tests  1 passed (1)

$ rtk vitest run; echo "exit $?"
PASS (1) FAIL (0)
[full output: ~/…/rtk/tee/…_vitest_run.log]
exit 1

With vitest 5.0.4 the parser falls back to passthrough, so the failure is visible there.

A related case, a coverage threshold failure that renders the same way, is in #4531.

rolfsormo avatar Oct 12 '26 11:10 rolfsormo

Still present in rtk 1.2.0 (Homebrew, aarch64-apple-darwin) with vitest 2.1.9 on Node 24.18. A test file whose import fails to resolve (Failed to resolve entry for package …) shows up in the JSON reporter as numFailedTestSuites: 1, numTotalTests: 0, and rtk vitest run <file> prints PASS (0) FAIL (0). Exit code is correctly 1; the cause is only visible via rtk recall.

moraizin avatar Nov 16 '26 22:11 moraizin