Harness mutation test

From Intense-Visions/harness-engineering · View interactive version

Harness mutation test is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Test quality validation through mutation testing. Introduces deliberate code mutations to verify that the test suite catches real bugs, exposing weak assertions, missing edge cases, and dead test co

How to use this skill

Skill file

Harness Mutation Test

Test quality validation through mutation testing. Introduces deliberate code mutations to verify that the test suite catches real bugs, exposing weak assertions, missing edge cases, and dead test code.

When to Use

Process

Phase 1: CONFIGURE -- Set Up Mutation Testing Framework

  1. Detect the project's language and test framework. Mutation testing tools are language-specific:
  1. Install and configure the mutation framework. Generate the configuration file:
  1. Define the scope. Mutation testing is expensive. Scope it:
  1. Set the mutation score threshold. Define the minimum acceptable score:
  1. Verify the test suite passes before mutating. Run the full test suite. All tests must pass. Mutation testing against a failing suite produces meaningless results.

Phase 2: GENERATE -- Create Mutants

  1. Run mutant generation in dry-run mode. List the mutations that will be applied without executing tests. Review:
  1. Review the mutant operators. Ensure the configured operators are relevant:
  1. Estimate execution time. Calculate:
  1. Filter out equivalent mutants (where possible). Some mutations produce functionally identical code (e.g., changing the order of commutative operations). Configure the framework to skip known equivalent patterns to reduce noise.

Phase 3: EXECUTE -- Run Tests Against Mutants

  1. Execute the mutation test run. Start the framework with the configured scope:

```

npx stryker run --concurrency 4

```

or

```

pitest:mutationCoverage

```

  1. Monitor progress. Track:
  1. Handle long-running mutations. If a single mutant takes longer than 3x the normal test timeout:
  1. Collect results. After completion, the framework produces:

Phase 4: ANALYZE -- Interpret Results and Improve Tests

  1. Review the overall mutation score. Compare against the threshold:
  1. Examine survived mutants. For each survived mutant, determine why the test suite did not catch it:
  1. Prioritize improvements by business impact. Focus on survived mutants in:
  1. Write targeted tests for the highest-priority survived mutants. For each:
  1. Generate an improvement report. Summarize:
  1. Run harness validate. Confirm the project passes all harness checks after test improvements.

Graph Refresh

If a knowledge graph exists at .harness/graph/, refresh it after code changes to keep graph queries accurate:

harness scan [path]

Harness Integration

Success Criteria

Examples

Example: Stryker Mutation Testing for a TypeScript Billing Module

CONFIGURE -- Stryker configuration:

// stryker.config.mjs
/** @type {import('@stryker-mutator/api/core').PartialStrykerOptions} */
export default {
  mutate: ['src/billing/**/*.ts', '!src/billing/**/*.test.ts'],
  testRunner: 'vitest',
  reporters: ['html', 'clear-text', 'progress'],
  coverageAnalysis: 'perTest',
  timeoutMS: 30000,
  concurrency: 4,
  thresholds: {
    high: 90,
    low: 80,
    break: 75,
  },
};

ANALYZE -- Survived mutant investigation:

Mutant #47: src/billing/calculate-discount.ts:23
  Original:  if (quantity >= 10) { discount = 0.15; }
  Mutation:   if (quantity > 10)  { discount = 0.15; }
  Status:    SURVIVED

Analysis: No test checks the boundary condition where quantity is exactly 10.
The existing test uses quantity=20 (well above threshold) and quantity=5 (below).

Fix -- Add boundary test:

// src/billing/calculate-discount.test.ts
it('applies 15% discount when quantity is exactly 10', () => {
  const result = calculateDiscount({ quantity: 10, unitPrice: 100 });
  expect(result.discount).toBe(0.15);
  expect(result.total).toBe(850);
});

it('does not apply discount when quantity is 9', () => {
  const result = calculateDiscount({ quantity: 9, unitPrice: 100 });
  expect(result.discount).toBe(0);
  expect(result.total).toBe(900);
});

Example: PIT Mutation Testing for a Java Service

CONFIGURE -- Maven PIT plugin:

<!-- pom.xml -->
<plugin>
  <groupId>org.pitest</groupId>
  <artifactId>pitest-maven</artifactId>
  <version>1.15.3</version>
  <configuration>
    <targetClasses>
      <param>com.example.orders.*</param>
    </targetClasses>
    <targetTests>
      <param>com.example.orders.*Test</param>
    </targetTests>
    <mutators>
      <mutator>CONDITIONALS_BOUNDARY</mutator>
      <mutator>NEGATE_CONDITIONALS</mutator>
      <mutator>RETURN_VALS</mutator>
      <mutator>MATH</mutator>
    </mutators>
    <mutationThreshold>80</mutationThreshold>
    <timestampedReports>false</timestampedReports>
  </configuration>
</plugin>

EXECUTE:

mvn org.pitest:pitest-maven:mutationCoverage
# Report generated at target/pit-reports/index.html

Rationalizations to Reject

| Rationalization | Why It Is Wrong |

| ---------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |

| "We have 80% line coverage, so test quality is already good" | Line coverage measures execution, not verification. Mutation testing reveals missing assertions and weak assertions. |

| "The survived mutants are in non-critical utility code, so we can ignore them" | Every survived mutant must be either addressed with a test or explicitly justified as an equivalent mutant. |

| "I will write a test that targets the specific mutation to kill it" | No gaming the mutation score. Every new test must test a meaningful behavior, not just kill a specific mutant. |

| "The test suite has some failures, but we can still run mutation testing to see what we learn" | No mutation testing against a failing test suite. Mutations against broken tests produce garbage results. |

Gates

Escalation

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.