Repository navigation
test: print server log lines only for failing tests - #788
Merged
Merged
Conversation
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 re-reviewed at 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>
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.stdoutorprocess.stderr, which vitest's console capture never sees. This PR:src/__tests__/helpers/route-log-lines-to-console.ts, that sends the logger's JSON lines throughconsole.logandconsole.error, so vitest files each line under the test that wrote it;silent: "passed-only", so vitest prints that output only when its test fails;--silent=falseshows it.A test that spies on
process.stdout.writereplaces 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
Verification
src/vault-mcp/mcp-coreandsearch-index.test.ts, 1,330 tests): 553 KB of output before, 242 bytes after.stdout |andstderr |headers that name the test.--silent=falseonsearch-index.test.tsprinted its 1,098 log lines again.process.stdout.write(logger.test.ts,mcp-router.test.ts) pass.tsc --noEmit, ESLint, knip, markdownlint and Prettier: clean.Checklist
npm testpassesnpm run buildsucceeds (CI)🤖 Generated with Claude Code