Skip to content

Tests: Improve isolation for randomized media tests - #13190

Closed
sirreal wants to merge 5 commits into
WordPress:trunkfrom
sirreal:agent/test-order-media-isolation
Closed

sirreal wants to merge 5 commits into
WordPress:trunkfrom
sirreal:agent/test-order-media-isolation

Conversation

@sirreal

@sirreal sirreal commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Resets loading-optimization state before each test and moves the remote image-cropping test into the external-HTTP group, preserving remote-fetch coverage.
  • Accepts generated caption-ID suffixes and derives expected attachment names from the files actually uploaded.
  • Restores the incoming HTTPS server value after attachment tests so a class-level fixture cannot capture leaked request state.
  • Keeps the changes confined to PHPUnit tests and fixtures.

Verification

  • Minimized seed 1789074025 to the HTTPS-mutating attachment test followed by the attachment-link class fixture, then replayed the full failing seed after the fix.
  • 100 consecutive fresh randomized media-group runs passed on the combined campaign branch after resetting the counter; each completed 842 tests and 2,220 assertions with 52 expected skips.
  • Exact seeds 1789084001 through 1789084100 all exited cleanly without exclusions or replays; maximum PHPUnit time was 33.552 seconds.
  • All three relevant changed file trees match this isolated PR branch, and the HTTPS restoration patch ID matches the gated commit.
  • PHP syntax checks and git diff --check passed.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@lancewillett

Copy link
Copy Markdown
Member

Refreshed with current trunk in a non-rewriting merge: 51c5e19.

Validation passed: git diff --check; vendor/bin/phpcs --standard=phpcs.xml.dist for the three changed PHP test files; and a focused randomized PHPUnit contamination replay (seed 13190): 7 tests, 32 assertions.

Limitation: this was a targeted replay; the new CI run provides the full matrix.

lancewillett and others added 2 commits September 30, 2026 09:49
Restores the remote URL in `Tests_Image_Functions::test_wp_crop_image_with_url()` and tags the test `external-http`, so it no longer runs by default and needs no network, but still covers cropping a remote image when that group runs.

See #65893.

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

Copy link
Copy Markdown
Member

Refreshed this against trunk and changed one thing.

  • The media.php resets fix Tests_Media::test_wp_get_attachment_image_fetchpriority_high_when_not_lazy_loaded at seed 2 of --group media, and the caption regex fixes test_img_caption_shortcode_with_old_format_id_and_align at seed 2 of the top-level files.
  • The HTTPS restore fixes a leak into the next class: the HTTPS attachment test followed by Tests_Post_WpGetAttachmentLink fails on trunk (the link comes out https://) and passes with this branch.
  • I put back the remote URL in test_wp_crop_image_with_url and tagged it external-http instead of switching to file://. The file:// version no longer tests a remote fetch; the group keeps it out of default runs, and CI still runs it in the external-http step.

--group media and post/ pass in default order and seeds 1–3.

@lancewillett
lancewillett marked this pull request as ready for review September 30, 2026 17:21
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, lancewillett, adrianmoldovanwp.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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

The crop test remains network-dependent despite the summary claiming replacement with a local fixture.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Improves isolation and stability of randomized media PHPUnit tests.

Changes:

  • Resets media optimization state between tests.
  • Restores HTTPS state and derives uploaded filenames dynamically.
  • Reclassifies a live crop test as external HTTP.
File Description
tests/​phpunit/​tests/​post/​attachments.php Restores HTTPS state and supports randomized upload names.
tests/​phpunit/​tests/​media.php Resets media state and accepts generated caption IDs.
tests/​phpunit/​tests/​image/​functions.php Marks the live crop test as external HTTP.

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

Comment thread tests/phpunit/tests/image/functions.php
wporg-sync pushed a commit that referenced this pull request Oct 1, 2026
Reset loading-optimization state before each media test, accept valid generated caption-ID suffixes, and derive expected attachment filenames from the uploaded files. Restore the incoming HTTPS server value after attachment tests.

Group the remote image-cropping test under external-http, preserving its remote-fetch coverage while keeping it out of the default test run.

Developed in: #13190

Props jonsurrell, adrianmoldovanwp.
See #65893.


git-svn-id: https://develop.svn.wordpress.org/trunk@64042 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 1, 2026
Reset loading-optimization state before each media test, accept valid generated caption-ID suffixes, and derive expected attachment filenames from the uploaded files. Restore the incoming HTTPS server value after attachment tests.

Group the remote image-cropping test under external-http, preserving its remote-fetch coverage while keeping it out of the default test run.

Developed in: WordPress/wordpress-develop#13190

Props jonsurrell, adrianmoldovanwp.
See #65893.

Built from https://develop.svn.wordpress.org/trunk@64042


git-svn-id: http://core.svn.wordpress.org/trunk@63201 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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.

4 participants