Skip to content

Import abilities: register get-config + cleanup-meta via Registrar#48759

Draft
enejb wants to merge 1 commit into
trunkfrom
add/ship-import-abilities
Draft

Import abilities: register get-config + cleanup-meta via Registrar#48759
enejb wants to merge 1 commit into
trunkfrom
add/ship-import-abilities

Conversation

@enejb
Copy link
Copy Markdown
Member

@enejb enejb commented May 13, 2026

Summary

Adds the WordPress Abilities API surface for the automattic/jetpack-import package via a Registrar subclass. References plan §4.2 ("Ship Import abilities").

The Import package is the backend half of the WPCOM Unified Importer — a stateless set of /jetpack/v4/import/* REST endpoints. It has no job lifecycle (no queue, no persistent state, no list-of-jobs surface) and no agent-actionable start/cancel write surface beyond a per-entity create RPC that should not be exposed directly to agents. Per the ship task's "don't fabricate write endpoints" guidance, the abilities map only to endpoints that actually exist:

  • jetpack-import/get-config wraps /import/start::get_item() — returns { max_batch_items, max_execution_time, max_input_time, mime_types, posts_max_id, version }. Read-only, idempotent.
  • jetpack-import/cleanup-meta wraps /import/end::cleanup_database() — deletes the _jetpack_import_id rows from postmeta, commentmeta, termmeta. Destructive but idempotent (second call returns zeros).

Both abilities reuse the REST controller's current_user_can( 'import' ) gate exactly — no widening of the existing access surface. Registration is gated behind the shared jetpack_wp_abilities_enabled filter (defaults to false) inside Registrar::init(), so this rolls out opt-in per site.

The per-entity create endpoints (posts/pages/comments/menus/templates/…) are deliberately not exposed as abilities — they are a private RPC surface for the Unified Importer orchestrator, not direct-call surfaces for AI agents.

Notes

  • Wired via class-main.php::configure() (the package's existing bootstrap), mirroring the Stats package pattern. The Import package has no actions.php, so wiring lives in Main rather than a separate file.
  • Tests use Brain Monkey (added to require-dev) since the package has no WordPress test environment — mirrors the wp-abilities package's own RegistrarTest. 17 tests, 85 assertions.
  • New tests/.phpcs.dir.xml adopts the Jetpack-Tests ruleset so test-file naming + globals follow the relaxed test conventions used by the other ability-shipping packages.
  • A tiny WP_Error shim lives in tests/php/class-wp-error.php so the cleanup_meta() error path is testable without spinning up WordPress.

Test plan

  • cd projects/packages/import && composer phpunit -- --filter Import_Abilities_Test — 17/17 pass.
  • PHPCS clean on the added files.
  • On a site with add_filter( 'jetpack_wp_abilities_enabled', '__return_true' ), the WP abilities REST surface exposes the jetpack-import category with both abilities.
  • Calling jetpack-import/get-config as an admin returns the env snapshot; calling as a non-import user returns 403.
  • Calling jetpack-import/cleanup-meta after an import returns non-zero counts; a second call returns { ..., changed: false }.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the add/ship-import-abilities branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/ship-import-abilities

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • 🔴 Add a "[Status]" label (In Progress, Needs Review, ...).
  • 🔴 Add testing instructions.
  • 🔴 Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


🔴 Action required: Please include detailed testing steps, explaining how to test your change, like so:

## Testing instructions:

* Go to '..'
*

🔴 Action required: We would recommend that you add a section to the PR description to specify whether this PR includes any changes to data or privacy, like so:

## Does this pull request change what data or activity we track or use?

My PR adds *x* and *y*.

Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@github-actions github-actions Bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 13, 2026
@jp-launch-control
Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/import/src/class-main.php 0/29 (0.00%) 0.00% 1 ❤️‍🩹

1 file is newly checked for coverage.

File Coverage
projects/packages/import/src/abilities/class-import-abilities.php 105/109 (96.33%) 💚

Full summary · PHP report · JS report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Import [Status] In Progress [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant