Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#55667 closed defect (bug) (fixed)

Tests_Basic::test_security_md() truncates the `.0` for `x.1` current version releases.

Reported by: hellofromtonya's profile hellofromTonya Owned by: hellofromtonya's profile hellofromTonya
Milestone: 6.1 Priority: normal
Severity: normal Version: 5.4
Component: Build/Test Tools Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Discovered when branching 6.0, the Tests_Basic::test_security_md() code introduced in [47403] removes the .0 in calcuating the latest stable version number:

$latest_stable   = sprintf( '%s.x', (float) $current_version - 0.1 );

When $current_version is say 6.1, after running through the (float) type conversion and subtracting 0.1, the resultant is 6 rather than 6.0. This causes the test to fail.

As a temporary workaround, the assertion was disabled in [53346]. Once fixed, this change can be reverted.

Attachments (2)

55667.diff (3.5 KB) - added by SergeyBiryukov 2 years ago.
55667.2.diff (3.4 KB) - added by SergeyBiryukov 2 years ago.

Download all attachments as: .zip

Change History (12)

#1 @hellofromTonya
2 years ago

See the problem in action here https://3v4l.org/928vf.

Using number_format() resolves the issue https://3v4l.org/M7Cb2.

This ticket was mentioned in PR #2671 on WordPress/wordpress-develop by hellofromtonya.


2 years ago
#2

  • Keywords has-patch has-unit-tests added; needs-patch removed

Uses number_format() after doing the floating point math to ensure the version is in X.X format.

See the problem in action here https://3v4l.org/928vf.

Using number_format() resolves the issue https://3v4l.org/M7Cb2.

Also reverts https://core.trac.wordpress.org/changeset/53346.

Trac ticket: https://core.trac.wordpress.org/ticket/55667

#3 @hellofromTonya
2 years ago

  • Owner set to hellofromTonya
  • Resolution set to fixed
  • Status changed from new to closed

In 53347:

Build/Test Tools: Ensure version number is in 'X.X' format after float math: Tests_Basic::test_security_md().

After subtracing 0.1 from a X.1 current version, the result was a single digit without the .0 decimal. Using number_format() ensures each current version has a decimal before appending the .x before the test.

This commit also reverts [55346] which was a temporary workaround.

Follow-up to [55346], [47403].
Fixes #55667.

@SergeyBiryukov
2 years ago

#5 @SergeyBiryukov
2 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Thanks for fixing this!

It looks like the test still fails on commits to older branches, or when run for older branches locally:

There was 1 failure:

1) Tests_Basic::test_security_md
SECURITY.md's version needs to be updated to 5.8.x.
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-5.8.x
+5.9.x

/var/www/tests/phpunit/tests/basic.php:28
phpvfscomposer:///var/www/vendor/phpunit/phpunit/phpunit:51

I think the test could further be updated to avoid a failure in this case, as well as to avoid a failure if SECURITY.md is updated prior to branching, like in [53342].

It's fine if the file is updated to include a soon-to-be-released version that's not the latest stable yet, the purpose of the test was to make sure the latest version in SECURITY.md is either the current one or latest stable, but not an older one.

See 55667.diff. Includes minor code layout changes for related tests for better readability. The fix could then be backported to older branches too.

This ticket was mentioned in Slack in #core by sergey. View the logs.


2 years ago

#8 @SergeyBiryukov
2 years ago

55667.2.diff is a simplified version with a bit less reformatting.

This ticket was mentioned in Slack in #core by sergey. View the logs.


2 years ago

#10 @SergeyBiryukov
2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 53357:

Tests: Improve the logic of the SECURITY.md test to check all supported versions.

This avoids a test failure if the list of supported WordPress versions is updated before the trunk version is bumped for a new major release.

Follow-up to [47403], [53347].

Fixes #55667.

Note: See TracTickets for help on using tickets.