Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .claude/skills/reportportal/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ counted once (a test with subtests is not counted itself). `t.Skip` tests are `S
"To Investigate" unless `--skipped-issue=false`. The launch gets the system attributes `agent`, `os`, `go`
and `skippedIssue`. With `--print-launch-uuid` the launch link is printed as well (`ReportPortal Launch: <url>`).

### Build failures

A package that fails to build (or fails `go vet`) is reported as a `FAILED` `SUITE` without test items. With
Go 1.24+ the compiler output is in the stream (`build-output` events, referenced by `FailedBuild` of the
package's `fail` event) and becomes one `ERROR` log of that suite. Such suites do not count in the launch's
execution statistics. Before Go 1.24 the build output is on stderr: pipe only stdout and it is lost.

### Go 1.27+ output handling

Starting with Go 1.27, `go test -json` annotates `"action":"output"` events with an `OutputType`
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ The suite skips itself when no credentials are configured.
- Quality gate polling uses a ticker (`time.NewTicker`) — the channel must be selected on, never `default`. The caller's `ctx` must be forwarded into each poll iteration. A failed/non-PASSED quality gate exits with **exit code 10** (`cli.Exit(..., 10)` in `quality_gate.go`); this is depended on by CI pipelines — do not change it casually.
- Log batch goroutines inside the `test2json` reporter are managed with `errgroup.Group` (not `sync.WaitGroup`). Errors surface at `errGroup.Wait()` in `receive()`.
- `pkg/openapi/` is regenerated from `openapi-modified.json`. `openapi-modified.json` is a git-ignored derived file: never edit it, change `reportportal-api-docs.json` or `scripts/openapi-preprocess.jq` instead.
- `report test2json` parses `go test -json` output (see `internal/commands/reporter.go`'s `testEvent` struct). As of **Go 1.27**, `test2json` annotates `"action":"output"` events with an `OutputType` field (`"frame"`, `"error"`, `"error-continue"`, or blank) and `"action":"fail"` events with `FailedBuild` when the failure was a build failure. The repo's `testEvent` struct captures both fields; `logLevelForOutputType` promotes `error`/`error-continue` output to `ERROR`-level RP logs, and `shouldMergeOutput` merges `error-continue` (or, for pre-1.27 streams with no `OutputType`, tab-indented) chunks into the previous log entry. `FailedBuild` is parsed but not currently acted on. See `reporter.go` and `report_log_test.go` for the full logic and test coverage. **Note:** despite the pre-existing fields (`time`, `action`, etc.) being tagged with lowercase `json:"..."` names while `OutputType`/`FailedBuild` use exact-case tags, `encoding/json.Unmarshal`'s case-insensitive fallback makes both work correctly against the real (PascalCase) `go test -json` wire format — this is a cosmetic inconsistency, not a bug.
- `report test2json` parses `go test -json` output (see `internal/commands/reporter.go`'s `testEvent` struct). As of **Go 1.27**, `test2json` annotates `"action":"output"` events with an `OutputType` field (`"frame"`, `"error"`, `"error-continue"`, or blank) and (since Go 1.24) `"action":"fail"` events with `FailedBuild` when the failure was a build failure. Since Go 1.24 the stream also contains the go command's own build events (`"Action":"build-output"` / `"build-fail"`, with `ImportPath` and **no `Time` or `Package`**): they must never start the launch or move its end time. The repo's `testEvent` struct captures both fields; `logLevelForOutputType` promotes `error`/`error-continue` output to `ERROR`-level RP logs, and `shouldMergeOutput` merges `error-continue` (or, for pre-1.27 streams with no `OutputType`, tab-indented) chunks into the previous log entry. Build output is buffered per `ImportPath`; a package `fail` with `FailedBuild` reports its suite as `FAILED` with that output as one `ERROR` log (`logBuildFailure`). Fixtures in `internal/commands/testdata/buildfail/` are real `go test -json` output. See `reporter.go` and `report_log_test.go` for the full logic and test coverage. **Note:** despite the pre-existing fields (`time`, `action`, etc.) being tagged with lowercase `json:"..."` names while `OutputType`/`FailedBuild` use exact-case tags, `encoding/json.Unmarshal`'s case-insensitive fallback makes both work correctly against the real (PascalCase) `go test -json` wire format — this is a cosmetic inconsistency, not a bug.
- `report test2json` reports tests as `STEP` items (subtests nested under their parent `STEP`), not `TEST`: ReportPortal counts execution statistics and assigns "To Investigate" only for `STEP` items without children. Don't switch them back to `TEST`.
- `ReportingClient.SaveLog` sends a one-entry multipart batch: a plain JSON body on `/log` is deprecated in ReportPortal 6.x.
- `Statuses.Canceled` (Go identifier, American spelling) serializes to the string `"CANCELLED"` (British spelling, matching the ReportPortal API) — don't "fix" the string value to match the identifier.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ The launch finishes as `FAILED` if any test or package failed, otherwise `PASSED
(Ctrl-C, `SIGTERM`) or the input stream breaks midway, items that are still running are finished as `INTERRUPTED`,
followed by the launch, so nothing is left `IN_PROGRESS`. A second Ctrl-C terminates immediately.

**Build failures.** A package that does not compile (or fails `go vet`) runs no test. With Go 1.24 or later,
`go test -json` puts the compiler output into the stream; the package is then reported as a `FAILED` suite with
that output as one `ERROR` log, and the launch is `FAILED`. A broken dependency fails every package that imports
it, each with the same log. Such a suite has no test items, so it does not show up in the launch's
total/passed/failed numbers. With older Go versions the build output goes to stderr, which gorp does not see: the
suite is reported as `FAILED` without the log.

**Reruns.** `--rerun` reports into the latest launch with the same `--launchName`, `--rerun-of <uuid>`
into that launch whatever its name. ReportPortal then updates the tests that are reported again, adds the new
ones and finishes the launch with the new status. If there is no launch to rerun, the server answers 404 and the
Expand Down
56 changes: 56 additions & 0 deletions e2e/buildfail_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//go:build e2e

package e2e

import (
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// A package that does not compile runs no test, so its failure exists only as build output: the suite
// must be reported as FAILED with that output. The stream is real `go test -json` output, whose build
// events come first and have no time.
func TestReportTest2JSON_BuildFailure(t *testing.T) {
e := newEnv(t)
name := uniqueName(t)
input := filepath.Join(
"..",
"internal",
"commands",
"testdata",
"buildfail",
"brokentest.jsonl",
)

runGorp(t, "report", "test2json", "--file", input, "--launchName", name).requireOK(t)

launch := e.findLaunch(t, name, finished)
assert.Equal(t, "FAILED", launch.GetStatus())
assert.Equal(
t,
2026,
launch.StartTime.Year(),
"build events have no time and must not start the launch",
)

items := e.items(t, launch.Id, 1)
suite := items["example.com/buildfail/brokentest"]
require.NotNil(t, suite)
assert.Equal(t, "SUITE", suite.Type)
assert.Equal(t, "FAILED", suite.Status)

var buildLog *logEntry
logs := e.logs(t, launch.Id, 1)
for i := range logs {
if logs[i].ItemID == suite.ID && strings.EqualFold(logs[i].Level, "ERROR") {
buildLog = &logs[i]
}
}
require.NotNil(t, buildLog, "the build output must be an ERROR log of the suite: %+v", logs)
assert.Contains(t, buildLog.Message, "brokentest/add_test.go:6:18: undefined: three")
assert.Contains(t, buildLog.Message, "declared and not used: unused")
}
151 changes: 151 additions & 0 deletions internal/commands/report_buildfail_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package commands

import (
"path/filepath"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// The streams in testdata/buildfail are the unedited stdout of `go test -json` (go1.27.4) for a module
// with a package whose test file does not compile (brokentest), a package that does not compile and is
// imported by two others (dep, usea, useb), a package that passes (ok) and one that fails `go vet`
// (vetfail):
//
// mixed.jsonl go test -json ./ok/... ./brokentest/... ./usea/... ./useb/...
// brokentest.jsonl go test -json ./brokentest/...
// vet.jsonl go test -json ./vetfail/...
func buildFailFixture(name string) string {
return filepath.Join("testdata", "buildfail", name)
}

// suiteErrorLogs returns the ERROR logs of the suite, as "LEVEL message". (With --reportEmptyPkg the
// suite also has the "FAIL <package> [build failed]" line of the test output as an INFO log; without
// it that line is a log of the launch, since the suite does not exist yet when it arrives.)
func (rec *hierarchyServer) suiteErrorLogs(t *testing.T, suite string) []string {
t.Helper()
id := rec.item(t, suite).ID
rec.mu.Lock()
defer rec.mu.Unlock()
var logs []string
for _, l := range rec.logs {
if l["itemUuid"] == id && l["level"] == "ERROR" {
logs = append(logs, l["level"].(string)+" "+l["message"].(string))
}
}
return logs
}

func TestReportLaunch_BuildFailures(t *testing.T) {
t.Parallel()

const (
pkg = "example.com/buildfail/"
brokenTestLogs = "ERROR # example.com/buildfail/brokentest [example.com/buildfail/brokentest.test]\n" +
"brokentest/add_test.go:6:18: undefined: three\n" +
"brokentest/add_test.go:9:6: declared and not used: unused\n"
depLogs = "ERROR # example.com/buildfail/dep\ndep/dep.go:3:27: undefined: undefinedThing\n"
)
tests := []struct {
fixture string
reportEmpty bool
// wantFailed are the packages that failed to build, with the log of their suite
wantFailed map[string]string
wantItems int
}{
{
fixture: "mixed.jsonl",
wantFailed: map[string]string{
pkg + "brokentest": brokenTestLogs,
// one broken dependency fails every package that imports it
pkg + "usea": depLogs,
pkg + "useb": depLogs,
},
wantItems: 5, // three failed suites, the suite of the passing package and its test
},
{
fixture: "mixed.jsonl",
reportEmpty: true, // the suites exist already when the packages fail
wantFailed: map[string]string{
pkg + "brokentest": brokenTestLogs,
pkg + "usea": depLogs,
pkg + "useb": depLogs,
},
wantItems: 5,
},
{
// the build events are the first lines of the stream and have no time
fixture: "brokentest.jsonl",
wantFailed: map[string]string{pkg + "brokentest": brokenTestLogs},
wantItems: 1,
},
{
fixture: "vet.jsonl",
wantFailed: map[string]string{
pkg + "vetfail": "ERROR # example.com/buildfail/vetfail\n# [example.com/buildfail/vetfail]\n" +
"vetfail/v_test.go:6:10: (*testing.common).Logf format %d has arg \"not a number\" " +
"of wrong type string\n",
},
wantItems: 1,
},
}
for _, tc := range tests {
t.Run(tc.fixture, func(t *testing.T) {
t.Parallel()

rec, srv := newHierarchyServer(t, "proj")
cfg := &clientConfig{URL: srv.URL, Project: "proj", ApiKey: "tok"}

_, _, err := reportLaunch(
t.Context(), cfg, reportCmd(buildFailFixture(tc.fixture), "launch", tc.reportEmpty),
)
require.NoError(t, err)

for suite, wantLog := range tc.wantFailed {
item := rec.item(t, suite)
assert.Equal(t, "SUITE", item.Body["type"])
assert.Empty(t, item.ParentID)
assert.Equal(t, "FAILED", rec.finishes[item.ID]["status"], suite)
assert.Equal(t, []string{wantLog}, rec.suiteErrorLogs(t, suite), suite)
}
assert.Len(t, rec.items, tc.wantItems)
assert.Equal(t, "FAILED", rec.launchFinish["status"])

// build events have no time: they must not become the start or the end of the launch
for name, body := range map[string]map[string]any{
"launch start": rec.launchStart, "launch finish": rec.launchFinish,
} {
field := "startTime"
if name == "launch finish" {
field = "endTime"
}
at, pErr := time.Parse(time.RFC3339Nano, body[field].(string))
require.NoError(t, pErr)
assert.Equal(t, 2026, at.Year(), "%s time must come from a test event", name)
}
})
}
}

// Before Go 1.24 the build output went to stderr: the stream only has the failed package.
func TestReportLaunch_BuildFailureWithoutBuildOutput(t *testing.T) {
t.Parallel()

rec, srv := newHierarchyServer(t, "proj")
file := writeEventLines(
t,
`{"Time":"2025-01-01T00:00:00Z","Action":"start","Package":"example/pkg"}`,
`{"Time":"2025-01-01T00:00:00Z","Action":"output","Package":"example/pkg","Output":"FAIL\texample/pkg [build failed]\n"}`,
`{"Time":"2025-01-01T00:00:00Z","Action":"fail","Package":"example/pkg","Elapsed":0,"FailedBuild":"example/pkg [example/pkg.test]"}`,
)
cfg := &clientConfig{URL: srv.URL, Project: "proj", ApiKey: "tok"}

_, _, err := reportLaunch(t.Context(), cfg, reportCmd(file, "launch", false))
require.NoError(t, err)

suite := rec.item(t, "example/pkg")
assert.Equal(t, "FAILED", rec.finishes[suite.ID]["status"])
assert.Empty(t, rec.suiteErrorLogs(t, "example/pkg"))
}
16 changes: 14 additions & 2 deletions internal/commands/report_hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ type hierarchyServer struct {
items []recordedItem
finishes map[string]map[string]any // item ID -> finish body
launchStart map[string]any
// launchFinish is the body of the launch finish request
launchFinish map[string]any
// logs are the reported log entries, in the order the batches arrived
logs []map[string]any
}

func newHierarchyServer(t *testing.T, project string) (*hierarchyServer, *httptest.Server) {
Expand All @@ -53,7 +57,10 @@ func newHierarchyServer(t *testing.T, project string) (*hierarchyServer, *httpte
})
mux.HandleFunc(
"PUT /api/v2/"+project+"/launch/launch-1/finish",
func(w http.ResponseWriter, _ *http.Request) {
func(w http.ResponseWriter, r *http.Request) {
rec.mu.Lock()
rec.launchFinish = decode(r)
rec.mu.Unlock()
reply(
w,
map[string]string{"id": "launch-1", "link": "http://rp.example/ui/#launches/all/1"},
Expand Down Expand Up @@ -82,7 +89,12 @@ func newHierarchyServer(t *testing.T, project string) (*hierarchyServer, *httpte
reply(w, map[string]string{"message": "finished"})
},
)
mux.HandleFunc("POST /api/v2/"+project+"/log", func(w http.ResponseWriter, _ *http.Request) {
mux.HandleFunc("POST /api/v2/"+project+"/log", func(w http.ResponseWriter, r *http.Request) {
var batch []map[string]any
require.NoError(t, json.Unmarshal([]byte(r.FormValue("json_request_part")), &batch))
rec.mu.Lock()
rec.logs = append(rec.logs, batch...)
rec.mu.Unlock()
reply(w, map[string]any{"responses": []map[string]string{{"id": "log-1"}}})
})

Expand Down
Loading