Repository navigation
Fixed: DELETE requests use query string instead of JSON body - #7
Conversation
WP Abilities API doesn't parse DELETE request bodies, causing delete operations to fail. Changed to send parameters via URL query string (matching GET behavior). - Added isIdempotent check: DELETE now requires both destructive AND idempotent annotations (all delete operations meet this criteria) - Updated serializeToPhpQueryString usage for DELETE requests - Added comprehensive tests for all delete operations - Bumped version to 1.0.0-alpha.19
WalkthroughThe PR introduces idempotent annotation support for abilities, adding a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
tests/integration/abilities.test.ts (1)
210-233: LGTM!Test description and comments correctly reflect the updated semantics. The test verifies DELETE is used for destructive + idempotent abilities.
Consider adding a test case for a destructive but non-idempotent ability to verify it falls back to POST instead of DELETE.
src/abilities.test.ts (1)
467-470: Consider testing both integer and string types for client_id_or_email.The schema allows
type: ['integer', 'string']for this parameter, but only the integer type is tested. While not critical for verifying DELETE method selection, testing both types would improve coverage of the query string serialization logic.Optional: Add a test for string type
You could add an additional test case:
it('should handle string identifiers in DELETE requests', async () => { mockFetch.mockResolvedValueOnce({ ok: true, json: async () => sampleAbilities, headers: new Headers(), }); mockFetch.mockResolvedValueOnce({ ok: true, json: async () => ({ deleted: true }), headers: new Headers(), }); await executeAbility(baseConfig, 'mainwp/delete-client-v1', { client_id_or_email: 'user@example.com', confirm: true, }); const calls = mockFetch.mock.calls; const url = calls[1][0] as string; expect(url).toContain('input[client_id_or_email]=user@example.com'); });
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
package.json(1 hunks)src/abilities.test.ts(9 hunks)src/abilities.ts(2 hunks)src/index.ts(1 hunks)tests/fixtures/abilities.json(1 hunks)tests/integration/abilities.test.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/abilities.test.ts (1)
src/abilities.ts (1)
executeAbility(329-430)
🔇 Additional comments (10)
src/index.ts (1)
50-50: LGTM!Version bump is consistent with package.json and aligns with the functional changes introduced in this PR.
package.json (1)
3-3: LGTM!Version bump is consistent with src/index.ts and reflects the functional changes in this PR.
src/abilities.ts (3)
31-36: LGTM!The
idempotentfield is correctly added to theAbilityAnnotationsinterface, aligning with the new ability metadata structure.
349-382: LGTM!The logic correctly routes requests based on ability annotations:
readonly→ GET with query stringdestructive && idempotent→ DELETE with query string (fixes the WP Abilities API body parsing issue)- Otherwise → POST with JSON body
This properly addresses the PR objective while maintaining correct HTTP semantics.
511-516: Inconsistent default foridempotentbetween execution and documentation.In
generateToolHelp(line 514),idempotentdefaults totrue, but inexecuteAbility(line 351), it defaults tofalse. This could lead to help documentation suggesting an ability is idempotent when execution treats it as non-idempotent.Consider aligning the defaults, or verify this discrepancy is intentional for different use cases (documentation vs. execution safety).
tests/fixtures/abilities.json (1)
74-80: LGTM!Setting
idempotent: truefordelete-site-v1is semantically correct—deleting a resource twice has the same effect as deleting it once. This enables the ability to use the DELETE method with query string parameters as intended by the PR.src/abilities.test.ts (4)
63-177: LGTM! Comprehensive test fixture expansion.The test fixtures correctly model the new ability set with proper annotations:
- All DELETE operations marked as
destructive: true, idempotent: true- Non-destructive write (update-site-v1) marked as
destructive: false, idempotent: true- Input schemas include appropriate safety parameters (confirm, dry_run) for destructive operations
The comments on lines 63, 85, 107, 130, 153 clearly document the DELETE routing behavior.
225-225: LGTM! Test expectations correctly updated.All assertions properly updated to reflect the expanded ability set (7 total abilities, 5 in mainwp-sites category).
Also applies to: 272-272, 301-301, 743-743, 770-770
410-582: LGTM! Comprehensive HTTP method routing tests.Excellent test coverage for the new routing logic:
- GET for readonly abilities (line 413-433)
- DELETE for destructive + idempotent abilities (lines 435-539) - all 5 delete operations tested
- POST for non-destructive writes (lines 541-558)
- Query string serialization explicitly verified for DELETE (lines 560-582)
The test at lines 560-582 correctly verifies that DELETE requests:
- Serialize input to query strings (
input[site_id]=1,input[dry_run]=true)- Don't include a request body (
expect(calls[1][1].body).toBeUndefined())This aligns perfectly with the PR objective to fix DELETE parameter handling.
738-780: LGTM! Help document tests correctly updated.The help document generation tests properly reflect the expanded ability set and category grouping.
Summary
WP Abilities API does not parse DELETE request bodies. Delete operations (sites, clients, tags, plugins, themes) were failing silently because parameters sent in the request body were ignored. Changed DELETE requests to send parameters via URL query string.
Key Improvements
isIdempotentannotation check - DELETE requires both destructive AND idempotent flagsTechnical Notes
The change affects
executeAbility()insrc/abilities.ts. The condition changed fromisDestructivetoisDestructive && isIdempotent, and the request switched from JSON body to query string serialization (using the existingserializeToPhpQueryStringfunction).This matches how GET requests already handle parameters and aligns with WordPress REST API behavior for DELETE methods.
Testing
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.