Index of every page on this site: llms.txt
All skills
soderlind avatar

/wp-mutate

@ba09e3b
Run it yourself

Run mutation testing on WordPress plugins and themes to find weak tests — Pest --mutate or Infection for PHP, StrykerJS for JavaScript — then triage surviving mutants into concrete test improvements.

Use this Skill: https://skilld.dev/gh/soderlind/skills/wp-mutate

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestriage-playbook.md

≈1.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Triage Playbook

How to turn a surviving mutant into a test that would have caught it.

The rule that governs every entry below

A survivor tells you which line lacks an assertion. It does not tell you what the assertion should say. Derive that from intended behaviour — a requirement, the plugin's documentation, an existing test's stated intent, or the function's contract.

If intent cannot be established, report the survivor as needs human judgement. Do not assert whatever the code currently returns. That kills the mutant, tests nothing, and breaks on the next legitimate refactor.

Mutant kind → killing assertion

Mutant kind What survival proves Assertion that kills it
Return value (return $x → return null / [] / 0) Nothing inspects the return value Assert on the returned value, not just that no exception was thrown
Conditional boundary (> → >=) No test sits on the boundary Test at the boundary and one either side
Negation / true-false (if ($x) → if (true)) Only one branch is tested Test the other branch, especially the rejection path
Method call removal The call has no observable effect in tests Assert the side effect: stored value, emitted action, escaped output
Arithmetic (+ → -) The computed value is never checked Assert the exact computed result, not merely its type
Logical operator (&& → ||) Only one combination of operands is tested Add cases where the operands differ
String literal The string is never asserted Assert the exact key, slug, capability, or option name
Array item removal Collection contents are unchecked Assert membership and length, not just emptiness
Increment / decrement Off-by-one is undetectable Assert exact counts and offsets
Default parameter The default is never exercised Call the function without the argument and assert the result

Tier 1 — security-control survivors

These are the reason to run mutation testing on a WordPress plugin at all.

Capability check

public function save_settings(): void {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    update_option( 'acme_settings', $this->sanitize( $_POST['acme'] ?? [] ) );
}

A survivor on the condition means no test proves an unauthorized user is blocked. Coverage was green because the authorized test walked the line.

it( 'refuses to save settings without manage_options', function () {
    // subscriber-level user
    $this->settings->save_settings();

    expect( get_option( 'acme_settings' ) )->toBeFalse();
} );

Assert the absence of the side effect. A test that merely calls the method and expects no exception kills nothing.

Nonce verification

if ( ! wp_verify_nonce( $_POST['_wpnonce'] ?? '', 'acme_save' ) ) {
    wp_die( esc_html__( 'Invalid request.', 'acme' ) );
}

Kill it with a request carrying a missing, wrong-action, and expired nonce — three cases, each asserting the rejection.

Escaping and sanitization

echo '<span>' . esc_html( $label ) . '</span>';

A removed esc_html() survives whenever the fixture is a boring ASCII string. Use a payload that renders differently when unescaped:

it( 'escapes the label', function () {
    $output = $this->renderer->render( '<script>alert(1)</script>' );

    expect( $output )->not->toContain( '<script>' );
    expect( $output )->toContain( '&lt;script&gt;' );
} );

The same applies to sanitize_text_field(), wp_kses_post(), and absint() — assert the transformed value with input that actually needs transforming.

Prepared statements

A survivor around $wpdb->prepare() usually means the query is asserted as a whole string rather than by its bound arguments. Assert the arguments, and include a fixture containing a quote character.

Tier 2 — data-integrity survivors

  • update_option / delete_option — assert the stored value and the exact option name. A string-literal mutant on the key survives any test that reads back through the same constant.
  • *_post_meta — assert single vs array retrieval; get_post_meta() with the wrong $single flag hides plenty of mutants.
  • set_transient — assert the expiry argument, not only the value.
  • Serialization — round-trip through the real store, not a mock, or the format mutant survives.

Tier 3 — hook-wiring survivors

add_action( 'init', [ $this, 'register_post_type' ], 20, 1 );

Priority and accepted_args mutants survive unless the test asserts them:

it( 'registers the post type at priority 20', function () {
    expect( has_action( 'init', [ $this->plugin, 'register_post_type' ] ) )->toBe( 20 );
} );

has_action() returns the priority, not true, when the callback is attached — which is exactly what makes this assertable. Priority matters whenever the plugin must run before or after another; if it genuinely does not matter, this is an equivalent mutant, so suppress it with that reason.

JavaScript

export function formatPrice( cents, currency = 'USD' ) {
  if ( cents < 0 ) {
    return null;
  }
  return new Intl.NumberFormat( 'en-US', { style: 'currency', currency } ).format( cents / 100 );
}

Typical survivors and their fixes:

  • cents < 0 → cents <= 0: add a 0 case and assert '$0.00', not null.
  • cents / 100 → cents * 100: assert the exact formatted string.
  • Default 'USD' removed: call formatPrice( 1000 ) with no second argument.
  • return null → return undefined: assert toBeNull(), not toBeFalsy().

That last one generalises: loose assertions (toBeTruthy, toBeDefined, not.toThrow) are the single largest source of survivors in any suite.

Recognising an equivalent mutant

Suppress, with a written reason, when the mutation cannot change observable behaviour:

  • The mutated value is discarded ($i++ → ++$i on an unused result).
  • A defensive guard that no reachable input can trigger.
  • A short-circuit reordering where both operands are pure and cheap.
  • Log or debug text with no assertable consequence.
  • Hook priority where ordering is genuinely irrelevant.

Before suppressing, try once to construct the input that distinguishes the two versions. If that input exists, it is not equivalent — it is a missing test.

When to stop

Stop triaging a file when the remaining survivors are all equivalent or all require production-code redesign to become testable. Record what is left and why. Driving the score to 100% is not the goal; knowing which untested behaviour you are choosing to accept is.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The wp-mutate skill automates mutation testing for WordPress projects by integrating tools like Pest, Infection, and StrykerJS. It uses a helper script to detect environmental configurations by executing the local PHP binary. The skill analyzes repository source files to provide triage for testing gaps. The analysis identified command execution capabilities and potential indirect prompt injection surfaces, but no malicious intent or data exfiltration was found.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at ba09e3b. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 3 months ago
version
1.0.0
Other metadata
compatibility
WordPress plugin/theme projects with an existing PHP test suite (Pest 3+ or PHPUnit) and/or JS tests (Vitest or Jest). Requires Xdebug 3+ with coverage mode or PCOV for PHP.

README badge

README badge for soderlind/skills/wp-mutate