@open-xchange/junit-hindsight
v0.1.1
Published
Sends JUnit XML test reports to Hindsight
Maintainers
Keywords
Readme
@open-xchange/junit-hindsight
Sends the test results in JUnit XML reports to Hindsight.
For suites whose runner writes JUnit XML (Gradle, Maven Surefire and most others) and has no Hindsight plugin of its own. It runs after the tests and needs no change to them.
Usage
npx @open-xchange/junit-hindsight [--client <name>] [--suite <kind>] [--redact-env <VARIABLE>]... <path>...Each path is a report file, or a directory searched for .xml files at any depth.
| Argument | Default | Description |
|----------|---------|-------------|
| --client | junit | Client identifier sent with every result |
| --suite | — | Kind of suite the results belong to: unit, integration or e2e |
| --redact-env | — | Environment variable whose value is removed from failure evidence. Repeatable |
The rest is configured through the environment:
| Env var | Default | Description |
|---------|---------|-------------|
| HINDSIGHT_URL | http://localhost:8080 | Hindsight API base URL |
| HINDSIGHT_TOKEN_ENDPOINT | — | Keycloak token endpoint |
| HINDSIGHT_CLIENT_ID | — | OIDC client ID |
| HINDSIGHT_CLIENT_SECRET | — | OIDC client secret |
| CI_COMMIT_REF_NAME | local | Git branch name |
| CI_PROJECT_PATH | hindsight | Project identifier |
| CI_PIPELINE_ID | — | CI pipeline ID. Nothing is sent without one |
| REPORT_PROJECT | — | Deployment identifier |
Authentication
When the client ID, client secret and token endpoint are all set, the adapter authenticates using the OIDC client credentials flow. The token goes in both the Authorization header and the hindsight_token cookie, which is the only place a preview deployment reads it from. Without them, requests are sent without authentication, which suits a local Hindsight running with auth disabled.
What gets reported
Every test case in every report, sent to POST /api/v1/test-runs:
| Field | Source |
|-------|--------|
| feature | classname of the test case, or the suite name without one |
| scenario | name of the test case |
| state | failed with a failure or error element, skipped with a skipped element, passed otherwise |
| duration_ms | time of the test case, in milliseconds |
| branch, project, pipeline_id, deployment | The environment, as above |
| client | --client (default: junit) |
| time | timestamp of the test suite, read as UTC when it names no time zone. Without one, the time the result arrives |
| suite | --suite, when given |
| run_id | Generated per test case |
| failure | Message and stack trace of a failed test |
A test case without a name is left out, with a warning.
Results go out in requests of at most 1000, and small enough to stay below the API's body size limit. A request that gets no answer within 30 seconds, or a 429 or 5xx one, is sent up to three times. If it still fails, the adapter carries on with the next request, and stops once three in a row have failed.
Failure context
A failed test reports the message attribute and the text of its failure or error element, which is the stack trace for JVM runners. Evidence longer than Hindsight keeps is cut just past that length, so Hindsight still marks it as truncated.
Test output contains credentials, so evidence is cleaned before it is sent. The adapter always removes its own client secret, and --redact-env removes the values of other environment variables:
npx @open-xchange/junit-hindsight --suite integration --redact-env TEST_PASSWORD build/test-resultsNaming the variable instead of the value keeps the secret out of the job log. Hindsight also removes recognisable secrets on arrival, but it can only match what secrets generally look like.
CI example (GitLab)
integration tests:
script:
- ./gradlew integrationTest
artifacts:
when: always
paths:
- "*/build/test-results/integrationTest"
report to hindsight:
image: node:24
needs: [integration tests]
when: always
variables:
HINDSIGHT_URL: https://hindsight.example.com
HINDSIGHT_TOKEN_ENDPOINT: https://keycloak.example.com/realms/my-realm/protocol/openid-connect/token
script:
- npx @open-xchange/junit-hindsight --suite integration */build/test-results/integrationTestThe tests run in one job and keep their reports as artifacts; a second job with Node.js sends them. when: always makes it run after failing tests too. The Gradle job needs no Node.js that way, and the exit code of the reporting job is visible, which GitLab ignores for a command in after_script.
In a multi-module build the reports are in <module>/build/test-results/<task>. Naming the task directory selects its tests only.
Point the adapter at each report once. A job that also keeps a second copy of its reports would report every test twice.
Error handling
Reporting problems are logged as warnings and the command exits successfully: a Hindsight that is unreachable or does not answer, a refused request or token, a file that is not a JUnit report, or no reports at all. Only a wrong command line exits with status 2, so a misconfigured job shows up when it is first set up.
License
AGPL-3.0-or-later
