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
11 changes: 11 additions & 0 deletions .claude/skills/reportportal/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ go test -json ./... | gorp report test2json --quality-gate-check
| `--rerun-of` | | `LAUNCH_RERUN_OF` | | UUID of the launch to rerun; implies `--rerun`. The printed UUID is the one the server returns (the original launch's, RP 5.13.5+) |
| `--launch-uuid` | | | | Report into an existing launch (sharded CI). The launch is looked up first (unknown UUID fails, retried for 10 s), and is neither started nor finished, also not on interrupt. Rejects `--rerun`, `--rerun-of` and `--quality-gate-check`; ignores `--launchName`, `--attr`, `--description`, `--mode`. No env var. The test events must not be older than the launch. |
| `--skipped-issue` | | `SKIPPED_ISSUE` | `true` | Skipped tests are "To Investigate" (`true`) or "No Defect" (`false`) |
| `--retries` | | `REPORT_RETRIES` | `true` | A test that runs again in the same input (`go test -count=N`, `gotestsum --rerun-fails`) is a retry of its previous run; `false` reports every run as its own item |
| `--print-launch-uuid` | | | `false` | Print the launch UUID and link after reporting completes |
| `--quality-gate-check` | `-qgc` | `QUALITY_GATE_CHECK` | `false` | Poll the quality gate after reporting; exits **10** on non-`PASSED` status |
| `--quality-gate-timeout` | `-qgt` | `QUALITY_GATE_TIMEOUT` | `1m` | Shared with `quality-gate check` |
Expand All @@ -257,6 +258,16 @@ 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>`).

### Repeated runs (retries)

With `go test -count=N` or `gotestsum --rerun-fails --jsonfile` a test runs several times in one stream. Each
further run of a test without subtests is sent with `retry=true` and `retryOf` = the UUID of the run before it
(always the latest one), so ReportPortal counts the test case once, with the status of its last run; earlier runs
are its retries. Tests with subtests and package suites are containers: they are reported once, reused and
finished again by every run. The launch is `FAILED` when the last run of a test or package failed (`-count=N`
with a failed run: `FAILED`; gotestsum rerun that passes: `PASSED`). Statistics differ from older gorp versions,
where `-count=3` of 10 tests gave `total 30` instead of `total 10`; `--retries=false` restores that.

### Build failures

A package that fails to build (or fails `go vet`) is reported as a `FAILED` `SUITE` without test items. With
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ The suite skips itself when no credentials are configured.
- `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.
- `report test2json` reports a test that runs again in the same stream (`go test -count=N`, `gotestsum --rerun-fails`) as a ReportPortal retry (`--retries`, default on; see `startTest` in `reporter.go`). `retryOf` must be the UUID of the **latest** run: the server skips a `retryOf` that points to an item which is itself a retry, and the run then becomes one more counted item. Tests with subtests and suites are never retried; their item is reused (`reopen`) and finished again, which the server allows for items with children. Fixtures in `internal/commands/testdata/retries/` are real `go test`/gotestsum output.
- `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.
- Generated types use long fully-qualified names (`ComEpamReportportal...`); short names (`StartLaunchRQ`, `PageMetadata`, …) are type aliases kept for backward compatibility in `scripts/openapi-compat/compat.go.tmpl`, which `task generate-openapi-client` copies to `pkg/openapi/compat.go`. If a regenerated spec renames a type, `go build` fails in `compat.go` — fix the template. An alias must point to the type with the same meaning, not just one that compiles: e.g. `LaunchResource` is the reporting model, while launch list/get endpoints return `LaunchViewModel` / `PageLaunchViewModel`.

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ go test -json ./... | gorp report test2json --quality-gate-check
| `--launch-uuid` | | | | Report into this existing launch instead of starting one. See [Reporting into an existing launch](#reporting-into-an-existing-launch). |
| `--reportEmptyPkg` | `--ep` | `REPORT_EMPTY_PKG` | `false` | Report packages with no test files |
| `--skipped-issue` | | `SKIPPED_ISSUE` | `true` | Whether skipped tests are "To Investigate" (`true`, ReportPortal's default) or "No Defect" (`false`) |
| `--retries` | | `REPORT_RETRIES` | `true` | Report a test that runs again in the same input as a retry of its previous run. See [Repeated runs](#repeated-runs-retries). |
| `--print-launch-uuid` | | | `false` | Print `ReportPortal Launch UUID: <uuid>` and `ReportPortal Launch: <url>` to stdout after reporting |
| `--quality-gate-check` | `--qgc` | `QUALITY_GATE_CHECK` | `false` | Poll for quality gate result after reporting; exits `10` on failure |
| `--quality-gate-timeout` | `--qgt` | `QUALITY_GATE_TIMEOUT` | `1m` | Maximum time to wait for quality gate |
Expand All @@ -264,6 +265,24 @@ it, each with the same log. Such a suite has no test items, so it does not show
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.

#### Repeated runs (retries)

A test can run more than once in one input: `go test -count=N` runs every test N times, and
`gotestsum --rerun-fails --jsonfile` appends the reruns of the failed tests. Such runs are reported as ReportPortal
**retries**: the test case is one item with the result of its **last** run, and the earlier runs are kept as its
retries (with their logs).

- A test without subtests is a retry of its previous run. A test with subtests, like the package's suite, is a
container that is not counted itself: it is reported once and finished again by every run, and its subtests are
the retries. Subtests that do not run again (gotestsum reruns only the failed ones) stay as they are.
- The launch is `FAILED` when the last run of a test or of a package failed. For `go test -count=N` a failed run
fails the package, so the launch is `FAILED` although the last run of every test may have passed. For gotestsum a
rerun that passes makes the package pass, so the launch is `PASSED`, like gotestsum's own exit code.
- **This changes the statistics for `-count=N`.** Before, every run was a separate item: `-count=3` of 10 tests
gave `total 30`. Now it gives `total 10`, each with two retries, and a test that failed in an earlier run and
passed in the last one is counted as passed. To find flaky tests, look for items with retries; to count every
run as before, use `--retries=false`.

**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 Expand Up @@ -594,6 +613,7 @@ all, err := client.GetAllLaunchesByFilterString(ctx, "my_project",
| `LAUNCH_RERUN` | `--rerun` | `report test2json`: rerun the latest launch with the same name |
| `LAUNCH_RERUN_OF` | `--rerun-of` | `report test2json`: UUID of the launch to rerun |
| `REPORT_EMPTY_PKG` | `--reportEmptyPkg` | Report packages with no tests |
| `REPORT_RETRIES` | `--retries` | `report test2json`: repeated runs of a test are retries (`true`) or separate items (`false`) |
| `SKIPPED_ISSUE` | `--skipped-issue` | Skipped tests are "To Investigate" (`true`) or "No Defect" (`false`) |
| `QUALITY_GATE_CHECK` | `--quality-gate-check` | Enable quality gate check after report |
| `QUALITY_GATE_TIMEOUT` | `--quality-gate-timeout` | Quality gate poll timeout (e.g. `2m`) |
Expand Down
5 changes: 5 additions & 0 deletions e2e/e2e_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ type (
Status string `json:"status"`
CodeRef string `json:"codeRef"`
Parent int64 `json:"parent"`
// Retries are the earlier runs of the item; they are not listed as items themselves
Retries []struct {
ID int64 `json:"id"`
Status string `json:"status"`
} `json:"retries"`
}
logEntry struct {
Message string `json:"message"`
Expand Down
145 changes: 145 additions & 0 deletions e2e/retries_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
//go:build e2e

package e2e

import (
"path/filepath"
"testing"

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

"github.com/reportportal/goRP/v5/pkg/openapi"
)

// The fixtures are real streams, see internal/commands/report_retries_test.go: in the package "flaky"
// TestFlaky and TestTable/flaky fail on their first run and pass on the second.
func retriesFixture(name string) string {
return filepath.Join("..", "internal", "commands", "testdata", "retries", name)
}

func withExecutions(l *openapi.LaunchViewModel) bool {
return finished(l) && l.GetStatistics().Executions != nil
}

func retryStatuses(item *testItem) []string {
statuses := []string{}
for _, r := range item.Retries {
statuses = append(statuses, r.Status)
}

return statuses
}

// `go test -count=2`: the second run of a test is a retry of the first, so ReportPortal counts every
// test case once, with the result of its last run.
func TestReportTest2JSON_CountRunsAreRetries(t *testing.T) {
e := newEnv(t)
name := uniqueName(t)

runGorp(
t,
"report",
"test2json",
"--file",
retriesFixture("count2.jsonl"),
"--launchName",
name,
).
requireOK(t)

launch := e.findLaunch(t, name, withExecutions)
executions := *launch.GetStatistics().Executions
assert.Equal(
t,
int32(6),
executions["total"],
"six test cases ran twice each: TestFlaky, TestStable, TestTable/ok, TestTable/flaky, TestParallel, TestFine",
)
assert.Equal(t, int32(6), executions["passed"], "the last run of every test passed")
assert.Zero(t, executions["failed"])
assert.True(t, launch.GetHasRetries())
assert.Equal(t, "FAILED", launch.GetStatus(),
"go test fails a package when one of the runs failed, and so does the launch")

// two suites, TestFlaky, TestStable, TestTable with two subtests, TestParallel, TestFine;
// the first runs are not items of their own anymore
items := e.items(t, launch.Id, 9)
assert.Equal(t, "PASSED", items["TestFlaky"].Status)
assert.Equal(t, []string{"FAILED"}, retryStatuses(items["TestFlaky"]))
assert.Equal(t, []string{"PASSED"}, retryStatuses(items["TestStable"]))
assert.Equal(t, []string{"FAILED"}, retryStatuses(items["flaky"]))
assert.Equal(t, []string{"PASSED"}, retryStatuses(items["ok"]))
assert.Equal(t, []string{"PASSED"}, retryStatuses(items["TestFine"]))

// a test with subtests is reused, not retried: its subtests are the retries
table := items["TestTable"]
assert.Empty(t, table.Retries)
assert.Equal(t, "PASSED", table.Status, "finished again with the status of its last run")
assert.Equal(t, table.ID, items["flaky"].Parent)
assert.Equal(t, table.ID, items["ok"].Parent)
assert.Equal(t, "FAILED", items["example.com/retries/flaky"].Status)
}

// `gotestsum --rerun-fails` runs the package again for the failed tests only. The reruns are retries,
// the tests that did not run again stay counted, and a run that gotestsum made pass is a passed launch.
func TestReportTest2JSON_GotestsumRerunsAreRetries(t *testing.T) {
e := newEnv(t)
name := uniqueName(t)

runGorp(
t,
"report",
"test2json",
"--file",
retriesFixture("gotestsum.jsonl"),
"--launchName",
name,
).
requireOK(t)

launch := e.findLaunch(t, name, withExecutions)
executions := *launch.GetStatistics().Executions
assert.Equal(t, int32(6), executions["total"])
assert.Equal(t, int32(6), executions["passed"])
assert.Zero(t, executions["failed"])
assert.True(t, launch.GetHasRetries())
assert.Equal(t, "PASSED", launch.GetStatus())

items := e.items(t, launch.Id, 9)
assert.Equal(t, []string{"FAILED"}, retryStatuses(items["TestFlaky"]))
assert.Equal(t, []string{"FAILED"}, retryStatuses(items["flaky"]))
for _, once := range []string{"TestStable", "TestParallel", "ok", "TestFine"} {
require.NotNil(t, items[once], once)
assert.Empty(t, items[once].Retries, once)
assert.Equal(t, "PASSED", items[once].Status, once)
}
assert.Equal(t, "PASSED", items["TestTable"].Status)
assert.Equal(t, "PASSED", items["example.com/retries/flaky"].Status,
"the suite is finished again by every run of the package")
}

// --retries=false keeps every run as a test item of its own.
func TestReportTest2JSON_RetriesDisabled(t *testing.T) {
e := newEnv(t)
name := uniqueName(t)

runGorp(
t,
"report",
"test2json",
"--file",
retriesFixture("count2.jsonl"),
"--launchName",
name,
"--retries=false",
).requireOK(t)

launch := e.findLaunch(t, name, withExecutions)
executions := *launch.GetStatistics().Executions
assert.Equal(t, int32(12), executions["total"], "six test cases, two runs each")
assert.Equal(t, int32(10), executions["passed"])
assert.Equal(t, int32(2), executions["failed"])
assert.False(t, launch.GetHasRetries())
assert.Equal(t, "FAILED", launch.GetStatus())
}
1 change: 1 addition & 0 deletions internal/commands/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func test2jsonCmd(host, file string, extra ...cli.Flag) (*cli.Command, *bytes.Bu
&cli.StringSliceFlag{Name: "attr"},
&cli.BoolFlag{Name: "skipped-issue", Value: true},
&cli.BoolFlag{Name: "print-launch-uuid", Value: true},
&cli.BoolFlag{Name: "retries", Value: true},
)

return &cli.Command{Flags: append(flags, extra...), Writer: &out}, &out
Expand Down
10 changes: 10 additions & 0 deletions internal/commands/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ var (
Sources: cli.EnvVars("SKIPPED_ISSUE"),
Value: true,
},
&cli.BoolFlag{
Name: "retries",
Usage: "Report a test that runs again in the same input (go test -count=N, gotestsum --rerun-fails) " +
"as a retry of its previous run: only the last run is counted. " +
"With false every run is a test item of its own",
Sources: cli.EnvVars("REPORT_RETRIES"),
Value: true,
},
&cli.BoolFlag{
Name: "print-launch-uuid",
Usage: "Print launch UUID and link to console",
Expand Down Expand Up @@ -192,6 +200,8 @@ func reportLaunch(
rerun: cmd.Bool("rerun"),
rerunOf: cmd.String("rerun-of"),
joined: joined,
// a command without the flag (tests) reports every run on its own, as before the flag existed
retries: cmd.Bool("retries"),
})

// start reporting in a separate goroutine.
Expand Down
21 changes: 16 additions & 5 deletions internal/commands/report_hierarchy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ type recordedItem struct {
// hierarchyServer is a ReportPortal fake that gives every started item its own ID and records the
// requests, so tests can check the reported hierarchy and request bodies.
type hierarchyServer struct {
mu sync.Mutex
items []recordedItem
finishes map[string]map[string]any // item ID -> finish body
launchStart map[string]any
mu sync.Mutex
items []recordedItem
finishes map[string]map[string]any // item ID -> finish body
// finishStatuses are the statuses an item was finished with, in order (a reused item is finished
// more than once)
finishStatuses map[string][]string
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
Expand All @@ -37,7 +40,10 @@ type hierarchyServer struct {

func newHierarchyServer(t *testing.T, project string) (*hierarchyServer, *httptest.Server) {
t.Helper()
rec := &hierarchyServer{finishes: map[string]map[string]any{}}
rec := &hierarchyServer{
finishes: map[string]map[string]any{},
finishStatuses: map[string][]string{},
}
decode := func(r *http.Request) map[string]any {
var body map[string]any
require.NoError(t, json.NewDecoder(r.Body).Decode(&body))
Expand Down Expand Up @@ -85,6 +91,11 @@ func newHierarchyServer(t *testing.T, project string) (*hierarchyServer, *httpte
body := decode(r)
rec.mu.Lock()
rec.finishes[r.PathValue("id")] = body
status, _ := body["status"].(string)
rec.finishStatuses[r.PathValue("id")] = append(
rec.finishStatuses[r.PathValue("id")],
status,
)
rec.mu.Unlock()
reply(w, map[string]string{"message": "finished"})
},
Expand Down
Loading