Skip to content

report test2json: report tests as STEPs, handle skips, send system attributes - #29

Open
DzmitryHumianiuk wants to merge 2 commits into
masterfrom
fix/test2json-reporting
Open

DzmitryHumianiuk wants to merge 2 commits into
masterfrom
fix/test2json-reporting

Conversation

@DzmitryHumianiuk

@DzmitryHumianiuk DzmitryHumianiuk commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Fixes #22, #23, #24, #25.

Problem

ReportPortal counts execution statistics, and assigns "To Investigate", only for STEP items without children. gorp report test2json reported every test as TEST, so its launches had no statistics at all. Two more problems:

  • Subtests were reported flat, next to their parent.
  • t.Skip() tests were never finished by gorp, so the server gave them the package's status (PASSED or FAILED).

Before, on ReportPortal 6.0.0 with master (pass, fail, skip, and a table test with three subtests):

LAUNCH t2j-master-baseline FAILED stats: {}
  TEST FAILED TestSkip
  TEST FAILED TestTable
  TEST PASSED TestTable/a=1   (flat, next to its parent)

After, same input:

LAUNCH t2j-fixed FAILED stats: {"total": 6, "passed": 3, "failed": 2, "skipped": 1}
  STEP SKIPPED TestSkip
  STEP FAILED  TestTable
    STEP PASSED a=1
    STEP FAILED b=2
    STEP PASSED c=3

Changes

  • Tests are STEPs, and subtests are nested under their running parent test. Every test case is counted exactly once: a test with subtests is not counted itself.
    • A test that already finished, or is paused in t.Parallel(), is never taken as the parent of a sibling named like it, e.g. t.Run("c/d") after t.Run("c").
    • testCaseId, uniqueId and codeRef are unchanged (pkg/Test/sub), so existing history is kept. Item names are now the last path segment.
  • skip is handled. Skipped tests are SKIPPED.
    • New --skipped-issue (env SKIPPED_ISSUE, default true, as rp.skipped.issue in the Java agents). Set it to false to finish skipped tests with NOT_ISSUE.
    • The launch carries the skippedIssue system attribute.
    • A package-level skip ("no test files") without a started suite is ignored, also with --reportEmptyPkg.
  • System attributes agent=gorp|<version>, os=<GOOS>|<GOARCH> and go=<version>, from new library helpers gorp.SystemAttributes, gorp.SkippedIssueAttribute and gorp.NotIssue.
  • Launch link: --print-launch-uuid now also prints the link returned by the server (ReportPortal Launch: <url>). quality-gate check --stdin still finds the UUID line.
  • ReportingClient.SaveLog sends a one-entry multipart batch. JSON on /log is deprecated in 6.x; multipart works on 5.x and 6.x.
    • Note for library users: on error the result is now nil, and the error is wrapped as unable to send log: ….

Tests

  • Unit tests:
    • hierarchy and nesting, including finished and paused siblings with / in their names;
    • skip with and without --skipped-issue;
    • system attributes, the printed link, a package skip with --reportEmptyPkg;
    • multipart SaveLog and the attribute helpers.
  • New e2e test asserting launch statistics (total/passed/failed/skipped), subtest nesting and the skipped status. The existing e2e tests never checked statistics, which is how this went unnoticed.
  • Checks run:
    • go vet, go test -race ./... and golangci-lint v2.15.0: 0 issues.
    • The e2e suite against a live ReportPortal 6.0.0: 9/9 pass.
    • Manual live runs with real go test -json streams, including parallel subtests and slash-named siblings.

Not in this PR: launch join, rerun, retries for -count, FailedBuild and the atomic command options (#26), shared library building blocks (#27), and the errorCode decoding issue (#28).

Known server issue: on ReportPortal versions without reportportal/service-api#2935, a launch merged from launches that share an attribute (gorp now sends the same agent/os/go system attributes) can't be deleted (reportportal/reportportal#2716).

🤖 Generated with Claude Code

…tributes

ReportPortal counts execution statistics and assigns "To Investigate"
only for STEP items without children. test2json reported every test as
TEST, so its launches had no statistics at all, and subtests were flat
next to their parent.

- Report each test as a STEP and nest subtests under their running
  parent test, so every test case is counted exactly once. A test that
  already finished or is paused in t.Parallel() is never taken as the
  parent of a test named like it.
- Handle the skip action: t.Skip() tests are SKIPPED instead of taking
  the package status. --skipped-issue (default true, as rp.skipped.issue
  in the Java agents) can mark them No Defect, and the launch carries
  the skippedIssue system attribute.
- Send the agent, os and go system attributes (new pkg/gorp helpers
  SystemAttributes, SkippedIssueAttribute, NotIssue).
- Print the launch link returned by the server with --print-launch-uuid.
- Send SaveLog as a one-entry multipart batch: JSON on /log is
  deprecated in ReportPortal 6.x.
- e2e: assert launch statistics, subtest nesting and skipped status.

Fixes #22, #23, #24, #25

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A critical hierarchy bug can attach a child to the wrong parallel sibling, corrupting leaf statistics and prematurely closing an unrelated child.

1 open issue
What changed in this PR

This PR addresses #22–#25 across goRP’s test2json reporter and public library, improving ReportPortal execution statistics, skipped-test handling, launch metadata, and log compatibility.

Changes:

  • Reports tests as nested STEP items and handles skips with configurable issue classification.
  • Adds system-attribute helpers and prints the server-provided launch link.
  • Sends single logs as multipart batches and expands unit and end-to-end coverage.
File Description
README.md Documents hierarchy, skip behavior, attributes, and launch-link output.
pkg/​gorp/​reporting_client.go Routes single-log requests through multipart batching.
pkg/​gorp/​reporting_client_test.go Verifies multipart single-log requests and responses.
pkg/​gorp/​attributes.go Adds system-attribute and “No Defect” helpers.
pkg/​gorp/​attributes_test.go Tests attribute values and issue classification.
internal/​commands/​reporter.go Implements nested steps, skip handling, system attributes, and launch-link capture.
internal/​commands/​report.go Adds the skip option, agent version lookup, and link output.
internal/​commands/​report_test.go Updates tests for reporter options and return values.
internal/​commands/​report_robustness_test.go Adapts robustness tests to the launch-link return value.
internal/​commands/​report_hierarchy_test.go Adds hierarchy, skip, attribute, link, and empty-package tests.
internal/​commands/​actions_test.go Adds the skipped-issue default to command fixtures.
e2e/​reporting_test.go Checks live execution statistics, nesting, skipped status, and link output.
AGENTS.md Updates contributor guidance and reporter file references.
.claude/​skills/​reportportal/​SKILL.md Documents the new reporting options and behavior.

Review effort: Balanced

Comment thread internal/commands/reporter.go Outdated
Comment on lines +305 to +306
if ok && !r.paused[name] && slices.Contains(r.openItems, id) {
return id, ev.Test[i+1:]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks. The case is real, but the stream doesn't contain enough information to resolve it. I ran both programs with go test -json (Go 1.27): a calling t.Run("b/c") and a/b calling t.Run("c"), with parallel siblings a and a/b both resumed. They produce the same event stream: run TestX/a/b/c with both tests running. No rule based on names or events can pick the right parent at start time, so some fallback is needed. I compared the two options:

  • Longest prefix (kept): right when a/b ran c, which I think is the more common pattern (for example, parallel table cases named /api and /api/users). When it is wrong, c is shown under its sibling, but every test case is still counted exactly once. a becomes the leaf in place of a/b, so the totals don't change. The early finish isn't harmful either. I sent that exact interleaving to a ReportPortal instance: a/b finished before its misplaced child, and ReportPortal accepted both finishes. All items ended PASSED with correct launch totals, and the child was not closed early.
  • Nearest common ancestor / rejecting: this would flatten c under TestX and count one test case too many in both readings, so the hierarchy would be wrong every time instead of only some of the time.

What I changed in d4d2e5e:

  • parentOf now also drops candidates that have a running subtest. Such a test is blocked in t.Run, or its body has returned while its parallel subtests run, so it can't start a new subtest. This resolves the interleavings that can be decided.
  • The undecidable case and the reasoning for the longest-prefix fallback are now documented in the parentOf comment.
  • New tests: TestReportLaunch_AmbiguousSubtestParent replays the real stream for your interleaving and checks the documented fallback. TestReportLaunch_SubtestParentHasNoRunningSubtest covers the new filter.

A running test with a running subtest is blocked in t.Run (or its body
returned and its parallel subtests run), so it cannot start a new
subtest. parentOf now drops such candidates before taking the longest
running prefix. Document the remaining case test2json cannot decide
(parallel siblings "a" and "a/b" both running) and why the longest
prefix is kept there: test cases are still counted exactly once.

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

4 participants