This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
This repository was archived by the owner on Feb 5, 2026. It is now read-only.

Add REST API controllers for Abilities API - #6

Merged
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration
Aug 14, 2025
Merged

Add REST API controllers for Abilities API#6
gziolo merged 13 commits into
WordPress:trunkfrom
emdashcodes:abilities-api-integration

Conversation

@emdashcodes

@emdashcodesemdashcodes commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

Closes#2.

This PR adds initial REST API endpoints to the Abilities API with support for both resource (GET) and tool (POST) type abilities.

How

Implements the following REST API endpoints:

  • WP_REST_Abilities_List_Controller - Handles listing abilities and retrieving individual abilities

    • GET /wp-json/wp/v2/abilities - List all registered abilities
    • GET /wp-json/wp/v2/abilities/{id} - Get a specific ability by ID
  • WP_REST_Abilities_Run_Controller - Handles executing abilities

    • GET/POST /wp-json/wp/v2/abilities/{id}/run - Execute an ability (method depends on ability type)
      • Resources use GET
      • Tools use POST

Testing Steps

  1. Make sure all unit tests pass

If you enable the Ability API as a plugin:

  1. Test listing abilities: GET /wp/v2/abilities
  2. Test getting a specific ability: GET /wp/v2/abilities/{id}
  3. Test executing a resource ability: GET /wp/v2/abilities/{id}/run
  4. Test executing a tool ability: POST /wp/v2/abilities/{id}/run

@emdashcodes
emdashcodes marked this pull request as draft August 12, 2025 15:48
@emdashcodesemdashcodes changed the title Add REST API controllers for Abilities API[WIP] Add REST API controllers for Abilities APIAug 12, 2025
@gziologziolo added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Aug 12, 2025
@emdashcodesemdashcodes changed the title [WIP] Add REST API controllers for Abilities APIAdd REST API controllers for Abilities APIAug 13, 2025
@emdashcodes
emdashcodes marked this pull request as ready for review August 13, 2025 02:28
Comment threadabilities-api.php Outdated
@gziolo
gziolo self-requested a review August 13, 2025 04:48
@gziolo
gziolo deleted the branch WordPress:trunkAugust 13, 2025 04:58
@gziologziolo closed this Aug 13, 2025
@gziolo

Copy link
Copy Markdown
Member

I landed #3, which triggered GitHub automations, and accidentally closed this PR after the target branch got deleted 😅

I'll try to fix it.

@gziologziolo reopened this Aug 13, 2025
@gziolo
gziolo changed the base branch from add/server-side-registry to trunkAugust 13, 2025 05:02
@gziolo

Copy link
Copy Markdown
Member

Reopened and changed the base branch, but it will require a rebase to remove my commits from the list of changes.

Comment threadabilities-api.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-init.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
Comment threadtests/unit/REST/WPRESTAbilitiesListControllerTest.php

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all the code and tests for the list controller and left my feedback inline. I still need to check the run controller. Everything is looking great, my feedback is mostly about minor things or I had some questions/notes where I wasn't entirely sure how it works.

My only high-level, important feedback is around using a single form: id or name to uniquely identify the ability.

@gziolo
gziolo requested a review from CopilotAugust 13, 2025 11:12

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements REST API controllers for the Abilities API, enabling web-based access to both resource and tool type abilities through standardized endpoints.

Key Changes:

  • Added two REST API controllers (WP_REST_Abilities_List_Controller and WP_REST_Abilities_Run_Controller) with full test coverage
  • Implemented HTTP method validation where resource abilities use GET and tool abilities use POST
  • Added comprehensive validation for input/output schemas and permission checks

Reviewed Changes

Copilot reviewed 16 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
src/rest/class-wp-rest-abilities-list-controller.phpImplements endpoints for listing and retrieving individual abilities
src/rest/class-wp-rest-abilities-run-controller.phpHandles ability execution with method validation and comprehensive error handling
src/rest/class-wp-rest-abilities-init.phpInitializes and registers REST API routes on the rest_api_init hook
tests/unit/REST/WPRESTAbilitiesListControllerTest.phpComprehensive test coverage for list controller including pagination and permissions
tests/unit/REST/WPRESTAbilitiesRunControllerTest.phpExtensive test coverage for run controller including method validation and error handling
Various test and configuration filesSupporting infrastructure for unit testing and development

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php Outdated
Comment threadsrc/rest/class-wp-rest-abilities-run-controller.php
Fixed REST controller calling non-existent get_execute_callback() method.
Always show run link for abilities in REST responses.
- Register run controller before list controller to fix route precedence
- Support both GET (resources) and POST (tools) methods based on ability type
- Add TODO comment explaining load order issue with ALLMETHODS
- Remove result wrapper to match Feature API response format
- Handle query params for GET requests and JSON body for POST
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from f98cb4c to a15939dCompareAugust 13, 2025 14:42
@codecov

codecovBot commented Aug 13, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.10429% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@c40f122). Learn more about missing BASE report.

Files with missing linesPatch %Lines
...rc/rest/class-wp-rest-abilities-run-controller.php81.57%28 Missing ⚠️
abilities-api.php0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## trunk #6 +/- ##
========================================
Coverage ? 90.32% Complexity ? 103 ========================================
Files ? 7 Lines ? 558 Branches ? 0 ========================================
Hits ? 504 Misses ? 54 Partials ? 0 
FlagCoverage Δ
unit90.32% <91.10%> (?)

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.

PHPStan fixes:
- Add return type annotations for void methods
- Add array type hints for array parameters and returns
- Cast integer header values to strings (PHPStan stubs expect strings)
- Add ignore rule for WP_REST_Request generic types with explanation
PHPCS compliance:
- Add file documentation headers to all REST API files
- Use fully qualified class names in PHPDoc comments
- Add 'abilities-api' domain to all translation functions
- Fix array alignment and spacing issues
- Fix short ternary operators to explicit conditionals
- Add periods to inline comments
- Simplify elseif logic in run controller
Type hints and modern PHP:
- Add native PHP type hints where compatible with PHP 7.4+
- Add WP_REST_Abilities prefix to allowed prefixes in PHPCS config
- Use native return types (void, array, bool) and parameter types
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from e1ac3e8 to 1af315dCompareAugust 13, 2025 15:45
- Add array<string, mixed> type hint for get_input_from_request return
- Add public visibility to DEFAULT_PER_PAGE constant
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 9008781 to db79c0dCompareAugust 13, 2025 19:10
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from db79c0d to 0180c4aCompareAugust 13, 2025 19:25
Comment threadphpstan.neon.dist
@emdashcodes

Copy link
Copy Markdown
ContributorAuthor

I've addressed the static analysis and PHPCS issues from this branch. The remaining ones seem to be on trunk.

Comment threadsrc/rest/class-wp-rest-abilities-list-controller.php Outdated
- Add test coverage for REST API controllers (List, Run, Init)
- Add tests for uncovered lines in run controller (29 lines)
- Add tests for init class route registration
- Add malformed input tests for edge cases
- Remove PHP type hints from REST controllers for WordPress compatibility
- Fix test expectations to match WordPress REST API behavior
- Use PHPUnit data providers for better test organization
- Fix HTTP method validation tests
- Add missing @return documentation tag
Test coverage improvements:
- WPRESTAbilitiesRunControllerTest: Full coverage with input validation, permissions, HTTP methods
- WPRESTAbilitiesListControllerTest: Pagination, special characters, invalid parameters
- WPRESTAbilitiesInitTest: Route registration and controller instantiation
All tests passing (105 tests, 246 assertions)
@emdashcodes
emdashcodesforce-pushed the abilities-api-integration branch from 0fe00d5 to 9b071cbCompareAugust 13, 2025 20:44
- WordPress core's WP_REST_Controller doesn't have type hints on methods
- Adding type hints causes fatal errors due to signature mismatch
- Exclude Squiz.Commenting.FunctionComment.TypeHintMissing for REST controllers
- Also exclude Slevomat type hint rules for consistency
- This is a common WordPress compatibility issue
* @return \WP_REST_Response|\WP_Error Response object on success, or WP_Error object on failure.
*/
public function get_item( $request ) {
$ability = wp_get_ability( $request['name'] );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to use WP_REST_Request->get_param() (/ ->get_params() elsewhere )?

We lose the rest_request_parameter_order filter by relying on \ArrayAccess

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both forms used in REST API controllers included in WP core, sometimes even in the same handler 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gziolo I think that's a sign of tech debt, not an endorsement of pattern 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can update to use get_param() 👍🏻

Will you take care of it?

Comment threadphpcs.xml.dist

@gziologziolo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for rebasing with trunk and addressing all feedback. I see the increased unit tests coverage added in 9b071cb 👏🏻

Let's land it in the current shape and address the code quality configuration challenges seperately. I also plan to open follow-up issues for TODO items included in the codebase.

Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

[Type] TaskIssues or PRs that have been broken down into an individual action to take

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement REST API controller that exposes registered abilities

5 participants

@emdashcodes@gziolo@swissspidy@justlevine