fix(logging): register the operation REST filter param#758
fix(logging): register the operation REST filter param#758i-anubhav-anand wants to merge 1 commit into
Conversation
The /ai/v1/logs endpoint reads and applies an `operation` filter (sent by the Request Log admin UI as a comma-separated string and parsed with explode()), but it was the only filter parameter missing from get_collection_params(). As a result it was absent from the REST schema and bypassed the framework's argument validation, so a non-string value (e.g. operation[]=a&operation[]=b) reached explode() and raised a TypeError, returning a 500. Register `operation` as a string collection param, matching the documented comma-separated contract. WordPress now validates the type before the value reaches the repository, and the parameter is discoverable in the REST schema like every sibling filter.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #758 +/- ##
=============================================
+ Coverage 74.45% 76.26% +1.80%
- Complexity 1740 1765 +25
=============================================
Files 85 85
Lines 7521 7596 +75
=============================================
+ Hits 5600 5793 +193
+ Misses 1921 1803 -118
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@i-anubhav-anand is this still in progress or can it come out of draft for review? |
What?
Registers the
operationquery parameter on the AI Request Log REST endpoint (/ai/v1/logs).operationis read and applied as a filter server-side and is sent by the Request Log admin UI, but it was the only filter parameter missing fromAI_Request_Log_Controller::get_collection_params().Why?
Because the parameter was unregistered:
It bypassed the REST framework's argument validation. The repository parses it as a comma-separated string:
The admin UI always sends a string (
operations.join(',')), but the public endpoint accepts whatever a client sends. A non-string value reachesexplode()and raises a fatal:It was missing from the REST schema, so API consumers couldn't discover it via schema introspection — unlike every sibling filter (
type,status,provider,search, …).How?
Add
operationtoget_collection_params()as astringparameter, matching the documented comma-separated contract. WordPress then validates the type before the value reaches the repository (a non-string value is rejected with a 400 instead of fataling), and the parameter is now part of the endpoint schema.This is a one-parameter, surgical change; no behavior changes for the existing (string) filter path.
Use of AI Tools
AI assistance: Yes
Tool(s): AI coding assistant (agentic CLI)
Used for: auditing the REST controller/repository, reproducing the bug, and drafting the fix + tests. All code was written test-first, executed, and reviewed by me; I take responsibility for it.
Testing Instructions
Added/extended tests in
tests/Integration/Includes/Logging/AI_Request_Log_ControllerTest.php:test_get_collection_params_returns_expected_keys— now also assertsoperationis a registered param.test_get_logs_filters_by_operation— the filter returns only matching rows (baseline; passes before and after).test_get_logs_rejects_non_string_operation— an arrayoperationvalue is handled with a 400 rather than a fatal.Fail-before / pass-after (source registration reverted, tests kept):
Full Logging suite is green (122 tests); full integration suite is green (840 tests, 34 pre-existing skips).
Changelog Entry