Repository navigation
Upload Media: Dominant color test plugin as a consumer of the operation API - #83332
Draft
swissspidy wants to merge 1 commit into
Draft
swissspidy wants to merge 1 commit into
swissspidy wants to merge 1 commit into
Conversation
An e2e test plugin that uses the public registration API the way a plugin would: one step planned before core/upload, a handler that reads the image in the browser and returns additionalData, and nothing that reaches into the queue. The color travels as a field of the upload request, which the plugin's PHP side accepts on the media endpoint, keeps as post meta and exposes on the attachment. The spec uploads the green fixture, half #00ff00 and the rest white at two opacities, and reads the color back through the REST API. It runs from outside the package, so it proves the script handle, the global, the plan placement, the handler contract and the additionalData route together, not just the store. Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ
🤖 PR meta 🤖📦 Bundle sizeSize Change: 0 B Total Size: 8.21 MB
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
See #82035. First of the step-3 proofs of concept for the upload operation API: a plugin that adds a step to the upload pipeline and sends what it computed to the server.
Stacked on #83331 (which is stacked on #82474). The diff here is only the test plugin and its spec.
Why?
The proposal's third step is to prove the API from a plugin before promoting anything to core. This is the smallest useful consumer: a
plan()that places a step beforecore/upload, a handler that reads the file in the browser and returnsadditionalData, and nothing that reaches into the queue. It validates, from outside the package:wp-upload-mediascript handle and thewp.uploadMediaglobal carry the API;plan()placement with{ before: 'core/upload' }, and skipping non-images;item.fileis the file as core prepared it — for HEIC that is the converted JPEG);additionalDatareturned by a handler reaches the server as a field of the create request.How?
packages/e2e-tests/plugins/upload-operation-dominant-color.phpregisters adominant_colorREST field on attachments (kept as post meta, validated as a lowercase hex color) and enqueues the script withwp-upload-mediaas a dependency.packages/e2e-tests/plugins/upload-operation-dominant-color/index.jsregistersgutenberg-test/dominant-color. The handler decodes the image withcreateImageBitmap, draws it at ≤64px onto anOffscreenCanvas, bins pixels by color (8 levels per channel) weighted by opacity, and returns the mean of the heaviest bin as{ additionalData: { dominant_color } }. A file the browser cannot decode returns nothing rather than failing the upload.test/e2e/specs/editor/various/upload-operation-dominant-color.spec.jsactivates the plugin, uploads10x10_e2e_test_image_green.pngthrough the Image block, drains the queue, and reads the attachment back through the REST API expectingdominant_color: '#00ff00'. The fixture is half#00ff00and the rest white at two opacities, so the answer is unambiguous but not trivial. A second test checks the operation is visible throughgetUploadOperation().Testing Instructions
npm run test:e2e -- test/e2e/specs/editor/various/upload-operation-dominant-color.spec.jsThe spec skips itself where client-side media processing is inactive, like the other upload specs. I could not run it locally (no Docker in this environment), so CI is the first run; the plugin JS and the spec pass eslint, the PHP passes phpcs.
Testing Instructions for Keyboard
N/A — no UI changes.
Screenshots or screencast
N/A.
Use of AI Tools
Authored with Claude Code: the plugin, the spec and this description.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ
Generated by Claude Code