diff --git a/CHANGELOG.md b/CHANGELOG.md index 7209ac1e..3854b223 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ - 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. +- *Rerun Failed Tests* works on a run opened from Test History. +- A run configuration that changes only Testo's own settings, such as a group, keeps them when saved. ## [2026.18] - 2026-11-27 diff --git a/CLAUDE.md b/CLAUDE.md index d7d26dd9..3aee27a3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -715,6 +715,9 @@ Non-obvious constraints already paid for in blood — read before touching the r - **`getVersion()` of both file-based indexes** (`TestoDataProvidersIndex`, `TestoGroupsIndex`) must be bumped whenever indexing logic changes — for the groups index that includes `groupNamesOf` (`TestoAttributes.kt`), which it indexes through — or stale on-disk indexes silently stay empty. +- **A new persisted `TestoRunnerSettings` field goes into its `persisted()` list.** Saving skips runner settings that + `equals` the defaults, and the PHP plugin's `equals` sees only its own fields; a field missing from the list is + dropped whenever it is the only change. No test catches the omission. - **The run-configuration editor calls the parent editor's `resetEditorFrom`/`applyEditorTo` reflectively** (they are not public on `PhpTestRunConfigurationEditor`) and swallows `ReadOnlyModificationException`. - **Parallel is injected into the PHP editor's own form.** The *Test Runner options* row is a one-row diff --git a/src/main/kotlin/com/github/xepozz/testo/launch/TestoConfiguration.kt b/src/main/kotlin/com/github/xepozz/testo/launch/TestoConfiguration.kt index 365b6bca..6e40fece 100644 --- a/src/main/kotlin/com/github/xepozz/testo/launch/TestoConfiguration.kt +++ b/src/main/kotlin/com/github/xepozz/testo/launch/TestoConfiguration.kt @@ -1,7 +1,10 @@ package com.github.xepozz.testo.launch import com.intellij.execution.configurations.RunConfiguration +import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction import com.intellij.execution.testframework.sm.runner.SMRunnerConsolePropertiesProvider +import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties +import com.intellij.execution.ui.ConsoleView /** * A Testo run configuration as the rest of the plugin sees it, whichever IDE's configuration class stands behind it. @@ -17,6 +20,9 @@ interface TestoConfiguration : RunConfiguration, SMRunnerConsolePropertiesProvid /** The kind of that interpreter (`local`, a remote connection type), for the run archive; empty when there is none. */ val interpreterKind: String + /** The *Rerun Failed Tests* action of a tab showing a run of this configuration. */ + fun rerunFailedTestsAction(console: ConsoleView, properties: SMTRunnerConsoleProperties): AbstractRerunFailedTestsAction + companion object { /** The executor a Coverage run is started with; the run history tells runs apart by it. */ const val COVERAGE_EXECUTOR_ID = "Coverage" 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 2cb82876..e215135b 100644 --- a/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunReplayProfile.kt +++ b/src/main/kotlin/com/github/xepozz/testo/runs/TestoRunReplayProfile.kt @@ -100,7 +100,13 @@ internal class TestoRunReplayProfile( } } }) - DefaultExecutionResult(console, handler) + DefaultExecutionResult(console, handler).apply { + (console as? SMTRunnerConsoleView)?.let { view -> + val rerunFailed = configuration.rerunFailedTestsAction(view, props) + rerunFailed.setModelProvider { view.resultsViewer } + setRestartActions(rerunFailed) + } + } } private fun feed(handler: ProcessHandler) { diff --git a/src/openide/kotlin/com/github/xepozz/testo/openide/tests/actions/TestoRerunFailedTestsAction.kt b/src/openide/kotlin/com/github/xepozz/testo/openide/tests/actions/TestoRerunFailedTestsAction.kt index 6cc2fb37..4d6c8d80 100644 --- a/src/openide/kotlin/com/github/xepozz/testo/openide/tests/actions/TestoRerunFailedTestsAction.kt +++ b/src/openide/kotlin/com/github/xepozz/testo/openide/tests/actions/TestoRerunFailedTestsAction.kt @@ -1,13 +1,20 @@ package com.github.xepozz.testo.openide.tests.actions import com.github.xepozz.testo.launch.TestoScope +import com.github.xepozz.testo.openide.tests.run.TestoProgramRunner import com.github.xepozz.testo.openide.tests.run.TestoRunConfiguration +import com.github.xepozz.testo.tests.actions.testoRunProfile import com.github.xepozz.testo.tests.console.TestoRunTarget import com.intellij.execution.Executor import com.intellij.execution.configurations.RunProfileState import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.runners.ExecutionEnvironmentBuilder +import com.intellij.execution.runners.ProgramRunner import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.ExecutionDataKeys +import com.intellij.openapi.actionSystem.impl.SimpleDataContext import com.intellij.openapi.project.Project import com.intellij.openapi.ui.ComponentContainer @@ -24,8 +31,18 @@ class TestoRerunFailedTestsAction( init(properties) } + override fun actionPerformed(e: AnActionEvent) { + val rerouted = e.getData(ExecutionDataKeys.EXECUTION_ENVIRONMENT)?.let(::throughTestoRunner) + ?: return super.actionPerformed(e) + val context = SimpleDataContext.builder() + .setParent(e.dataContext) + .add(ExecutionDataKeys.EXECUTION_ENVIRONMENT, rerouted) + .build() + super.actionPerformed(e.withDataContext(context)) + } + override fun getRunProfile(environment: ExecutionEnvironment): MyRunProfile? { - val configuration = myConsoleProperties.configuration as? TestoRunConfiguration ?: return null + val configuration = environment.testoRunProfile() as? TestoRunConfiguration ?: return null val clone = rerunConfiguration(configuration, failedFilters(configuration.project)) ?: return null return object : MyRunProfile(clone) { override fun getState(executor: Executor, environment: ExecutionEnvironment): RunProfileState = @@ -43,6 +60,17 @@ class TestoRerunFailedTestsAction( .toList() companion object { + /** + * [environment] run by [TestoProgramRunner] instead, which prepares the process off the EDT; null when it already is. + * The platform reruns with the tab's own runner, and a tab replayed from Test History is the platform's. + */ + internal fun throughTestoRunner(environment: ExecutionEnvironment): ExecutionEnvironment? { + if (environment.runner is TestoProgramRunner) return null + val profile = environment.testoRunProfile() ?: return null + val runner = ProgramRunner.getRunner(environment.executor.id, profile) as? TestoProgramRunner ?: return null + return ExecutionEnvironmentBuilder(environment).runner(runner).build() + } + /** A clone of [configuration] running exactly [filters]; its scope is cleared so it narrows nothing more. */ internal fun rerunConfiguration(configuration: TestoRunConfiguration, filters: List): TestoRunConfiguration? { if (filters.isEmpty()) return null diff --git a/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunConfiguration.kt b/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunConfiguration.kt index 1d25b91d..c87511f2 100644 --- a/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunConfiguration.kt +++ b/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunConfiguration.kt @@ -8,8 +8,9 @@ import com.github.xepozz.testo.launch.TestoRunContexts import com.github.xepozz.testo.launch.TestoRunSelection import com.github.xepozz.testo.launch.TestoSavedConfiguration import com.github.xepozz.testo.launch.TestoScope -import com.github.xepozz.testo.openide.openIdeConsoleProperties import com.github.xepozz.testo.openide.OpenIdeToolEnvironment +import com.github.xepozz.testo.openide.openIdeConsoleProperties +import com.github.xepozz.testo.openide.tests.actions.TestoRerunFailedTestsAction import com.intellij.execution.ExecutionException import com.intellij.execution.Executor import com.intellij.execution.configurations.ConfigurationFactory @@ -24,6 +25,7 @@ import com.intellij.execution.process.ProcessHandler import com.intellij.execution.process.ProcessTerminatedListener import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties +import com.intellij.execution.ui.ConsoleView import com.intellij.openapi.application.ReadAction import com.intellij.openapi.options.SettingsEditor import com.intellij.openapi.project.Project @@ -181,6 +183,9 @@ class TestoRunConfiguration( null -> "" } + override fun rerunFailedTestsAction(console: ConsoleView, properties: SMTRunnerConsoleProperties) = + TestoRerunFailedTestsAction(console, properties) + private fun archivedEnvironment(): PhpLaunchEnvironment? = lastEnvironment ?: runCatching { launchEnvironment() }.getOrNull() diff --git a/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunState.kt b/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunState.kt index b4361e5c..d2604a65 100644 --- a/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunState.kt +++ b/src/openide/kotlin/com/github/xepozz/testo/openide/tests/run/TestoRunState.kt @@ -1,6 +1,5 @@ package com.github.xepozz.testo.openide.tests.run -import com.github.xepozz.testo.openide.tests.actions.TestoRerunFailedTestsAction import com.github.xepozz.testo.tests.TestoConsoleProperties import com.intellij.execution.DefaultExecutionResult import com.intellij.execution.ExecutionResult @@ -30,7 +29,8 @@ internal class TestoRunState( properties, ) as SMTRunnerConsoleView // The platform hands the results model to the tree's own toolbar only; a restart action reads it from here. - val rerunFailed = TestoRerunFailedTestsAction(console, properties).apply { setModelProvider { console.resultsViewer } } + val rerunFailed = configuration.rerunFailedTestsAction(console, properties) + rerunFailed.setModelProvider { console.resultsViewer } return DefaultExecutionResult(console, prepared.handler).apply { setRestartActions(rerunFailed) } diff --git a/src/openideTest/kotlin/com/github/xepozz/testo/openide/TestoRerunFailedRunnerTest.kt b/src/openideTest/kotlin/com/github/xepozz/testo/openide/TestoRerunFailedRunnerTest.kt new file mode 100644 index 00000000..592bed3a --- /dev/null +++ b/src/openideTest/kotlin/com/github/xepozz/testo/openide/TestoRerunFailedRunnerTest.kt @@ -0,0 +1,37 @@ +package com.github.xepozz.testo.openide + +import com.github.xepozz.testo.launch.TestoConfiguration +import com.github.xepozz.testo.openide.tests.actions.TestoRerunFailedTestsAction +import com.github.xepozz.testo.openide.tests.run.TestoProgramRunner +import com.github.xepozz.testo.php.TestoPhp +import com.github.xepozz.testo.runs.TestoRunArchiver.withConfiguration +import com.github.xepozz.testo.runs.TestoRunManifest +import com.github.xepozz.testo.runs.TestoRunReplayProfile +import com.intellij.execution.executors.DefaultRunExecutor +import com.intellij.execution.runners.ExecutionEnvironmentBuilder +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import java.nio.file.Path + +class TestoRerunFailedRunnerTest : BasePlatformTestCase() { + private val executor get() = DefaultRunExecutor.getRunExecutorInstance() + + private fun configuration() = + TestoPhp.getInstance().configurationFactory().createTemplateConfiguration(project) as TestoConfiguration + + fun testAReplayedTabRerunsThroughTheTestoRunner() { + val replay = TestoRunReplayProfile(project, Path.of("run"), TestoRunManifest().withConfiguration(configuration())) + val environment = ExecutionEnvironmentBuilder.create(project, executor, replay).build() + assertFalse(environment.runner is TestoProgramRunner) + + val rerouted = TestoRerunFailedTestsAction.throughTestoRunner(environment) + + assertInstanceOf(rerouted?.runner, TestoProgramRunner::class.java) + assertSame(replay, rerouted!!.runProfile) + } + + fun testALiveTabKeepsItsRunner() { + val environment = ExecutionEnvironmentBuilder.create(project, executor, configuration()).build() + + assertNull(TestoRerunFailedTestsAction.throughTestoRunner(environment)) + } +} diff --git a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/actions/TestoRerunFailedTestsAction.kt b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/actions/TestoRerunFailedTestsAction.kt index 4cd4e57d..d5d676dd 100644 --- a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/actions/TestoRerunFailedTestsAction.kt +++ b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/actions/TestoRerunFailedTestsAction.kt @@ -3,6 +3,7 @@ package com.github.xepozz.testo.phpstorm.tests.actions import com.github.xepozz.testo.TestoBundle import com.github.xepozz.testo.phpstorm.tests.TestoFrameworkType import com.github.xepozz.testo.phpstorm.tests.run.TestoRunConfiguration +import com.github.xepozz.testo.tests.actions.testoRunProfile import com.github.xepozz.testo.tests.console.TestoRunTarget import com.intellij.execution.ExecutionException import com.intellij.execution.Executor @@ -39,14 +40,9 @@ class TestoRerunFailedTestsAction( .toList() override fun getRunProfile(environment: ExecutionEnvironment): MyRunProfile? { - val profile = this.myConsoleProperties.configuration - if (profile !is TestoRunConfiguration) { - LOG.warn( - TestoBundle.message( - "php.testo.run.configuration.rerun.incorrect.configuration", - profile.javaClass, - ) - ) + val profile = environment.testoRunProfile() as? TestoRunConfiguration ?: run { + val profileClass = environment.runProfile.javaClass + LOG.warn(TestoBundle.message("php.testo.run.configuration.rerun.incorrect.configuration", profileClass)) return null } diff --git a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunConfiguration.kt b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunConfiguration.kt index ceebdbe7..70c383ab 100644 --- a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunConfiguration.kt +++ b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunConfiguration.kt @@ -102,6 +102,9 @@ class TestoRunConfiguration(project: Project, factory: ConfigurationFactory) : P properties: SMTRunnerConsoleProperties, ) = TestoRerunFailedTestsAction(consoleView, properties) + override fun rerunFailedTestsAction(console: ConsoleView, properties: SMTRunnerConsoleProperties) = + createRerunAction(console, properties) + override fun getConfigurationEditor(): SettingsEditor { val editor = super.getConfigurationEditor() as PhpTestRunConfigurationEditor editor.setRunnerOptionsDocumentation("https://php-testo.github.io/docs/guide/cli-reference") diff --git a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunnerSettings.kt b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunnerSettings.kt index 9bdc0835..33317f7d 100644 --- a/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunnerSettings.kt +++ b/src/phpstorm/kotlin/com/github/xepozz/testo/phpstorm/tests/run/TestoRunnerSettings.kt @@ -172,6 +172,22 @@ class TestoRunnerSettings( infectionOptions = other.infectionOptions } + // The inherited equals compares the PHP plugin's fields alone, so saving, which skips settings equal to the + // defaults, dropped a configuration that differed from them only in Testo's own fields. + override fun equals(other: Any?): Boolean = + super.equals(other) && other is TestoRunnerSettings && persisted() == other.persisted() + + override fun hashCode(): Int = 31 * super.hashCode() + persisted().hashCode() + + private fun persisted(): List = listOf( + dataProviderIndex, dataSetIndex, coverageEngine, parallelTestingEnabled, command, parallel, + coverageClover, coverageCobertura, coverageXml, coverageLevel, coverageOptions, logHtml, logJunit, + infectionScope, infectionGitDiffBase, infectionThreads, infectionOnlyCoveringTestCases, + infectionWithUncovered, infectionTimeoutsAsEscaped, infectionMutators, infectionStaticAnalysisTool, + infectionOptions, binaryPath, interpreterId, testoTypes, suites, groups, excludeGroups, + legacyGroup, legacyExcludeGroup, legacySuite, legacyTestoType, + ) + companion object Companion { const val DEFAULT_COVERAGE_OPTIONS = TestoRunSelection.DEFAULT_COVERAGE_OPTIONS diff --git a/src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/baseline/PersistenceBaselineTest.kt b/src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/baseline/PersistenceBaselineTest.kt index 99f4d6f2..d96c962f 100644 --- a/src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/baseline/PersistenceBaselineTest.kt +++ b/src/phpstormTest/kotlin/com/github/xepozz/testo/phpstorm/baseline/PersistenceBaselineTest.kt @@ -115,4 +115,19 @@ class PersistenceBaselineTest : BasePlatformTestCase() { out.appendLine(write(restored)) Baselines.assertMatches("persistence-legacy", out.toString()) } + + fun testOnlyTestoFieldsChangedAreStillSaved() { + val configuration = BaselineSettings.newConfiguration(project, "Groups") + configuration.testoSettings.getTestoRunnerSettings().apply { + groups = mutableListOf("db") + coverageXml = false + } + + val restored = BaselineSettings.newConfiguration(project, "Restored") + restored.readExternal(JDOMUtil.load(write(configuration))) + + val settings = restored.testoSettings.getTestoRunnerSettings() + assertEquals(listOf("db"), settings.groups) + assertFalse(settings.coverageXml) + } } diff --git a/src/test/kotlin/com/github/xepozz/testo/runs/TestoReplayConfigurationTest.kt b/src/test/kotlin/com/github/xepozz/testo/runs/TestoReplayConfigurationTest.kt new file mode 100644 index 00000000..895d6b88 --- /dev/null +++ b/src/test/kotlin/com/github/xepozz/testo/runs/TestoReplayConfigurationTest.kt @@ -0,0 +1,48 @@ +package com.github.xepozz.testo.runs + +import com.github.xepozz.testo.launch.TestoConfiguration +import com.github.xepozz.testo.php.TestoPhp +import com.github.xepozz.testo.runs.TestoRunArchiver.withConfiguration +import com.intellij.execution.DefaultExecutionResult +import com.intellij.execution.configurations.WrappingRunConfiguration +import com.intellij.execution.executors.DefaultRunExecutor +import com.intellij.execution.runners.ExecutionEnvironment +import com.intellij.execution.runners.ExecutionEnvironmentBuilder +import com.intellij.execution.testframework.actions.AbstractRerunFailedTestsAction +import com.intellij.execution.testframework.sm.runner.SMTestProxy +import com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView +import com.intellij.openapi.util.Disposer +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import java.nio.file.Path + +class TestoReplayConfigurationTest : BasePlatformTestCase() { + private class Replayed(val environment: ExecutionEnvironment, val result: DefaultExecutionResult) { + val view get() = result.executionConsole as SMTRunnerConsoleView + val rerunFailed get() = result.restartActions.single() as AbstractRerunFailedTestsAction + } + + private fun replay(archived: TestoConfiguration): Replayed { + val replay = TestoRunReplayProfile(project, Path.of("run"), TestoRunManifest().withConfiguration(archived)) + val executor = DefaultRunExecutor.getRunExecutorInstance() + val environment = ExecutionEnvironmentBuilder.create(project, executor, replay).build() + val result = replay.getState(executor, environment).execute(executor, environment.runner) as DefaultExecutionResult + Disposer.register(testRootDisposable, result.executionConsole) + return Replayed(environment, result) + } + + fun testAReplayedTabRerunsItsFailedTestsWithTheArchivedConfiguration() { + val archived = TestoPhp.getInstance().configurationFactory().createTemplateConfiguration(project) as TestoConfiguration + archived.selection = archived.selection.copy(testRunnerOptions = "-q --teamcity --stop-on-failure") + val replayed = replay(archived) + val failed = SMTestProxy("sum", false, "php_qn:///src/CalcTest.php::\\App\\CalcTest::sum") + replayed.view.resultsViewer.testsRootNode.addChild(failed) + failed.setStarted() + failed.setTestFailed("boom", null, false) + + val rerun = replayed.rerunFailed.getRunProfileTestAccessor(replayed.environment) + + val configuration = (rerun as WrappingRunConfiguration<*>).peer as TestoConfiguration + assertEquals("-q --teamcity --stop-on-failure", configuration.selection.testRunnerOptions) + assertEquals(listOf("\\App\\CalcTest::sum"), configuration.selection.rerunFilters) + } +}