Skip to content

Conversation

@adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Jan 27, 2026

Adds a fix and test for #2358 where deleting a media item does not remove the full-size converted source file (e.g. the AVIF version of an originally uploaded JPEG). The bug is in webp_uploads_remove_sources_files() which incorrectly skips the full-size source when the attached file's MIME type matches the source MIME type.

Summary

Fixes #2358

Relevant technical choices

Use of AI Tools

I used Claude to investigate the issue and write this test that demonstrates the failure. I also used Claude to suggest a solution to the problem.

@adamsilverstein adamsilverstein added the [Type] Bug An existing feature is broken label Jan 27, 2026
@github-actions
Copy link

github-actions bot commented Jan 27, 2026

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: adamsilverstein <[email protected]>
Co-authored-by: westonruter <[email protected]>

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

@adamsilverstein adamsilverstein added this to the webp-uploads n.e.x.t milestone Jan 27, 2026
@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.17%. Comparing base (509ad26) to head (adaa042).
⚠️ Report is 2 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk    #2364   +/-   ##
=======================================
  Coverage   69.17%   69.17%           
=======================================
  Files          90       90           
  Lines        7708     7708           
=======================================
  Hits         5332     5332           
  Misses       2376     2376           
Flag Coverage Δ
multisite 69.17% <ø> (ø)
single 35.39% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…hment removal

Adds a regression test for #2358 where deleting a media item does not
remove the full-size converted source file (e.g. the AVIF/WebP version
of an originally uploaded JPEG).

The test calls webp_uploads_remove_sources_files() directly rather than
wp_delete_attachment(), because WordPress's own file cleanup masks the
bug by deleting the attached file (which after the plugin's replacement
is the converted file itself).

The root cause is in webp_uploads_remove_sources_files() which checks
$original_mime_from_file via wp_check_filetype() on the current attached
file. After the plugin replaces the attached file with the converted
format, this check incorrectly matches the source's MIME type, causing
the function to skip deleting it.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@adamsilverstein adamsilverstein force-pushed the add/tests-for-deleted-files branch from adaa042 to 71568ba Compare January 27, 2026 21:53
@westonruter
Copy link
Member

So will the fix for the failure be worked on in this PR as well? I don't think we should merge a failing test.

@adamsilverstein
Copy link
Member Author

So will the fix for the failure be worked on in this PR as well? I don't think we should merge a failing test.

yes! I wanted to work on the test first to validate the issue and I can see it is failing as expected (https://github.com/WordPress/performance/actions/runs/21415667609/job/61663435120?pr=2364). I'll work on the fix next.

@adamsilverstein adamsilverstein changed the title Add failing test for full-size source file not being deleted on attachment removal Fix: full-size source file not deleted on attachment removal Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Original AVIF files don't get deleted

3 participants