Skip to content

test: print server log lines only for failing tests - #788

Merged
aliasunder merged 6 commits into
mainfrom
test/quiet-passing-test-logs
Nov 13, 2026
Merged

aliasunder merged 6 commits into
mainfrom
test/quiet-passing-test-logs

Conversation

@aliasunder

Copy link
Copy Markdown
Owner

What does this PR do?

A test run prints the server's log lines for every test, passing or not. On a recent CI run they were about 4,900 JSON lines, 1.05 MB of the 1.17 MB test log: too long to scroll to a failure, and about 260k tokens for an agent that reads the run's output unfiltered.

The logger writes each line straight to process.stdout or process.stderr, which vitest's console capture never sees. This PR:

  • adds a vitest setup file, src/__tests__/helpers/route-log-lines-to-console.ts, that sends the logger's JSON lines through console.log and console.error, so vitest files each line under the test that wrote it;
  • sets silent: "passed-only", so vitest prints that output only when its test fails;
  • adds one line to AGENTS.md's test conventions: a passing test's output is hidden, and --silent=false shows it.

A test that spies on process.stdout.write replaces the wrapper while its spy is active, so it still captures every line it asserts on. Writes that are not log lines, such as the timing tests' printed medians, pass through unchanged.

Type of change

  • New feature (a tool, a prompt, a setting, a parameter, or a change to what a tool does)
  • Bug fix
  • Refactoring
  • Documentation
  • CI / workflow change
  • Infrastructure (SST, Docker)
  • Other: test tooling

Verification

  • Full suite: 146 files and 8,350 tests pass. Its output is 4,109 bytes over 20 lines, with no log lines; before the change, the same run printed about 1.2 MB.
  • A log-heavy slice (src/vault-mcp/mcp-core and search-index.test.ts, 1,330 tests): 553 KB of output before, 242 bytes after.
  • A throwaway test file with one passing and one failing test, each logging: only the failing test's two lines printed, under stdout | and stderr | headers that name the test.
  • --silent=false on search-index.test.ts printed its 1,098 log lines again.
  • The files whose tests spy on process.stdout.write (logger.test.ts, mcp-router.test.ts) pass.
  • tsc --noEmit, ESLint, knip, markdownlint and Prettier: clean.

Checklist

  • The pre-commit hook passed: typecheck, knip, and ESLint, Prettier, markdownlint and ShellCheck on the staged files
  • npm test passes
  • npm run build succeeds (CI)
  • If this adds a feature, the description links the feature request it came from
  • New MCP tools follow the naming and description conventions in AGENTS.md
  • README or ARCHITECTURE.md updated (if user-facing behavior changed)

🤖 Generated with Claude Code

The logger writes each JSON line straight to process.stdout or
process.stderr, so a test run printed about 4,900 of them, 1.05 MB of a
1.17 MB CI log. A vitest setup file routes those lines through console,
which vitest files under each test, and silent: "passed-only" prints them
only when that test fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@umm-actually

umm-actually Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

umm-actually re-reviewed at 3d479a1

No new findings (5 tracked finding(s) across all runs).


umm-actually · z-ai/glm-5.3-flash

…s on

The setup file recognizes a log line as one string that opens with the
timestamp field, written with no encoding or callback. A logger test now
fails if either changes, so a logger edit cannot silently print every
log line again. Also completes the setup file's garbled sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aliasunder and others added 3 commits November 12, 2026 21:28
- The helper returns the replacement write and the call site assigns it, so
  the function no longer mutates the stream it is given; the original write
  is named originalWrite.
- Comments name src/logger.ts instead of "the server", state why the line is
  trimmed and why write is called in two shapes, say that vitest's console
  never writes to process.stdout, and point to the test that pins the
  logger's write shape.
- The vitest config comment names `silent: "passed-only"` directly, and the
  AGENTS.md bullet gives the exact npm test command.

Ship-Check: code-quality · claude-opus-5-5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The setup file's write wrapper now has its own tests: a log line goes to
the console without its newline and never to the stream, and text that is
not a log line, a log line as bytes, and a log line with an encoding or a
callback all reach the stream with their arguments in place and return the
stream's result. The factory is exported for these tests and takes any
object with a write method.

The logger write-shape test's comment now states the rule the setup file
applies instead of counting facts the test name lists differently.

Ship-Check: test-audit · claude-opus-5-5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AGENTS.md asks for explicit return types on exports, and the factory became
an export when its tests were added.

Ship-Check: triage · claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A test spies on console.log and console.error and writes a log line to
process.stdout and process.stderr, so dropping or miswiring the setup
file's two installation lines fails the suite.

Ship-Check: pr-monitor · claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aliasunder
aliasunder merged commit bbe23f0 into main Nov 13, 2026
18 checks passed
@aliasunder
aliasunder deleted the test/quiet-passing-test-logs branch November 13, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant