You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Static mutants are activated too late when --testFiles produces a test filter #6144
With Stryker 9.6.1 and the Vitest runner, mutate a module-initialization value while selecting its covering test explicitly:
// static-value.tsexportconststaticValue=true
// static-value.spec.tsimport{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:
constcanHotSwap=!!testFilter&&isStatic===false
However, the generated run options choose runtime activation from testFilter alone:
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.
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:
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
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.
Activity
rhbra commentedon Oct 14, 2026
Same symptom with
@stryker-mutator/jest-runner10.0.0 (core 10.0.0, Jest 30.5.1), and it is not only the activation mode.With
ignoreStatic: false,coverageAnalysis: perTestand--testFiles <spec>, a static mutant (a module-levelconst X = '__', mutated to"") is planned withtestFilter: globalTestFilter, i.e. the spec's file path. The jest runner buildstestNamePatternfromtestFilter(jest-test-runner.js, each entryescapeRegExp'd), so the pattern Jest receives is the file path, matches no test name, and the mutant is reportedSurvivedwithtestsCompleted: 0("Ran 0.00 tests per mutant"). Trace log of the arguments Jest received:Findings:
--testFileshas no filter and isKilled(14 tests).mutantActivation: canHotSwap ? 'runtime' : 'static') leavesSurvived, 0 tests:testNamePatternis still the file path.testFilter: undefinedfor a static mutant givesKilled.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.
chore(mutation-gate): use plugin-side related-test discovery for the …
chore(mutation-gate): use plugin-side related-test discovery for the …
Mheaus commentedon Nov 9, 2026
I tested the two open fixes for this issue, #6145 and #6293, on a real project. Both fix the
--testFilescase. They differ on hybrid mutants withignoreStatic, where #6145 changes a result even without--testFiles.Setup:
@stryker-mutator/coreand@stryker-mutator/vitest-runner10.1.1, Vitest 5.1.0, Node 26.5.0,coverageAnalysis: "perTest",--concurrency 4.mutant-test-planner.tshas not changed since v10.1.1, so I applied each PR's change to theactivationline indist/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--ignoreStatic, file D, 3 runs each:--testFiles--testFilesThe mutant is a hybrid:
BlockStatement{}on the body of a small date helper that a module-level constant also calls, covered by 8 tests. WithignoreStatic, it gets a test filter from per-test coverage, andisStaticistrue. #6145 usescanHotSwap, which isfalsefor it, so it is now activated statically: the module-level call returnsundefined, the test file fails to load, and the mutant moves from Killed to RuntimeError. #6293 keeps runtime activation whenignoreStaticis set, which matches the current result.So, as far as these runs show, #6293 fixes this issue without changing the
perTest+ignoreStaticresults. Happy to run something else if useful.