Skip to content

Fixed: DELETE requests use query string instead of JSON body - #7

Merged
dennisdornon merged 1 commit into
mainfrom
fixing-delete-issues
Dec 18, 2025
Merged

dennisdornon merged 1 commit into
mainfrom
fixing-delete-issues

Conversation

@dennisdornon

@dennisdornon dennisdornon commented Dec 18, 2025 •

Copy link
Copy Markdown
Member

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

  • DELETE requests now use query string parameters instead of JSON body
  • Added isIdempotent annotation check - DELETE requires both destructive AND idempotent flags
  • All existing delete operations already have both annotations set correctly

Technical Notes

The change affects executeAbility() in src/abilities.ts. The condition changed from isDestructive to isDestructive && isIdempotent, and the request switched from JSON body to query string serialization (using the existing serializeToPhpQueryString function).

This matches how GET requests already handle parameters and aligns with WordPress REST API behavior for DELETE methods.

Testing

  • Added unit tests covering DELETE parameter serialization
  • Verified delete_site_v1, delete_client_v1, delete_tag_v1 work correctly with dry_run
  • Tested against local MainWP Dashboard

Summary by CodeRabbit

  • New Features

    • Added new abilities: delete-client, delete-tag, delete-site-plugins, delete-site-themes, and update-site operations
    • Enhanced destructive operations with improved request handling
  • Chores

    • Version bumped to 1.0.0-alpha.19

✏️ Tip: You can customize this high-level summary in your review settings.

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
@coderabbitai

coderabbitai Bot commented Dec 18, 2025 •

Copy link
Copy Markdown

Walkthrough

The PR introduces idempotent annotation support for abilities, adding a new idempotent flag to ability metadata. When an ability is both destructive and idempotent, it uses DELETE with query-string inputs; otherwise, existing GET/POST/DELETE routing applies. Version bumped from 1.0.0-alpha.15 to 1.0.0-alpha.19, with test fixtures expanded to cover 7 sample abilities.

Changes

Cohort / File(s) Summary
Version Updates
package.json, src/index.ts
Version bumped from 1.0.0-alpha.15 to 1.0.0-alpha.19 across manifest and server constants.
Core Ability Logic
src/abilities.ts
Added idempotent: boolean to AbilityAnnotations interface. HTTP method routing now treats destructive+idempotent abilities as DELETE with query-string inputs; read-only paths use GET, non-destructive writes use POST.
Test Fixtures & Data
tests/fixtures/abilities.json, src/abilities.test.ts, tests/integration/abilities.test.ts
Updated Delete Site ability to idempotent: true. Added five new sample abilities (delete-client-v1, delete-tag-v1, delete-site-plugins-v1, delete-site-themes-v1, update-site-v1). Test expectations adjusted from 2 to 7 total abilities; tests added for HTTP method selection rules and query-string serialization for DELETE requests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • HTTP method routing logic in src/abilities.ts requires careful verification of the destructive+idempotent condition and query-string handling path
  • Test assertions across multiple test files need validation, especially HTTP method verification and serialization expectations
  • Ability annotations on five new abilities should be checked for correctness and consistency
  • Fixture data alignment with test expectations (7 abilities, idempotent flags, etc.)

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: DELETE requests now use query string instead of JSON body, which directly addresses the core issue described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fixing-delete-issues

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9626510 and caa6600.

📒 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 idempotent field is correctly added to the AbilityAnnotations interface, aligning with the new ability metadata structure.


349-382: LGTM!

The logic correctly routes requests based on ability annotations:

  • readonly → GET with query string
  • destructive && 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 for idempotent between execution and documentation.

In generateToolHelp (line 514), idempotent defaults to true, but in executeAbility (line 351), it defaults to false. 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: true for delete-site-v1 is 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:

  1. Serialize input to query strings (input[site_id]=1, input[dry_run]=true)
  2. 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.

@dennisdornon
dennisdornon merged commit caa6600 into main Dec 18, 2025
5 checks passed
@dennisdornon
dennisdornon deleted the fixing-delete-issues branch October 6, 2026 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant