From 29fefef648eff7ed771acd2c63c384c94f73b9c9 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Sat, 28 Nov 2026 23:42:27 +0400 Subject: [PATCH] fix(infection): keep a Rerun Failed Tests run's filters when it is mutated or replayed PhpStorm's final clone() round-trips the configuration through writeExternal, which drops the transient rerunFilters, so the mutation runner copies them back. The run archive stores them beside the serialized configuration, since that form leaves them out on both builds. Assisted-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + .../xepozz/testo/runs/TestoRunArchiver.kt | 24 +++++++++---------- .../xepozz/testo/runs/TestoRunManifest.kt | 2 ++ .../testo/runs/TestoRunReplayProfile.kt | 3 +++ .../coverage/TestoMutationProgramRunner.kt | 4 +++- .../TestoMutationProgramRunnerTest.kt | 23 ++++++++++++++++++ .../xepozz/testo/php/TestoPhpContractTest.kt | 16 +++++++++++++ 7 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunnerTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index fb61bd88..7209ac1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Starting a mutation run no longer reads the coverage report on the UI thread. - OpenIDE: a Coverage run says why it could not check for Xdebug or PCOV, and refuses to start when PHP cannot be started at all. +- *Run with Mutation* on a *Rerun Failed Tests* tab, and rerunning such a run from Test History, run the failed tests only instead of the whole suite. ## [2026.18] - 2026-11-27 diff --git a/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunArchiver.kt b/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunArchiver.kt index b815b6b6..cee88e5c 100644 --- a/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunArchiver.kt +++ b/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunArchiver.kt @@ -78,7 +78,6 @@ internal object TestoRunArchiver { configurationName = recording.configurationName, executorId = recording.executorId, commandLine = props.commandLine.orEmpty(), - configuration = serializeConfiguration(props), startedAt = recording.startedAt, finishedAt = finishedAt, workingDirectory = props.workingDirectory.orEmpty(), @@ -93,7 +92,7 @@ internal object TestoRunArchiver { interpreterType = configuration?.interpreterKind.orEmpty(), pluginVersion = pluginVersion(), testoVersion = props.testoVersion.orEmpty(), - ) + ).withConfiguration(configuration) recording.writeManifest(manifest) TestoRunStore.getInstance(project).prune() // The archive is the lens's whole source of truth, and it only just became complete — so the lens is @@ -154,17 +153,18 @@ internal object TestoRunArchiver { (javaClass.classLoader as? PluginAwareClassLoader)?.pluginDescriptor?.version.orEmpty() /** - * The run configuration as XML — the same form the IDE persists it in, so a replay can restore it and rerun the - * real thing. Empty when this console is not backed by a Testo configuration (nothing to rerun then). + * [configuration] as the IDE persists it, so a replay can restore it and rerun the real thing, plus the rerun + * filters that form leaves out. Unchanged when the console is not backed by a Testo configuration. */ - private fun serializeConfiguration(props: TestoConsoleProperties): String = - (props.configuration as? TestoConfiguration)?.let { configuration -> - runCatching { - val element = Element("configuration") - configuration.writeExternal(element) - JDOMUtil.write(element) - }.onFailure { LOG.warn("Failed to serialize the Testo run configuration", it) }.getOrNull() - }.orEmpty() + fun TestoRunManifest.withConfiguration(configuration: TestoConfiguration?): TestoRunManifest { + if (configuration == null) return this + val xml = runCatching { + val element = Element("configuration") + configuration.writeExternal(element) + JDOMUtil.write(element) + }.onFailure { LOG.warn("Failed to serialize the Testo run configuration", it) }.getOrNull().orEmpty() + return copy(configuration = xml, rerunFilters = configuration.selection.rerunFilters) + } /** * Copies one report into the run's `reports/`, and returns the run-dir-relative path of its **entry** (what the diff --git a/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunManifest.kt b/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunManifest.kt index a87d31c9..353057d6 100644 --- a/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunManifest.kt +++ b/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunManifest.kt @@ -46,6 +46,8 @@ data class TestoRunManifest( val commandLine: String = "", /** The run configuration as XML (`RunConfiguration.writeExternal`), so a replayed tab can rerun the real thing. */ val configuration: String = "", + /** A "Rerun Failed Tests" run's `--filter`s, which [configuration] never carries. */ + val rerunFilters: List = emptyList(), val startedAt: Long = 0, val finishedAt: Long = 0, val workingDirectory: String = "", diff --git a/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunReplayProfile.kt b/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunReplayProfile.kt index 63e43f49..2cb82876 100644 --- a/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunReplayProfile.kt +++ b/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunReplayProfile.kt @@ -213,6 +213,9 @@ internal fun restoreTestoConfiguration(project: Project, runDir: Path, manifest: runCatching { configuration.readExternal(JDOMUtil.load(xml)) } .onFailure { Logger.getInstance(TestoRunReplayProfile::class.java).warn("Failed to restore the run configuration of $runDir", it) } } + if (manifest.rerunFilters.isNotEmpty()) { + configuration.selection = configuration.selection.copy(rerunFilters = manifest.rerunFilters) + } configuration.name = manifest.configurationName.ifEmpty { runDir.fileName.toString() } return configuration } diff --git a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunner.kt b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunner.kt index 1cffeafd..32d913e0 100644 --- a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunner.kt +++ b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunner.kt @@ -12,10 +12,12 @@ class TestoMutationProgramRunner : TestoCoverageProgramRunner() { override fun canRun(executorId: String, profile: RunProfile): Boolean = executorId == TestoMutationExecutor.ID && profile is TestoRunConfiguration - override fun prepare(configuration: TestoRunConfiguration): TestoRunConfiguration = + // clone() goes through writeExternal, which leaves out a "Rerun Failed Tests" run's transient filters. + public override fun prepare(configuration: TestoRunConfiguration): TestoRunConfiguration = (configuration.clone() as TestoRunConfiguration).apply { testoSettings.runnerSettings.coverageXml = true testoSettings.runnerSettings.logJunit = true + testoSettings.runnerSettings.rerunFilters = configuration.testoSettings.runnerSettings.rerunFilters } override fun started(env: ExecutionEnvironment, properties: TestoConsoleProperties) = mutateAfterArchive(env, properties) diff --git a/src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunnerTest.kt b/src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunnerTest.kt new file mode 100644 index 00000000..77674d85 --- /dev/null +++ b/src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/coverage/TestoMutationProgramRunnerTest.kt @@ -0,0 +1,23 @@ +package com.github.xepozz.testo.phpstorm.coverage + +import com.github.xepozz.testo.phpstorm.tests.run.TestoRunConfiguration +import com.github.xepozz.testo.phpstorm.tests.run.TestoRunConfigurationType +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import com.jetbrains.php.testFramework.run.PhpTestRunnerSettings + +class TestoMutationProgramRunnerTest : BasePlatformTestCase() { + fun testMutatingARerunOfFailedTestsKeepsItsFilters() { + val rerun = TestoRunConfigurationType.INSTANCE.createTemplateConfiguration(project) as TestoRunConfiguration + rerun.testoSettings.runnerSettings.apply { + rerunFilters = listOf("\\App\\CalcTest::sum") + scope = PhpTestRunnerSettings.Scope.ConfigurationFile + } + + val mutated = TestoMutationProgramRunner().prepare(rerun).testoSettings.runnerSettings + + assertEquals(listOf("\\App\\CalcTest::sum"), mutated.rerunFilters) + assertEquals(PhpTestRunnerSettings.Scope.ConfigurationFile, mutated.scope) + assertTrue(mutated.coverageXml) + assertTrue(mutated.logJunit) + } +} diff --git a/src/test/kotlin/com/github/xepozz/testo/php/TestoPhpContractTest.kt b/src/test/kotlin/com/github/xepozz/testo/php/TestoPhpContractTest.kt index 7e3c573f..cbd56a09 100644 --- a/src/test/kotlin/com/github/xepozz/testo/php/TestoPhpContractTest.kt +++ b/src/test/kotlin/com/github/xepozz/testo/php/TestoPhpContractTest.kt @@ -1,6 +1,9 @@ package com.github.xepozz.testo.php import com.github.xepozz.testo.launch.TestoConfiguration +import com.github.xepozz.testo.runs.TestoRunArchiver +import com.github.xepozz.testo.runs.TestoRunManifest +import com.github.xepozz.testo.runs.restoreTestoConfiguration import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.util.io.FileUtil import com.intellij.psi.PsiDocumentManager @@ -8,6 +11,7 @@ import com.intellij.psi.PsiElement import com.intellij.psi.PsiFile import com.intellij.psi.util.PsiTreeUtil import com.intellij.testFramework.fixtures.BasePlatformTestCase +import java.nio.file.Path /** * What the plugin relies on from a PHP implementation, asked through [TestoPhp] only — the same questions any @@ -309,4 +313,16 @@ class TestoPhpContractTest : BasePlatformTestCase() { assertInstanceOf(factory.createTemplateConfiguration(project), TestoConfiguration::class.java) assertEquals("The type id saved configurations carry", "TestoRunConfiguration", factory.type.id) } + + fun testAReplayKeepsTheRerunFiltersTheSavedConfigurationDrops() { + val rerun = (php.configurationFactory().createTemplateConfiguration(project) as TestoConfiguration).apply { + selection = selection.copy(rerunFilters = listOf("\\App\\CalcTest::sum")) + } + val manifest = with(TestoRunArchiver) { TestoRunManifest().withConfiguration(rerun) } + + val restored = restoreTestoConfiguration(project, Path.of("run"), manifest) + + assertFalse("Saved configurations stay free of the filters", manifest.configuration.contains("CalcTest")) + assertEquals(listOf("\\App\\CalcTest::sum"), restored.selection.rerunFilters) + } }