Skip to content

feat: summarize integration test results and upload the reports - #401

Open
DavidLambauer wants to merge 3 commits into
mage-os:mainfrom
DavidLambauer:feat/integration-test-report
Open

DavidLambauer wants to merge 3 commits into
mage-os:mainfrom
DavidLambauer:feat/integration-test-report

Conversation

@DavidLambauer

Copy link
Copy Markdown
Contributor

Why

The Nx integration job only shows test results in the raw job log, and often not even there:

  • Nx prints a module's PHPUnit output only after the module has finished. A cancelled or timed-out job therefore shows nothing for the module that was running.
  • The JUnit files are written but never uploaded.
  • Finding the failures of a long module run means scrolling through thousands of log lines.

What

  • phpunit-report is a new composite action that uses only the Python 3 standard library.
    • It turns PHPUnit TeamCity logs into a job summary: a headline, the failed tests per suite with their messages, and a table of all suites.
    • It annotates the first 10 failures with file and line.
    • It reads the TeamCity log rather than JUnit because PHPUnit writes the TeamCity log while the tests run. A run that PHPUnit aborted still lists its failures, and the summary marks that suite as ended early. PHPUnit writes the JUnit log only at the end, so an aborted run has none.
    • It never fails the job.
  • Nx integration workflow
    • Streams PHPUnit output while each module runs (--output-style=stream-without-prefixes; the Nx 15.4.1 pinned by nx-for-php supports it).
    • Writes a TeamCity log per module next to the JUnit log.
    • Summarizes the TeamCity logs with phpunit-report.
    • Uploads phpunit-output/ (JUnit and TeamCity) as integration-test-reports-<job-index>, kept for 14 days.
  • _internal-phpunit-report.yaml runs the script's unit tests and runs the action on the fixture logs.

Testing

  • python3 -m unittest discover -s phpunit-report/test: 13 tests, passing.
  • Ran the script on the TeamCity logs of real Catalog and Sales integration runs. One was a Catalog run that PHPUnit aborted after 1708 of 2195 tests: it reported 98 failures and marked the suite as ended early.
  • End to end: ran this workflow from a fork against a throwaway mageos-magento2 commit with deliberately failing tests in Magento_Version: run 46139702565.
    • Nx streamed the PHPUnit output.
    • The report annotated the three failures (an assertion, an exception and a data set) at the right file and line.
    • The artifact holds junit/Version.xml and teamcity/Version.log.
Job summary of that run

Integration tests

❌ 1 of 1 suite failed: 3 failed tests.

Version: 3 failed tests
Test Message
Magento\Version\Test\Integration\ReportDemoTest::testFailsAnAssertion Deliberate failure to check the CI report
Magento\Version\Test\Integration\ReportDemoTest::testThrows RuntimeException: Deliberate error to check the CI report
Magento\Version\Test\Integration\ReportDemoTest::testDataSet with data set "large" Failed asserting that 5 is less than 2.
Suite Tests Failed Skipped Result
Version 6 3 0 ❌ failed

Notes

  • The workflow uses mage-os/github-actions/phpunit-report@main, like the other actions, so the summary step works once this PR is merged.
  • A re-run of a commit whose Nx project cache was saved before this change has no TeamCity logs. Its summary then says that no suite ran.

🤖 Generated with Claude Code

DavidLambauer and others added 2 commits November 28, 2026 12:31
…logs

The action writes a job summary with the failed tests of each suite and
annotates the first failures. It reads the TeamCity log because PHPUnit
writes it while the tests run, so it also covers runs that PHPUnit aborted,
which never get a JUnit log.

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

- Stream each module's PHPUnit output while it runs. Nx printed it only
  after the module finished, so a cancelled or timed-out job showed nothing.
- Write a TeamCity log per module and summarize it with phpunit-report.
- Upload the JUnit and TeamCity logs as an artifact.

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

@rhoerr rhoerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice improvement. Three things to look at:

  1. An empty TeamCity log is reported as passed. If PHPUnit opens the log but dies before the first suite starts (e.g. a data provider or test loading error), parse() returns planned=None, no failures and ended_early=False. The summary then shows :white_check_mark: passed with ? tests. Suggest treating planned is None as ended early or unknown, with an empty-log fixture test.
  2. The summary can exceed GitHub's 1 MiB limit and be dropped. A broad change (e.g. Framework) runs many modules in one job. At up to 100 rows of about 450 bytes per failing suite, roughly 23 failing suites pass the limit, and GitHub then drops the whole summary. Suggest a global row cap (about 300–500) or a byte budget in markdown(), pointing to the artifact for the rest.
  3. Minor: a bootstrap failure reads as "no suite ran". If PHPUnit's bootstrap fails (e.g. the Magento install), no log is created, so that module is left out, or the summary says "no suite ran". Something like "No TeamCity logs found, see the job log" would be more accurate.

…ary below 1 MiB

- An empty TeamCity log is shown as without results instead of passed.
  PHPUnit leaves the log empty both when no test matched and when it
  stopped while loading the tests, so it can't be read as ended early.
- The failure rows stop at 512 KiB, because GitHub drops a step summary
  larger than 1 MiB. The summary then points to the new reports-url
  input, which the Nx integration workflow sets to the uploaded reports.
- Without any log, the summary says to see the job log instead of
  claiming that no suite ran: PHPUnit writes no log when its bootstrap
  fails.
@DavidLambauer

Copy link
Copy Markdown
Contributor Author

@rhoerr thanks, all three are fixed in 661cd3b:

  1. Empty log: it now shows as :grey_question: no results instead of passed, and the headline counts it, for example "1 of 2 suites passed: …, 1 suite without results". I didn't count it as "ended early". With PHPUnit 12 the log is also empty when no test matches the module's filter, and then PHPUnit exits 0. Loading errors leave it empty too, but exit non-zero: a parse error exits 255 and a broken data provider exits 2. The log alone can't tell these cases apart. I added an Empty.log fixture and tests.
  2. 1 MiB: the failure rows now stop at 512 KiB, and the 100-per-suite cap stays. Suites past that point keep their <details> block and say "N failures not listed". The summary then links to the full reports through a new optional reports-url input. The Nx workflow fills it from the artifact-url output of actions/upload-artifact, so the upload step now runs before the summary. In the new test with 30 suites of 100 failures each, the summary was 1.27 MB before and is 529 KB now.
  3. No logs: the summary now says "No PHPUnit TeamCity logs found in …, see the job log." The README notes that PHPUnit writes no log when its bootstrap fails, so that suite is missing from the summary.

I also ran the Nx workflow end to end from my forks with a failing test in Magento_Version. The summary step received the artifact URL, the failure is annotated at its file and line, and the summary rendered from the downloaded artifact is correct.

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.

2 participants