Abilities: Add validation tests pinning behavior for WP-specific schema keywords#78783
Abilities: Add validation tests pinning behavior for WP-specific schema keywords#78783gziolo wants to merge 3 commits into
Conversation
…ma keywords Document via tests how the client-side validator currently behaves when schemas contain keywords that are valid in WordPress server schemas but not in JSON Schema draft-04: sanitize_callback, validate_callback, arg_options, example, examples, and the per-arg boolean `required` flag. All of these currently fail AJV compilation and surface as a generic "Invalid schema provided for validation." error. Pinning that so any future change to strip or ignore those keywords becomes a visible diff. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
…ation tests `context` (per-field availability across view/edit/embed) and lowercase `readonly` (server-computed fields) are the two most common WordPress REST schema keywords that aren't part of JSON Schema draft-04 and would realistically leak into ability input/output schemas. AJV strict mode rejects both at compile time, matching the failure mode already pinned for `sanitize_callback`, `validate_callback`, `arg_options`, etc. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
The eight WP-specific / non-draft-04 keywords share an identical failure mode (compile-time rejection -> "Invalid schema provided for validation."). Drive them from a single tuple table instead of copy-pasting the same setup eight times, matching how the rest of the codebase parameterises similar tests (e.g. wp-compat-overlay-slot, global-styles-engine/utils). One standalone test still pins the same behavior at the top level of the schema. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Size Change: 0 B Total Size: 8.18 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 5eb5956. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26582131125
|
Summary
Extend
packages/abilities/src/tests/validation.test.tswith a newWordPress-specific schema keywordsgroup that pins how the client-side validator currently behaves when aninput_schema/output_schemacontains keywords that are valid on WordPress REST API schemas but not on JSON Schema draft-04 (which the AJV instance inpackages/abilities/src/validation.tstargets):sanitize_callback,validate_callback,arg_options— server-only WordPress keywords (the last one comes fromregister_meta())context— REST response-shaping keyword (['view', 'edit', 'embed'])readonly(lowercase, WordPress style) — marks server-computed fields, common on output schemasexample/examples— OpenAPI / draft-06+ documentation fieldsrequired: true— the boolean per-arg form used by WordPress REST argument definitions (JSON Schema expects an array of property names)In every case the validator currently returns
'Invalid schema provided for validation.'and logs toconsole.error, because AJV strict mode rejects the keyword at compile time (or, for booleanrequired, fails the meta-schema check). The tests are driven from a singleit.eachtable so the eight keywords share one body, matching the parameterised-test convention used elsewhere in the codebase (wp-compat-overlay-slot.test.ts,global-styles-engine/utils.test.ts, etc.).Goal: unify handling with WordPress core
This PR is the client-side counterpart to WordPress/wordpress-develop#11997, which hardens the Abilities REST controller by switching to an allow-list of schema keywords — stripping the same WordPress-internal keys (
sanitize_callback,validate_callback,arg_options,examples, …) before they leave the server.Together the two PRs converge on a single rule for what client validation sees:
No production code changes here.
Test plan
npm run test:unit -- --testPathPattern="packages/abilities/src/tests/validation"— 48 tests passnpm run lint:js -- packages/abilities/src/tests/validation.test.ts— cleannpm run format -- packages/abilities/src/tests/validation.test.ts— no diff🤖 Generated with Claude Code