Skip to content

report test2json: report packages that fail to build - #44

Open
DzmitryHumianiuk wants to merge 2 commits into
feat/test2json-launch-uuidfrom
feat/test2json-build-failures
Open

DzmitryHumianiuk wants to merge 2 commits into
feat/test2json-launch-uuidfrom
feat/test2json-build-failures

Conversation

@DzmitryHumianiuk

Copy link
Copy Markdown
Member

Summary

Part of #26 (slice C4). Stacked on C3 (feat/test2json-launch-uuid) → C2 → #29. The change itself only needs #29.

Since Go 1.24, go test -json writes the go command's build events into the same stream as the test events.
report test2json did not know them. Two things went wrong with a real stream of a package that does not compile:

  1. The launch started at year 0001. Build events have no Time, and the first event of the stream starts the
    launch. Observed on the demo server with the binary of the base branch: "startTime":"0001-12-30T00:00:00Z".
  2. The failed package was not reported. It has no test, so no suite was started and its fail event was
    ignored. The launch was FAILED with nothing in it that failed, and the compiler output was dropped.

Changes

  • testEvent gets ImportPath. build-output and build-fail events are recognised (isBuildEvent); they never
    start the launch and never move the time the launch is finished with.
  • The output of each build is kept by ImportPath.
  • A package fail event with FailedBuild:
    • starts the package's suite if there is none (also without --reportEmptyPkg),
    • adds the output of the build named by FailedBuild as one ERROR log on the suite, stamped with the time
      of the fail event,
    • finishes the suite as FAILED. The launch is FAILED, as before.
  • One broken dependency fails every package that imports it; each of those suites gets the dependency's output.
  • If the stream has no output for the failed build (Go before 1.24 prints it to stderr), the suite is still
    reported as FAILED and a warning is logged.
  • Fixtures internal/commands/testdata/buildfail/*.jsonl: unedited stdout of go test -json, go1.27.4.
  • hierarchyServer (test fake) now records log entries and the launch finish body.
  • README, skill, and the FailedBuild note in AGENTS.md (which said it was a Go 1.27 field and not acted on).

Behaviour change

  • A package that fails to build now appears as a FAILED suite with an ERROR log. Before it did not appear.
  • The launch start time of such a run is the time of the first test event instead of year 0001.
  • Not changed: the FAIL\t<package> [build failed] line of the test output is still a launch-level log when the
    suite does not exist yet at that point (without --reportEmptyPkg), like any package output without a suite.
  • Statistics: the failed suite has no STEP items, so the launch's executions (total/passed/failed) do not count
    it. The launch status is FAILED.

Verification

  • go build ./... && go vet ./... && go test -race ./...: ok. Lint (run ./..., run --build-tags e2e ./e2e/...):
    0 issues.
  • Unit: TestReportLaunch_BuildFailures runs the three real streams (and mixed.jsonl with --reportEmptyPkg):
    suite type, FAILED status, the exact log text, number of items, launch FAILED, launch start and end time
    from 2026 (not the zero time). TestReportLaunch_BuildFailureWithoutBuildOutput covers a pre-1.24 stream.
  • Live, ReportPortal 6.0.0 (demo), scratchpad/wave/live-c4.sh, log scratchpad/wave/live/c4.log, same file
    mixed.jsonl:
    • before (binary of the C2 branch): launch startTime 0001-12-30T00:00:00Z, items: only …/ok and TestOne.
    • after: startTime 2026-11-27T22:38:27.286697Z; suites …/brokentest, …/usea, …/useb FAILED, …/ok
      PASSED; error logs on the three failed suites with the compiler output (undefined: three, …;
      # example.com/buildfail/dep on both usea and useb). Executions: total 1, passed 1.
  • e2e: go test -tags e2e -count=1 -v -run BuildFailure ./e2e/... → PASS TestReportTest2JSON_BuildFailure (3.46s).

Investigation log

  1. The stream format, from the toolchain rather than from release notes: go help buildjson (struct
    BuildEvent{ImportPath, Action, Output}, actions build-output / build-fail, "does not match
    TestEvent.Package") and go doc cmd/test2json ("The FailedBuild field is set for Action == "fail" if the test
    failure was caused by a build failure … matches … BuildEvent.ImportPath").
  2. Real output: scratchpad/wave/mkbuildfail.sh builds a module with brokentest (test file does not compile),
    dep (does not compile) imported by usea and useb, ok, and vetfail (fails go vet), and records
    go test -json for several package sets into scratchpad/wave/buildfail/out/. What the streams show:
    • build events come first, before any timed event, and carry no Time and no Package;
    • ImportPath of a test build is pkg [pkg.test], of a dependency just pkg;
    • the failed package then gets start, one output (FAIL\tpkg [build failed]), and fail with
      "Elapsed":0,"FailedBuild":"<ImportPath>"; no run event;
    • usea and useb both name example.com/buildfail/dep;
    • a vet failure looks the same (FailedBuild = the test build).
  3. Why the launch started at year 0001: receive() in internal/commands/reporter.go started the launch with
    ev.Time of the first event of any kind and overwrote the end time on every event. Confirmed live (see above).
  4. Why the package was missing: finishSuite returned early when no suite exists and --reportEmptyPkg is off.
  5. One log entry instead of one per line: the build output of a package is one compiler report; the events split
    it by line only. The entry gets the fail event's time because build events have none.
  6. Cached test results still carry Time (checked by running go test -json ./ok/ twice), so build events are
    the only events without one.

Not verified

  • How the ReportPortal UI shows a suite that has logs but no child items.
  • Go 1.24-1.26 streams: the fixtures are from go1.27.4 only. The build-event format is documented as stable in
    go help buildjson, but was not captured with an older toolchain.
  • Build output that no package fail refers to (for example warnings of a successful build) is kept in memory
    and not reported. No real stream with such output was produced.

🤖 Generated with Claude Code

Since Go 1.24 'go test -json' puts the build events of the go command
into the stream: build-output and build-fail, with an ImportPath and
without Time or Package, and the package's fail event names the failed
build in FailedBuild. The reporter treated them as test events: the first
one started the launch at the zero time, and the failed package was not
reported at all, since it has no test.

Build output is now kept per ImportPath. A package that fails with
FailedBuild is reported as a FAILED suite with the output of that build
as one ERROR log. Build events neither start the launch nor move its end
time. The fixtures are unedited 'go test -json' output of go1.27.4.

Part of #26.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants