Skip to content

Static mutants are activated too late when --testFiles produces a test filter #6144

Open

Description

@vasco

Reproduction

With Stryker 9.6.1 and the Vitest runner, mutate a module-initialization value while selecting its covering test explicitly:

// static-value.ts
export const staticValue = true
// static-value.spec.ts
import { expect, it } from 'vitest'
import { staticValue } from './static-value'
it('rejects the mutation', () => expect(staticValue).toBe(true))
stryker run --mutate static-value.ts --testFiles static-value.spec.ts

Set all mutation thresholds to 100. The Boolean substitution is reported as Survived even though the test imports and asserts the value. Without --testFiles, or with a dynamic mutant, activation works.

Root cause

MutantTestPlanner.planMutantTest correctly computes whether a mutant can be hot-swapped:

const canHotSwap = !!testFilter && isStatic === false

However, the generated run options choose runtime activation from testFilter alone:

mutantActivation: testFilter ? 'runtime' : 'static'

A static mutant with a test filter is therefore scheduled for runtime activation by the Vitest runner. Its module has already been imported by the time the runner's hook activates it, so the covered mutant survives incorrectly.

Proposed fix

Use the already-computed capability:

mutantActivation: canHotSwap ? 'runtime' : 'static'

This keeps runtime activation for non-static mutants with a test filter and activates static mutants before module loading.

I have a deterministic regression fixture and will submit the one-line fix with core tests.

Activity

  1. rhbra commented on Oct 14, 2026

    @rhbra

    Same symptom with @stryker-mutator/jest-runner 10.0.0 (core 10.0.0, Jest 30.5.1), and it is not only the activation mode.

    With ignoreStatic: false, coverageAnalysis: perTest and --testFiles <spec>, a static mutant (a module-level const X = '__', mutated to "") is planned with testFilter: globalTestFilter, i.e. the spec's file path. The jest runner builds testNamePattern from testFilter (jest-test-runner.js, each entry escapeRegExp'd), so the pattern Jest receives is the file path, matches no test name, and the mutant is reported Survived with testsCompleted: 0 ("Ran 0.00 tests per mutant"). Trace log of the arguments Jest received:

    "testNamePattern":"(/…/.stryker-tmp/sandbox-…/tests/unit/jobs/job\\-id\\.test\\.ts)"
    

    Findings:

    So for the jest runner the filter has to be dropped (or carried as files, not test ids) for a static mutant, in addition to #6145's activation change.

  2. Mheaus commented on Nov 9, 2026

    @Mheaus

    I tested the two open fixes for this issue, #6145 and #6293, on a real project. Both fix the --testFiles case. They differ on hybrid mutants with ignoreStatic, where #6145 changes a result even without --testFiles.

    Setup: @stryker-mutator/core and @stryker-mutator/vitest-runner 10.1.1, Vitest 5.1.0, Node 26.5.0, coverageAnalysis: "perTest", --concurrency 4. mutant-test-planner.ts has not changed since v10.1.1, so I applied each PR's change to the activation line in dist/src/mutants/mutant-test-planner.js. The reference for each file is the same run without --testFiles. I compared each mutant by mutator, location and replacement.

    --mutate <file> --testFiles <its test file>: mutants with a status different from the reference

    source file static mutants 10.1.1 #6145 #6293
    A (15 static, 13 killed in the reference) 15 13 (all killed static mutants survive) 0 0
    B (17 static, 5 killed) 17 5 0 0
    C (has hybrid mutants) 13 9 0 0
    D (has hybrid mutants) 14 9 0 0

    --ignoreStatic, file D, 3 runs each:

    10.1.1 #6145 #6293
    without --testFiles 0, 0, 0 1, 1, 1 0, 0, 0
    with --testFiles n/a 1, 1, 1 0

    The mutant is a hybrid: BlockStatement {} on the body of a small date helper that a module-level constant also calls, covered by 8 tests. With ignoreStatic, it gets a test filter from per-test coverage, and isStatic is true. #6145 uses canHotSwap, which is false for it, so it is now activated statically: the module-level call returns undefined, the test file fails to load, and the mutant moves from Killed to RuntimeError. #6293 keeps runtime activation when ignoreStatic is set, which matches the current result.

    So, as far as these runs show, #6293 fixes this issue without changing the perTest + ignoreStatic results. Happy to run something else if useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions