Skip to content

fix(pipe): preserve non-JSON Go test reports - #4455

Merged
KuSh merged 20 commits into
rtk-ai:developfrom
yeahjack:fix/go-test-pipe-text
Nov 2, 2026
Merged

KuSh merged 20 commits into
rtk-ai:developfrom
yeahjack:fix/go-test-pipe-text

Conversation

@yeahjack

@yeahjack yeahjack commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Recognize an event-only Go test JSON stream before applying the pipe -f go-test JSON filter
  • Preserve plain text, unrelated/malformed JSON, and mixed text/JSON input in full, including failures after many successful package lines
  • Reuse the existing GoTestEvent schema for recognition; leave the Go runner and its JSON result/fuzz/build parsers unchanged

Closes #4418. This is the plain-text follow-up to merged #1444 and does not change the list/fuzz routing addressed by #4430 / #4437 / #4438.

Spec-driven re-review

Acceptance was derived from #4418, the repository's lossless fallback principle, and Go's event schema before inspecting this implementation.

  • G1: Preserve unsupported input completely. Covered by plain_failure_after_many_successes_is_preserved_in_full, plain_success_empty_and_non_event_json_are_not_misclassified, mixed_json_and_text_keeps_every_line, and the added raw_fallback_preserves_line_endings_and_unterminated_text (CRLF, Unicode, whitespace, no trailing newline).
  • G2: Each nonblank record must have a recognized action and supported event shape before filtering. The new output_shaped_json_without_output_is_not_a_test_report exposed one missed case: an object with Action/Package but no Output lost its diagnostic and became No tests found. It failed on the original PR implementation (6 CLI tests passed, 1 failed). A five-line guard now leaves output/build-output records without their required payload unchanged; all 7 CLI tests pass. Matching wrapper unit cases cover the same boundary.
  • G3: Existing success/failure and build summaries remain unchanged. Covered by valid_json_events_still_use_the_existing_filter, added padded_json_and_build_failures_keep_existing_summaries, and existing Go parser tests. The runner, list/fuzz routing, and renderer are unchanged.

Package-less go tool test2json input is conservatively retained raw; Package is optional in that tool's format, so this is a lossless fallback, not a claim that such JSON is malformed. This recognizer checks individual event shapes, not sequence completeness. pipe cannot recover the upstream command's status. No plain-text parser or new framework is added.

Verification

  • cargo fmt --all --check, cargo clippy --offline --all-targets, and cargo test --offline --all passed: 4,122 tests passed; 8 pre-existing ignored tests were not run
  • The 7 focused built-CLI regression tests passed
  • Original develop baseline loses plain/mixed reports; the missing-payload case fails on the initial PR and passes after the fix
  • Local execution was Linux. No Go language toolchain or local performance benchmark was available; JSON fixtures and the existing parser tests cover Go formatting

CI run 37336140553 passed for fb79b81d570ec3249cc17a66b5a2af0a7baee94f, including Windows/macOS/Linux tests, formatting, clippy, benchmark and security jobs. CLA status passed. The target-branch job is intentionally skipped for the develop base. The optional AI documentation review was skipped because its repository API key is not configured; the job reports success.

The spec-driven self-review has no remaining known in-scope finding. Ready for maintainer review.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working go testing pipe labels Oct 5, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

This PR fixes the rtk pipe -f go-test filter to detect whether stdin is actually a complete Go test JSON event stream before applying the Go test JSON filter, preserving plain text, malformed/unrelated JSON, and mixed text/JSON input unchanged. It adds a new is_go_test_json recognizer reusing the existing GoTestEvent schema, leaving the underlying Go test parser and build/fuzz routing untouched.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4418


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@yeahjack
yeahjack marked this pull request as ready for review October 5, 2026 16:00
@yeahjack
yeahjack force-pushed the fix/go-test-pipe-text branch from 28051d2 to e11a981 Compare October 19, 2026 10:25

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 1 — CHANGES REQUESTED

Claim: rtk pipe -f go-test (and auto-detected Go JSON) passes input that is not a Go test event stream through unchanged instead of reporting Go test: No tests found.
Scope: accept. The plain-text fix for #4418 works as stated; what holds merge is inside the new recognizer.
Ran: real go test from Go 1.24.6 and Go 1.27.1 on a 31-package module, plain and -json, plus go tool test2json and go build -json. Cases: green, failing after 25 ok, build failure, zero tests, t.Attr, -artifacts, parallel/skip/subtest/panic, cold module cache. 27 streams × develop 5538d72 / head d94b031, 20 of them also through auto-detect (rtk pipe without -f). Invariants: split streams (stdout only and 2>&1), under the hook (the hook leaves … | rtk pipe -f go-test as typed, and go test goes to the unchanged runner), every decision. Savings: valid JSON 99–100% on both builds; plain text 0% by design (lossless fallback).
Pins: 12 decisions, 24 mutations, 7 survived (6 allowlist entries: start, output, skip, pause, cont, bench; the empty-name conjunct)
Matrix: executed this round; pin check: executed this round
CI @d94b031: all green (15/15)

Blocks merge (2, frozen at round 1)

  1. src/cmds/go/go_cmd.rs:326 — the recognizer rejects streams that develop summarizes correctly (6 producer shapes, one cause: the all-or-nothing accept set is stricter than what filter_go_test_json already handles). Evidence, each a real captured stream through rtk pipe -f go-test, develop → head:

    • Go ≥1.25, a test calling t.Attr("issue", "4455"), go test -json ./... (emits {"Action":"attr",…,"Key":"issue","Value":"4455"}): Go test: 51 passed in 27 packages → the whole 45,295-byte stream raw.
    • Go ≥1.26, t.ArtifactDir() under go test -json -artifacts (emits "Action":"artifacts"): Go test: 3 passed in 2 packages → raw.
    • go test -c -o s.test ./pkg && go tool test2json -t ./s.test -test.v=test2json (no Package on any event): Go test: 4 passed, 2 failed, 1 skipped in 1 packages + the failures → 4,704 bytes raw.
    • A UTF-8 BOM before the first event (what Windows PowerShell 5.1 Out-File -Encoding utf8 writes): 51 passed, 1 failed in 27 packages → 44,616 bytes raw.
    • go test -json ./... 2>&1 on a cold module cache, where Go writes two go: downloading golang.org/x/text v0.21.0 lines to stderr: Go test: 51 passed in 26 packages → 44,503 bytes raw. One line that isn't an event is enough to turn off the filter for the whole report.
    • A stream cut mid-object (head -c 20050 of a failing run): Go test: 23 passed in 16 packages → 20,050 bytes raw.

    For the last two, the PR's goal of not dropping lines silently and develop's summary are both achievable: the summary plus the non-event lines verbatim keeps every line that isn't an event and still compresses the events. mixed_json_and_text_keeps_every_line currently pins the whole-stream raw output and would change with it.

    In the other direction, within this PR's claim though not a regression: go build -json ./broken (only build-output/build-fail events) is accepted and prints Go test: No tests found, dropping broken/b.go:3:23: undefined: missing. Develop prints the same thing; the PR's G1 says this input should be preserved.
    Test must: run each of these captured streams through pipe -f go-test and assert the summary (for the 2>&1 stream: the summary and both go: downloading lines; for the build-only stream: the compile error is in the output). attr and artifacts are the 1.25 and 1.26 additions to an action set the test2json docs call fixed, so expect another one: a check that accepts only the actions it knows will need updating with each Go release.

  2. src/cmds/go/go_cmd.rs:326 — unpinned behaviour (action allowlist entries). Evidence: removing "start", "output", "skip", "pause", "cont" or "bench" from the match passes the whole suite (pipe_cmd and go_cmd unit tests + go_test_pipe_test). Every real stream begins with start, has output events, and skip for a package with no test files; pause/cont come from t.Parallel. valid_json_events_still_use_the_existing_filter does not catch the missing "output": its fail case falls back to raw, and the raw input also contains TestX and x_test.go:12 and not No tests found. Test must: run a real go test -json ./... stream from a module with a no-test-files package, a t.Parallel pair, and a benchmark that calls b.Log, and assert the exact summary line. Each of the six mutations must turn it red; asserting shown != input in the existing fail case closes the output one.

Optional — will not hold merge

  • go_cmd.rs:311 says "Recognize a complete event stream"; the function checks each line's shape, not completeness (your PR body says so). A stream cut at a line boundary before TestX's fail event still summarizes as 50 passed, same as develop (#4693).
  • go_cmd.rs:332: the name.is_empty() half survives mutation, and no Go producer emits "Package":"" (the field is omitempty). Either drop it or pin it.

Filed as follow-ups

  • #4692 rtk pipe without -f reads plain go test output as find/grep results — pre-existing, outside this PR's hunks; filed.
  • #4693 go test JSON filter reports a cut-off stream as all passed — pre-existing, outside this PR's hunks; filed.

Checked and correct — no need to re-verify

  • Plain text from both Go versions (green, failure after 25 ok lines, build failure on stdout-only and 2>&1, zero tests) comes back byte for byte with exit 0; develop printed Go test: No tests found for every one.
  • Valid -json streams (green, failing, build failure, zero tests on both Go versions; stdout-only cold-cache run; parallel/skip/subtests/panic) give output byte-identical to develop.
  • rtk go test (the runner) is unchanged and unaffected.
  • cargo fmt --check, cargo clippy --all-targets (0 warnings) and cargo test --all (4528 passed) on the head, which already contains the develop tip.

Your questions

None asked.

Next

A recognizer that summarizes the six stream shapes in item 1 (keeping the non-event lines of the last two, and not summarizing away a build-only stream), and a test over real captured streams that kills the six allowlist mutations in item 2.
Rounds: 1. Threads: 2 open (waiting on the author), 0 resolved this round.

Comment thread src/cmds/go/go_cmd.rs Resolved
Comment thread tests/go_test_pipe_test.rs Resolved
@yeahjack

Copy link
Copy Markdown
Contributor Author

At synced head 810ab1f, 13/14 CI checks passed. The only failure is the unchanged CTest test caps_failed_test_entries_with_one_complete_section_tee on Windows MSVC: it expected one recovery hint but got zero. The same test passed in #4456's MSVC job and this PR's Windows GNU job, so this may be intermittent, but the cause is not confirmed.

Could a maintainer rerun just this failed Windows MSVC job once? My attempt returned HTTP 403: "Must have admin rights to Repository."

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2 — CHANGES REQUESTED

Claim: rtk pipe -f go-test (and auto-detected Go JSON) passes input that is not a Go test event stream through unchanged instead of reporting Go test: No tests found.
Scope: accept (round 1, frozen).
Ran: real go test from Go 1.24.6 and Go 1.27.1 on a 33-package module, plain and -json (green, failing, build failure, zero tests, t.Attr, -artifacts, parallel/skip/subtest/panic, benchmarks chatty and -v=false), plus go tool test2json with and without -t, go build -json, and go test -json ./... 2>&1 on a cold module cache. Also derived streams: BOM, CRLF, cut mid-object, cut at a line boundary, two runs concatenated. 33 streams × develop 6c2313a / this head merged onto it, through pipe -f go-test and auto-detect; benchmark rows also on v1.0.1. Invariants: split streams, every decision. Savings on valid JSON 94–100%.
Pins: 20 decisions, 43 mutations, 17 survived the suite; 4 of them change the output on real streams (below), the other 13 change nothing on any of the 33 streams.
Matrix: executed this round @810ab1f7b; pin check: executed this round
CI @810ab1f7b: 1 failing: test (windows-latest), caps_failed_test_entries_with_one_complete_section_tee (left 0, right 1). The test is outside this PR's diff; see your question below.

Both round-1 blockers are fixed: every row of item 1 now summarizes (attr, artifacts, test2json with and without timestamps, BOM, 2>&1 with the go: downloading line kept, mid-object cut with the fragment kept, build-only stream raw), and all nine lifecycle actions are now pinned by the captured-stream tests. Threads resolved.

Blocks merge (2 from round 1, closed; +3 on code added in bd8fc65)

  1. src/cmds/system/pipe_cmd.rs:200 — auto-detect now routes text that quotes Go events into the reducer, which removes those lines. is_go_test_json(input) scans every line, and pipe_event_line trims leading spaces, so one event-shaped line anywhere is enough. Evidence, rtk pipe with no -f, develop → this head:

    • git diff --no-index of tests/fixtures/go_test_pipe/failure.jsonl against a copy with one Elapsed changed: unchanged (1,413 bytes) → 414 bytes, Go test: No tests found on top and all six context lines gone, so the hunk no longer matches its @@ -2,7 +2,7 @@ header.
    • A markdown note quoting three events (run, an output with flaky_test.go:12: got 3, want 4, pass) in a fenced block: unchanged (493 bytes) → 173 bytes, Go test: 1 passed in 1 packages and an empty fence; the quoted diagnostic is gone.

    Fix must: return both inputs unchanged under rtk pipe. Two ways reach that, your call: keep develop's first-line check (drop the is_go_test_json(input) || disjunct; the auto-detect variants of captured_cold_cache_stderr_survives_next_to_the_summary and leading_bom_does_not_disable_a_captured_stream then change with it), or keep the whole-input scan and also keep the cold-cache 2>&1 stream summarized under auto-detect.

  2. src/cmds/go/go_cmd.rs:337 — unpinned behaviour (the key check on package-less records). Each of these passes the whole suite and changes the output of a real go tool test2json -t ./x.test -test.v=test2json stream: removing "Time" from the allowed keys (the start and fail lines are appended raw after the summary), removing "Elapsed" (the fail line), and dropping the && event.output.is_none() conjunct (the {"Action":"output","Output":"FAIL\n","OutputType":"frame"} line). Test must: run the captured package_less.jsonl and package_less_no_time.jsonl through pipe -f go-test and assert the whole output; each of the three mutations must turn it red.

  3. src/cmds/go/go_cmd.rs:422 — unpinned behaviour (consuming build records that a package-level fail represents). Changing index < *fail_index to index < *fail_index && false passes the whole suite, and on a real go test -json build failure the summary becomes broken [build failed] with no error under it while the three build records are appended as raw JSON (105 → 473 bytes). The current assertions hold because the raw JSON also contains undefined: missing. Test must: assert the exact summary of a captured build-failure stream, with broken/b.go:3:23: undefined: missing under broken [build failed] and no JSON after it.

Optional — will not hold merge

  • Two go test -json runs concatenated (a CI retry log): repeated_build_failure clears represented_builds for every package, so each [build failed] block prints without its errors and all build errors follow as raw JSON (106 → 880 bytes; nothing is lost). Clearing only the repeated package would keep the others readable.
  • 13 surviving mutations change nothing on any of the 33 real streams (summary package order aside, which is random between runs on develop too): the ImportPath/Output requirements on build records (unmatched ones end up in the residual either way), each single field in pipe_test_evidence, build events counted as evidence, BOM stripping past line 1, is_go_test_json accepting any supported event, counting test-level fails in repeated_build_failure, passing raw instead of line to the reducer, and the old first-line disjunct in auto-detect. Simplifying them is your call.

Filed as follow-ups

  • #4862 pipe -f go-test drops benchmark results: -v=false -bench gives Go test: No tests found, the chatty run loses its ns/op line. Same on v1.0.1 and develop; #1445 fixed the runner path only.

Checked and correct — no need to re-verify

  • Every valid -json stream from both Go versions gives the same summary as develop; streams develop already handled are byte-identical apart from the residual lines this PR adds on purpose.
  • Plain text from both Go versions (green, failing, build failure, zero tests; stdout only and 2>&1) passes through byte for byte, exit 0.
  • CRLF, an unterminated final fragment and a BOM come back intact in the residual.
  • cargo fmt --check, cargo clippy --all-targets (0 warnings) and cargo test --all (4803 passed) on this head merged onto develop 6c2313a.

Your questions

  • "Could a maintainer rerun just this failed Windows MSVC job once?" → Flagged for a rerun. The failing test is in ctest_cmd, which this PR does not touch, and it passed on this head's Windows GNU job and on the MSVC job of d94b031. I could not reproduce it locally.

Next

Items 1–3 above. Both round-1 blockers are closed.
Rounds: 2. Threads: 3 open (waiting on the author), 2 resolved this round.

Comment thread src/cmds/system/pipe_cmd.rs Resolved
Comment thread src/cmds/go/go_cmd.rs Resolved
Comment thread src/cmds/go/go_cmd.rs Resolved
A cold-cache stream whose first package fails to build opens with a
download line and build records, so auto-detection must keep scanning
to the first test event. Only download lines are skipped before a
stream; other go command output keeps the input verbatim. Both cases
use real Go 1.27.1 captures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 3 — APPROVED

Claim: rtk pipe -f go-test (and auto-detected Go JSON) passes input that is not a Go test event stream through unchanged instead of reporting Go test: No tests found.
Scope: accept (round 1, frozen); maintainer PRs: none overlap.
Ran: real go test from Go 1.27.1 and Go 1.26.1 on 9- and 4-package modules, plain and -json (green, failing, panic, build failure, zero tests, t.Attr, -artifacts, parallel/skip/subtest, benchmarks chatty and -v=false), go test -json ./... 2>&1 on a cold module cache, with text build output (GODEBUG=gotestjsonbuildtext=1), with a -coverpkg warning and with -mod=mod resolution, go tool test2json with and without -t, go build -json. Derived: BOM, CRLF, leading blank lines, an echoed command line before the stream, cut mid-object, cut at a line boundary, two runs concatenated. Text quoting events: a git diff of a captured stream, a markdown note, a patch. 38 inputs × v1.1.0 / develop 22812af / 810ab1f / this head merged onto develop, through pipe -f go-test and auto-detect. Invariants: split streams, every decision. Savings on valid JSON 86–99%.
Pins: 12 decisions (the new auto-detect loop and its caller, plus the four round-2 items), 13 mutations; 2 survived the author's suite and are killed by the tests in 15cf650.
Matrix: executed this round @139618d80; pin check: executed this round
CI: all green on 139618d (15/15); on 15cf650 (fixup) all green (15/15)

All three round-2 blockers are fixed; threads resolved.

Blocks merge (3 from round 2, closed)

  1. src/cmds/system/pipe_cmd.rs:200 — auto-detect on quoted events. Fixed: the git diff and markdown rows come back byte for byte, as on develop, and the cold-cache 2>&1 stream and a BOM-prefixed stream are still summarized under auto-detect. Since 810ab1f only three auto-detect rows changed (the two quoted-text rows, and a stream preceded by an echoed go test command line, now raw as on develop); every -json stream gives the same output as before.
  2. src/cmds/go/go_cmd.rs:337 — package-less key check. Fixed: dropping "Time", dropping "Elapsed" and dropping && event.output.is_none() each turn captured_package_less_test2json_with_and_without_timestamps_is_summarized red.
  3. src/cmds/go/go_cmd.rs:434 — build-record consumption. Fixed: index < *fail_index && false turns captured_build_failure_has_an_exact_summary_without_raw_json red.

Fixup 15cf650 (tests and fixtures only)

Two decisions of the new is_go_test_json loop changed real output without failing a test:

  • continuing past events without test evidence: returning false there leaves a cold-cache go test -json ./... 2>&1 whose first package fails to build completely raw under auto-detect (753 → 18,842 bytes). captured_cold_cache_build_failure_is_summarized_past_its_build_records pins the summary on a real Go 1.27.1 capture.
  • skipping only go: downloading lines: widening it to any go: line summarizes a -mod=mod stream that opens with go: finding module, which this head (like develop and v1.1.0) passes through unchanged. captured_stream_after_other_go_command_output_is_not_auto_detected pins the current behaviour on a real capture, and its -f go-test output.

It also documents the two captures in the fixture README (sources, go.mod, flags) and renames its "Round 2 regression captures" heading to "Build-failure and quoted-input captures". No production code changes.

Filed as follow-ups

  • #4692 (existing) — auto-detect misses go test -json streams with go command output before the first event; with text build output in front, the grep heuristic keeps the compile error and drops the test failures. Same on v1.1.0 and develop; comment added.
  • #4862 pipe -f go-test drops benchmark results — pre-existing; filed at round 2.

Checked and correct — no need to re-verify

  • Every other mutation of the new loop is killed: blank-line skip, the go: downloading skip, stop at the first non-event line, stop at the first event with test evidence, final false, BOM on line 1, and the caller in pipe_cmd.rs.
  • Every valid -json stream from both Go versions gives the same summary as at round 2; plain text passes through byte for byte under -f go-test.
  • cargo fmt --check, cargo clippy --all-targets (0 warnings) and cargo test --all --no-fail-fast (5464 passed, 0 failed) on 15cf650 merged onto develop 22812af.

Next

Fixup 15cf650 pushed, code-reviewed: it adds two tests on real captures and renames a README heading — approving.
Rounds: 3. Threads: 0 open, 3 resolved this round.

@KuSh
KuSh merged commit 2087fe5 into rtk-ai:develop Nov 2, 2026
15 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go pipe testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk pipe -f go-test reports plain-text go test output as "No tests found"

3 participants