Skip to content

Forms: Add ability output schemas#49954

Open
DevinWalker wants to merge 1 commit into
trunkfrom
add/forms-abilities-output-schemas
Open

Forms: Add ability output schemas#49954
DevinWalker wants to merge 1 commit into
trunkfrom
add/forms-abilities-output-schemas

Conversation

@DevinWalker

@DevinWalker DevinWalker commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fixes JETPACK-1770

This PR is open because Forms is already the strongest Jetpack Abilities API integration, and agents need dependable response shapes to use it safely. It keeps the change limited to output contracts and a small no-op guard so the broader rollout can stay reviewable.

This follows the WordPress wp_register_ability() documentation: schemas define the expected structure of ability inputs and outputs, support validation, and make the API contract self-documenting for developers and tools.

Proposed changes

  • Add explicit output schemas for the Jetpack Forms abilities so agent clients can reason about response shapes.
  • Tighten jetpack-forms/update-response so calls must include a mutation field, matching the declared object output contract.
  • Return the admin edit URL from jetpack-forms/get-form instead of the public permalink.
  • Strengthen Forms ability tests for public metadata, output schemas, no-op update handling, and edit URL behavior.

Related product discussion/links

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

No.

Testing instructions

  • From projects/packages/forms, run:
    • php vendor/bin/phpunit-select-config phpunit.#.xml.dist --colors=always tests/php/abilities/Forms_Abilities_Test.php
  • Confirm the test passes with 30 tests, 227 assertions.
  • Optional broader check: CI=true jp test php packages/forms -v currently reaches PHPUnit but fails in existing webhook localhost tests unrelated to these Forms abilities changes.

@DevinWalker DevinWalker added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. labels Jun 25, 2026
@DevinWalker DevinWalker self-assigned this Jun 25, 2026
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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/forms-abilities-output-schemas branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack add/forms-abilities-output-schemas

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 🤖


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!

@jp-launch-control

Copy link
Copy Markdown

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/forms/src/abilities/class-forms-abilities.php 600/651 (92.17%) 1.56% 0 💚

Full summary · PHP report · JS report

@DevinWalker DevinWalker marked this pull request as ready for review June 25, 2026 19:56
@DevinWalker DevinWalker requested review from enejb and simison June 25, 2026 19:56
@simison simison requested a review from nerrad June 25, 2026 20:02
@enejb

enejb commented Jun 26, 2026

Copy link
Copy Markdown
Member

Review — standard depth (296 lines, 1 project). No blockers; the change is correct and consistent with existing patterns. Three non-blocking suggestions, all around schema-vs-reality fidelity and test coverage of the new contracts.

  1. [suggestion] update-response output_schema likely doesn't match the actual return shape. The execute callback returns the raw merged REST data from POST /wp/v2/feedback/{id} and /feedback/{id}/read, not a curated { id, status, is_unread, count } object. test_every_ability_declares_output_schema_for_current_return_shape only asserts the declared property types, never that a real return conforms — so the schema can drift from reality unnoticed. Since this is the contract agents reason about, consider verifying it against an actual dispatch result (or documenting that extra properties may appear).

    'output_schema' => array(
    'type' => 'object',
    'properties' => array(
    'id' => array( 'type' => 'integer' ),
    'status' => array( 'type' => 'string' ),
    'is_unread' => array( 'type' => 'boolean' ),
    'count' => array( 'type' => 'integer' ),
    ),
    ),
    'execute_callback' => array( __CLASS__, 'update_form_response' ),
    'permission_callback' => array( __CLASS__, 'can_edit_pages' ),
    'meta' => array(

  2. [suggestion] get-responses output_schema is array of bare object with no properties — it documents almost nothing for the one ability whose payload (sender info, fields, metadata) an agent most needs to understand. If the shape is stable enough, declaring a few top-level keys would make the contract useful; otherwise a comment noting the intentional looseness would help future maintainers.

    'output_schema' => array(
    'type' => 'array',
    'items' => array(
    'type' => 'object',
    ),
    ),

  3. [suggestion] Behavioral change worth calling out: update-response now returns WP_Error('missing_update') for an id-only call that previously returned an empty-array no-op. Intentional and reasonable, but the class's own init() docblock stresses not silently breaking existing consumers — worth confirming no caller relies on the old no-op. Also, the new anyOf input-schema constraint isn't directly tested (only the execute-callback guard is); a one-line test that input validation rejects { id } would pin the anyOf + additionalProperties: false combination.

    if ( ! isset( $args['status'] ) && ! isset( $args['is_unread'] ) ) {
    return new \WP_Error( 'missing_update', __( 'Provide a status or read state to update.', 'jetpack-forms' ) );
    }

@simison simison removed their request for review June 26, 2026 07:17
@DevinWalker DevinWalker removed the request for review from nerrad June 26, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Feature] Contact Form [Package] Forms [Status] In Progress [Status] Needs Review This PR is ready for review. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants