phpunit-test-runner icon indicating copy to clipboard operation
phpunit-test-runner copied to clipboard

host-test unable to report results as of r62226 (simplexml load failing of junit.xml)

Open kmott opened this issue 7 months ago • 12 comments

Describe the bug It's looking like some recently added email tests cause the test reporters to fail. More specifically, simplexml can't load the junit.xml report:

[ ... ]
Getting SVN Revision
Getting SVN message
Copying junit.xml results
rsync -r '/var/www/wordpress'/tests/phpunit/build/logs/* '/var/www/wordpress'
Processing and uploading junit.xml
PHP Warning:  simplexml_load_string(): Entity: line 9474: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0x80 0x62 0x40 0x65 in /var/www/phpunit/functions.php on line 211
PHP Warning:  simplexml_load_string(): name="test_returns_false_if_given_an_invalid_email_address with data set "a in /var/www/phpunit/functions.php on line 211
PHP Warning:  simplexml_load_string():                                                                                ^ in /var/www/phpunit/functions.php on line 211
PHP Warning:  Attempt to read property "testsuite" on false in /var/www/phpunit/functions.php on line 213
PHP Warning:  Trying to access array offset on null in /var/www/phpunit/functions.php on line 217
PHP Warning:  Trying to access array offset on null in /var/www/phpunit/functions.php on line 218
PHP Warning:  Trying to access array offset on null in /var/www/phpunit/functions.php on line 219
PHP Warning:  Trying to access array offset on null in /var/www/phpunit/functions.php on line 220
PHP Fatal error:  Uncaught Error: Call to a member function xpath() on false in /var/www/phpunit/functions.php:225
Stack trace:
#0 /var/www/phpunit/report.php(97): process_junit_xml()
#1 {main}
  thrown in /var/www/phpunit/functions.php on line 225

To Reproduce Steps to reproduce the behavior:

  1. Run the host tests which will pass
  2. Attempt to report back results, which loads junit.xml
  3. Notice failure

Expected behavior No failures, host tests report back successfully.

Screenshots N/A

Additional context Actual junit.xml.gz report is here for reference: junit.xml.gz

kmott avatar Apr 14 '26 15:04 kmott

[....] WARNINGS! Tests: 29175, Assertions: 3440834, Warnings: 86, Skipped: 77. 2026-04-15 02:37:05 report.php Environment variables pass checks. Getting SVN Revision Getting SVN message Copying junit.xml results rsync -r '/home/wptest/runs/php83'/tests/phpunit/build/logs/* '/home/wptest/runs/php83' Processing and uploading junit.xml PHP Warning: simplexml_load_string(): Entity: line 9474: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0x80 0x62 0x40 0x65 in /home/wptest/phpunit-test/functions.php on line 211 PHP Warning: simplexml_load_string(): name="test_returns_false_if_given_an_invalid_email_address with data set "a in /home/wptest/phpunit-test/functions.php on line 211 PHP Warning: simplexml_load_string(): ^ in /home/wptest/phpunit-test/functions.php on line 211 PHP Warning: Attempt to read property "testsuite" on false in /home/wptest/phpunit-test/functions.php on line 213 PHP Warning: Trying to access array offset on null in /home/wptest/phpunit-test/functions.php on line 217 PHP Warning: Trying to access array offset on null in /home/wptest/phpunit-test/functions.php on line 218 PHP Warning: Trying to access array offset on null in /home/wptest/phpunit-test/functions.php on line 219 PHP Warning: Trying to access array offset on null in /home/wptest/phpunit-test/functions.php on line 220 PHP Fatal error: Uncaught Error: Call to a member function xpath() on false in /home/wptest/phpunit-test/functions.php:225 Stack trace: #0 /home/wptest/phpunit-test/report.php(97): process_junit_xml() #1 {main} thrown in /home/wptest/phpunit-test/functions.php on line 225 root@vmi2069036:~# file -bi /home/wptest/runs/php83/tests/phpunit/build/logs/junit.xml text/xml; charset=us-ascii

@kmott I am getting same issue.

sanyogs avatar Apr 15 '26 10:04 sanyogs

This issue was file parsing which can be one byte sequence in the XML content that XML parsing does not accept. Which we fixed while running command and issue is solved. Test Result This show Version Next Under Hosting Test Result.

sanyogs avatar Apr 15 '26 10:04 sanyogs

@sanyogs Can you please share the specific steps taken when running the command that fixed it?

kittenkamala avatar Apr 15 '26 18:04 kittenkamala

Reported on the related Trac https://core.trac.wordpress.org/ticket/31992#comment:90 and @dmsnell was tagged to look into this (in relation to their recent PR)

kittenkamala avatar Apr 15 '26 18:04 kittenkamala

@kittenkamala

report.php was failing because the generated junit.xml occasionally contained invalid byte sequences for XML parsing. The key symptom was this:

simplexml_load_string(): Input is not proper UTF-8

Even though file showed us-ascii, the XML still had at least one bad byte sequence inside the content that SimpleXML rejected. Because of that: • simplexml_load_string() returned false • process_junit_xml() could not read the XML structure • report.php crashed before upload

The cleanup block fixed that by reopening junit.xml, decoding it as UTF-8 with invalid bytes ignored, and writing back a clean UTF-8 version before report.php reads it.

sanyogs avatar Apr 16 '26 10:04 sanyogs

I wrote the test in question. It guards against fun-loving browsers passing us malformed UTF8. Guarding against that is a good thing, and I guess at least some such tests will report what they're doing, so the fix by @sanyogs sounds like the best possible solution. Thanks!

arnt avatar Apr 16 '26 13:04 arnt

Hitting the same issue here. Can confirm the UTF-8 sanitization approach works.

rollecode avatar Apr 20 '26 08:04 rollecode

The cleanup block fixed that by reopening junit.xml, decoding it as UTF-8 with invalid bytes ignored, and writing back a clean UTF-8 version before report.php reads it.

the invalid UTF-8 should only appear when tests fail, so I’m surprised it passed, unless it’s coming from the test case name.

either way, instead of stripping away the invalid bytes, which will obscure the test run results, we can alter the output of the tests to convey the same information in UTF-8. the tests should deal with invalid UTF-8, including conveying properly when those parts fail.

in the past I’ve used hex digits in parentheses, for example, to convey the invalid bytes.

dmsnell avatar Apr 20 '26 17:04 dmsnell

Hope this is closed by https://github.com/WordPress/wordpress-develop/commit/4440667d806019cbe9b9e67fad6836b0d74cce6d

It runs test names with invalid UTF-8 in them through a transformer to represent the invalid bytes as hex values.

dmsnell avatar Apr 21 '26 14:04 dmsnell

@kmott @sanyogs Host tests are reporting passed tests with the above changeset but I'm not sure if yours are. Are your tests still failing or are they passing after they pull in the latest change? https://make.wordpress.org/hosting/test-results/r62249/

edit to add: I am sure now that neither of your bots have sent reports on this. Can you try running tests again and see if they go through this time?

kittenkamala avatar Apr 21 '26 21:04 kittenkamala

https://github.com/WordPress/wordpress-develop/commit/4440667d806019cbe9b9e67fad6836b0d74cce6d looks good to me, but I'm curious about why it's needed. It seems to me that if the CI reports that there is breakage when there is, and in which file/commit, then that's good enough. Reporting the name of the test is just nice to have. What do I overlook?

arnt avatar Apr 22 '26 11:04 arnt

@kmott @sanyogs Host tests are reporting passed tests with the above changeset but I'm not sure if yours are. Are your tests still failing or are they passing after they pull in the latest change? https://make.wordpress.org/hosting/test-results/r62249/

Yup, mine are all passing now @kittenkamala, thanks again for chasing it down!

kmott avatar Apr 22 '26 14:04 kmott