Skip to content

feat: include scenario name and id in test reports - #2765

Open
lukkaempf wants to merge 3 commits into
kyverno:mainfrom
lukkaempf:feat/scenario-in-report
Open

lukkaempf wants to merge 3 commits into
kyverno:mainfrom
lukkaempf:feat/scenario-in-report

Conversation

@lukkaempf

Copy link
Copy Markdown

Explanation

When a test defines scenarios, Chainsaw runs the test once per scenario. The terminal output already shows which scenario is running, but the generated reports did not.
This PR fixes that by carrying the scenario name and scenario id through to the report output. It is an additive, backwards-compatible change: tests without scenarios produce exactly the same reports as before.

Proposed Changes

  • model.TestReport gains ScenarioId and ScenarioName, plus a DisplayName() helper that returns <test-name> [<scenario-name>] when a scenario is set, and the plain test name otherwise.
  • runner populates both fields when building the test report. The scenario name comes from names.Scenario(...), so unnamed scenarios fall back to scenario #N, consistent with the terminal logger.

Proof Manifests

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: scenario-report
spec:
  scenarios:
    - name: variant-a
      bindings:
        - name: message
          value: hello
    - name: variant-b
      bindings:
        - name: message
          value: goodbye
  steps:
    - try:
        - script:
            env:
              - name: message
                value: ($message)
            content: echo $message
            check:
              (trim_space($stdout)): ($message)
chainsaw test scenario-report --no-cluster --report-format JSON --report-path .

Before

"tests": [
  {
    "basePath": "testdata/e2e/examples/scenario-report",
    "name": "scenario-report",
    "status": "passed",
    ...
  },
  {
    "basePath": "testdata/e2e/examples/scenario-report",
    "name": "scenario-report",
    "status": "passed",
    ...
  }
]

After

"tests": [
  {
    "basePath": "testdata/e2e/examples/scenario-report",
    "name": "scenario-report",
    "scenarioId": 2,
    "scenario": "variant-b",
    "status": "passed",
    ...
  },
  {
    "basePath": "testdata/e2e/examples/scenario-report",
    "name": "scenario-report",
    "scenarioId": 1,
    "scenario": "variant-a",
    "status": "passed",
    ...
  }
]

Same run with --report-format JUNIT-TEST

<!-- before -->
<testcase name="scenario-report" classname="" time="0.008511"></testcase>
<testcase name="scenario-report" classname="" time="0.008824"></testcase>

<!-- after -->
<testcase name="scenario-report [variant-b]" classname="" time="0.008511"></testcase>
<testcase name="scenario-report [variant-a]" classname="" time="0.008824"></testcase>

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Signed-off-by: Lukas Kaempf <lukkaempf@gmail.com>
@lukkaempf
lukkaempf requested a review from a team as a code owner September 3, 2026 09:58

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.

Copilot review overview

🟡 Changes recommended

Add meaningful assertions or golden-output coverage for scenario and backwards-compatibility cases.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds scenario IDs and names to JSON and JUnit test reports while preserving existing behavior for tests without scenarios.

Changes:

  • Propagates scenario metadata from the runner.
  • Serializes scenario fields in JSON reports.
  • Uses scenario-aware display names in JUnit output.

Review note: Report tests should assert generated content, including named, unnamed, and no-scenario cases.

File Description
pkg/​runner/​runner.go Populates scenario metadata.
pkg/​report/​junit.go Includes scenario names in JUnit output.
pkg/​report/​json.go Serializes scenario fields in JSON.
pkg/​model/​report.go Adds scenario fields and display-name formatting.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/model/report.go Resolved
Signed-off-by: Lukas Kaempf <lukkaempf@gmail.com>

This branch has not been deployed

No deployments
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.

3 participants