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
13 changes: 11 additions & 2 deletions .claude/skills/reportportal/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,20 @@ go test -json ./... | gorp report test2json --quality-gate-check
| `--launchName` | `-ln` | `LAUNCH_NAME` | `"gorp launch"` | Launch name |
| `--reportEmptyPkg` | `-ep` | `REPORT_EMPTY_PKG` | `false` | Report packages with no test files as a launch item |
| `--attr` | `-a` | | | Launch attribute `key:value` or `value` (repeatable) |
| `--print-launch-uuid` | | | `false` | Print the launch UUID after reporting completes |
| `--skipped-issue` | | `SKIPPED_ISSUE` | `true` | Skipped tests are "To Investigate" (`true`) or "No Defect" (`false`) |
| `--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` |
| `--quality-gate-check-interval` | `-qgci` | `QUALITY_GATE_CHECK_INTERVAL` | `3s` | Shared with `quality-gate check` |

### Reported hierarchy

Each package is a `SUITE`, each test a `STEP`, and each subtest (`t.Run`) a `STEP` nested under its
parent test. ReportPortal counts executions only for `STEP` items without children, so every test case is
counted once (a test with subtests is not counted itself). `t.Skip` tests are `SKIPPED`; they are
"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>`).

### Go 1.27+ output handling

Starting with Go 1.27, `go test -json` annotates `"action":"output"` events with an `OutputType`
Expand All @@ -257,7 +266,7 @@ field: `"frame"` (test framing like `=== RUN`/`--- FAIL:`), `"error"` (first chu
so older Go toolchains still work.

No flags are needed to enable this — it's automatic based on whether the incoming stream has
`OutputType` set. See `internal/commands/report.go` (`logLevelForOutputType`, `shouldMergeOutput`)
`OutputType` set. See `internal/commands/reporter.go` (`logLevelForOutputType`, `shouldMergeOutput`)
and `internal/commands/report_log_test.go` for the exact behavior and test fixtures.

---
Expand Down
10 changes: 7 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ A Go CLI tool (`gorp`) and library (`pkg/gorp`) for [ReportPortal](https://repor
|------|----------|
| `commands.go` | `init`, config loading (`~/.gorp`), client builders (`buildClient`, `buildReportingClient`) |
| `launch.go` | `launch list`, `launch merge` |
| `report.go` | `report test2json` pipeline (test2json event stream → RP); `reporter`/`testEvent` types |
| `report.go` | `report test2json` command: flags, input scanning, feeding events to the reporter |
| `reporter.go` | `reporter`/`testEvent` types: test2json events → launch, `SUITE` per package, `STEP` per test, subtests nested under their parent |
| `report_steps.go` | Atomic report commands: `start-launch`, `start-test`, `log`, `finish-test`, `finish-launch` |
| `quality_gate.go` | `quality-gate check` (polls launch metadata until QG resolves) |
| `util.go` | Shared CLI helpers (config file path, validation, stdin checks) |
Expand All @@ -39,6 +40,7 @@ A Go CLI tool (`gorp`) and library (`pkg/gorp`) for [ReportPortal](https://repor
| `filters.go` | User-filter lookup for launch queries |
| `oauth2.go` | Password-grant token source, `WithPasswordOwnerGrantAuth` |
| `quality_gate.go` | `ParseQualityGate` from launch metadata |
| `attributes.go` | `SystemAttributes` (agent/os/go), `SkippedIssueAttribute`, `NotIssue` |
| `multipart.go` | `Multipart` interface + `FileMultipart`/`ReaderMultipart` |
| `model_api.go`, `model_enums.go` | Hand-written request/response types, `Statuses`, `TestItemTypes`, `LaunchModes`, log levels |

Expand Down Expand Up @@ -121,7 +123,9 @@ 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/report.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 `report.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 `"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` 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.
- 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 All @@ -145,4 +149,4 @@ Before considering a change done:
2. `task test` (or `go test -cover ./...` if Docker/Task aren't available)
3. `task e2e` when the change affects what is sent to ReportPortal (needs credentials, writes to the configured project)
4. `task lint` (or `golangci-lint run ./...` if you have it installed locally with the pinned config)
5. For anything touching `report test2json` / `internal/commands/report.go`: generate real `go test -json` output from the installed Go toolchain and diff its shape against the `testEvent` struct and `report_log_test.go` fixtures rather than relying on release notes alone — Go's JSON stream format is a better source of truth than prose docs.
5. For anything touching `report test2json` / `internal/commands/report.go` / `reporter.go`: generate real `go test -json` output from the installed Go toolchain and diff its shape against the `testEvent` struct and `report_log_test.go` fixtures rather than relying on release notes alone — Go's JSON stream format is a better source of truth than prose docs.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,18 @@ go test -json ./... | gorp report test2json --quality-gate-check
| `--file` | `-f` | `FILE` | stdin | Input file (test2json format). Reads stdin if omitted. |
| `--launchName` | `--ln` | `LAUNCH_NAME` | `gorp launch` | Launch name in ReportPortal |
| `--attr` | `-a` | | | Launch attribute, format `key:value` or `value`. Repeatable. |
| `--reportEmptyPkg` | `--ep` | `REPORT_EMPTY_PKG` | `false` | Report packages with no test cases |
| `--print-launch-uuid` | | | `false` | Print `ReportPortal Launch UUID: <uuid>` to stdout after reporting |
| `--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`) |
| `--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 |
| `--quality-gate-check-interval` | `--qgci` | `QUALITY_GATE_CHECK_INTERVAL` | `3s` | How often to poll for quality gate status |

Each package is a `SUITE`. Each test is a `STEP`, and a subtest (`t.Run`) is a `STEP` nested under its parent test,
so ReportPortal counts every test case once: a test with subtests is not counted itself. Tests skipped with
`t.Skip` are reported as `SKIPPED`. The launch carries the system attributes `agent` (`gorp|<version>`), `os`, `go`
and `skippedIssue`. With `--print-launch-uuid`, the launch link is printed too, as `ReportPortal Launch: <url>`.

The launch finishes as `FAILED` if any test or package failed, otherwise `PASSED`. If the run is interrupted
(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.
Expand Down Expand Up @@ -530,6 +536,7 @@ all, err := client.GetAllLaunchesByFilterString(ctx, "my_project",
| `LAUNCH_NAME` | `--launchName` | Launch name for `report test2json` |
| `FILE` | `--file` | Input file for `report test2json` |
| `REPORT_EMPTY_PKG` | `--reportEmptyPkg` | Report packages with no tests |
| `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`) |
| `QUALITY_GATE_CHECK_INTERVAL` | `--quality-gate-check-interval` | Quality gate poll interval (e.g. `5s`) |
Expand Down
63 changes: 63 additions & 0 deletions e2e/reporting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

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

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

// test2json stream of a package with a passing and a failing test (Go 1.27 OutputType annotations).
Expand Down Expand Up @@ -88,6 +90,67 @@ func TestReportTest2JSON_PassingRunPassesLaunch(t *testing.T) {
assert.Equal(t, "PASSED", launch.GetStatus())
}

// ReportPortal counts executions only for STEP items without children, so this checks the launch
// statistics themselves: subtests are nested under their parent test, the parent is not counted, and a
// skipped test is SKIPPED.
func TestReportTest2JSON_StatisticsSubtestsAndSkip(t *testing.T) {
e := newEnv(t)
name := uniqueName(t)
input := writeFile(t, "events.jsonl", strings.Join([]string{
`{"Time":"2026-01-01T10:00:00Z","Action":"run","Package":"example.com/e2e","Test":"TestPass"}`,
`{"Time":"2026-01-01T10:00:01Z","Action":"pass","Package":"example.com/e2e","Test":"TestPass"}`,
`{"Time":"2026-01-01T10:00:01Z","Action":"run","Package":"example.com/e2e","Test":"TestSkip"}`,
`{"Time":"2026-01-01T10:00:02Z","Action":"skip","Package":"example.com/e2e","Test":"TestSkip"}`,
`{"Time":"2026-01-01T10:00:02Z","Action":"run","Package":"example.com/e2e","Test":"TestTable"}`,
`{"Time":"2026-01-01T10:00:02Z","Action":"run","Package":"example.com/e2e","Test":"TestTable/ok"}`,
`{"Time":"2026-01-01T10:00:03Z","Action":"pass","Package":"example.com/e2e","Test":"TestTable/ok"}`,
`{"Time":"2026-01-01T10:00:03Z","Action":"run","Package":"example.com/e2e","Test":"TestTable/bad"}`,
`{"Time":"2026-01-01T10:00:04Z","Action":"fail","Package":"example.com/e2e","Test":"TestTable/bad"}`,
`{"Time":"2026-01-01T10:00:04Z","Action":"fail","Package":"example.com/e2e","Test":"TestTable"}`,
`{"Time":"2026-01-01T10:00:05Z","Action":"fail","Package":"example.com/e2e"}`,
}, "\n")+"\n")

res := runGorp(
t,
"report",
"test2json",
"--file",
input,
"--launchName",
name,
"--print-launch-uuid",
).
requireOK(t)
assert.Contains(t, res.stdout, "ReportPortal Launch: ", "the launch link is printed")

launch := e.findLaunch(t, name, func(l *openapi.LaunchViewModel) bool {
return finished(l) && l.GetStatistics().Executions != nil
})
executions := *launch.GetStatistics().Executions
assert.Equal(
t,
int32(4),
executions["total"],
"TestPass, TestSkip and two subtests; TestTable itself is not counted",
)
assert.Equal(t, int32(2), executions["passed"])
assert.Equal(t, int32(1), executions["failed"])
assert.Equal(t, int32(1), executions["skipped"])

items := e.items(t, launch.Id, 6) // the suite, three tests and two subtests
assert.Equal(t, "SKIPPED", items["TestSkip"].Status)
assert.Equal(
t,
items["TestTable"].ID,
items["ok"].Parent,
"subtests belong to their parent test",
)
assert.Equal(t, items["TestTable"].ID, items["bad"].Parent)
for _, n := range []string{"TestPass", "TestSkip", "TestTable", "ok", "bad"} {
assert.Equal(t, "STEP", items[n].Type, n)
}
}

// The atomic commands are what shell-based integrations use: each prints the ID it created.
func TestAtomicSteps(t *testing.T) {
e := newEnv(t)
Expand Down
1 change: 1 addition & 0 deletions internal/commands/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func test2jsonCmd(host, file string, extra ...cli.Flag) (*cli.Command, *bytes.Bu
&cli.StringFlag{Name: "launchName", Value: "launch"},
&cli.BoolFlag{Name: "reportEmptyPkg"},
&cli.StringSliceFlag{Name: "attr"},
&cli.BoolFlag{Name: "skipped-issue", Value: true},
&cli.BoolFlag{Name: "print-launch-uuid", Value: true},
)

Expand Down
51 changes: 40 additions & 11 deletions internal/commands/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ import (
"log/slog"
"os"
"path/filepath"
"strings"

"github.com/urfave/cli/v3"
)

// agentName identifies gorp in the "agent" system attribute of the launches it reports.
const agentName = "gorp"

// scannerMaxLine bounds a single test2json line; output events can be larger than bufio's 64 KB default.
const scannerMaxLine = 10 * 1024 * 1024

Expand Down Expand Up @@ -57,9 +61,16 @@ var (
attrFlag(
"Launch attribute with format 'key:value'. Omitting a ':' separator will tag the launch with the value.",
),
&cli.BoolFlag{
Name: "skipped-issue",
Usage: "Whether skipped tests are 'To Investigate' (true, ReportPortal's default) " +
"or 'No Defect' (false)",
Sources: cli.EnvVars("SKIPPED_ISSUE"),
Value: true,
},
&cli.BoolFlag{
Name: "print-launch-uuid",
Usage: "Print launch UUID to console",
Usage: "Print launch UUID and link to console",
Value: false,
},
&cli.BoolFlag{
Expand All @@ -83,13 +94,16 @@ func reportTest2Json(ctx context.Context, cmd *cli.Command) error {
}

// start reporting of the launch
launchID, err := reportLaunch(ctx, cfg, cmd)
launchID, launchLink, err := reportLaunch(ctx, cfg, cmd)
if err != nil {
return err
}
// check if we need to print launch UUID
// check if we need to print launch UUID (and the link, if the server returned one)
if cmd.Bool("print-launch-uuid") && launchID != "" {
_, _ = fmt.Fprintf(cmd.Writer, "ReportPortal Launch UUID: %s\n", launchID)
if launchLink != "" {
_, _ = fmt.Fprintf(cmd.Writer, "ReportPortal Launch: %s\n", launchLink)
}
}
// check if we need to check quality gate
if cmd.Bool("quality-gate-check") {
Expand All @@ -108,15 +122,22 @@ func reportTest2Json(ctx context.Context, cmd *cli.Command) error {
return nil
}

func reportLaunch(ctx context.Context, cfg *clientConfig, cmd *cli.Command) (string, error) {
// reportLaunch reports the test2json input as a launch and returns its UUID and UI link.
func reportLaunch(
ctx context.Context,
cfg *clientConfig,
cmd *cli.Command,
) (string, string, error) {
rpClient := buildReportingClient(ctx, cfg)

input := make(chan *testEvent)

launchNameArg := cmd.String("launchName")
reportEmptyPkgArg := cmd.Bool("reportEmptyPkg")
attrArgs := cmd.StringSlice("attr")
rep := newReporter(ctx, input, rpClient, launchNameArg, reportEmptyPkgArg, attrArgs...)
rep := newReporter(ctx, input, rpClient, cmd.String("launchName"), reporterOptions{
reportEmpty: cmd.Bool("reportEmptyPkg"),
skippedIssue: cmd.Bool("skipped-issue"),
agentVersion: agentVersion(cmd),
attributes: cmd.StringSlice("attr"),
})

// start reporting in a separate goroutine.
// recvErr is written before done is closed, so it is safe to read once done is closed.
Expand All @@ -135,12 +156,20 @@ func reportLaunch(ctx context.Context, cfg *clientConfig, cmd *cli.Command) (str
// reporter errors take precedence: they are the reason the input might have been abandoned
if recvErr != nil {
slog.Error("input processing interrupted", "error", recvErr)
return "", recvErr
return "", "", recvErr
}
if readErr != nil {
return "", readErr
return "", "", readErr
}
return rep.launchUUID, rep.launchLink, nil
}

// agentVersion is gorp's version as set on the root command ("1.2.3 (date)"), without the date.
func agentVersion(cmd *cli.Command) string {
if fields := strings.Fields(cmd.Root().Version); len(fields) > 0 {
return fields[0]
}
return rep.launchUUID, nil
return "dev"
}

// feedEventsFrom feeds the reporter from the --file argument, or from stdin if it is not set.
Expand Down
Loading
Loading