Allow muting cacheable tests: tests-common-new

^KTI-1999
diff --git a/compiler/tests-mutes/mutes-junit5/src/org/jetbrains/kotlin/test/muteWithDatabaseJunit5.kt b/compiler/tests-mutes/mutes-junit5/src/org/jetbrains/kotlin/test/muteWithDatabaseJunit5.kt
index 0b9abb3..a354d35 100644
--- a/compiler/tests-mutes/mutes-junit5/src/org/jetbrains/kotlin/test/muteWithDatabaseJunit5.kt
+++ b/compiler/tests-mutes/mutes-junit5/src/org/jetbrains/kotlin/test/muteWithDatabaseJunit5.kt
@@ -55,7 +55,7 @@
             testMethod != null
         ) {
             DO_AUTO_MUTE?.muteTest(
-                testKey(testClass, testMethod.name)
+                testKey(testClass, context.displayName)
             )
         }
     }
@@ -83,7 +83,7 @@
         extensionContext: ExtensionContext
     ) {
         val testClass = extensionContext.testClassNullable
-        val testMethod = extensionContext.testMethodNullable
+        val testMethod: Method? = extensionContext.testMethodNullable
         if (testClass != null &&
             testMethod != null
         ) {
@@ -91,15 +91,19 @@
             if (mutedTest != null &&
                 isPresentedInDatabaseWithoutFailMarker(mutedTest)
             ) {
-                if (mutedTest.isFlaky) {
-                    invocation.proceed()
-                    return
-                } else {
+                if (!mutedTest.isFlaky) {
                     invertMutedTestResultWithLog(
                         f = { invocation.proceed() },
                         testKey = testKey(testMethod.declaringClass, mutedTest.methodKey)
                     )
                     return
+                } else if (DO_AUTO_MUTE.isMuted(testKey(testClass, extensionContext.displayName))) {
+                    DO_AUTO_MUTE.mute(testKey(testClass, extensionContext.displayName))
+                    invocation.skip()
+                    return
+                } else {
+                    invocation.proceed()
+                    return
                 }
             }
         }
diff --git a/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/AutoMute.kt b/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/AutoMute.kt
index 8631f3a..9395022 100644
--- a/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/AutoMute.kt
+++ b/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/AutoMute.kt
@@ -1,52 +1,33 @@
 /*
- * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
+ * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
  * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
  */
 
 package org.jetbrains.kotlin.test.mutes
 
-import java.io.File
+class AutoMute() {
+    private val mutedTests: MutableList<String> = mutableListOf()
 
-class AutoMute(
-    val file: String,
-    val issue: String
-)
+    fun muteTest(testKey: String) {
+        mutedTests.add(testKey)
+    }
 
-val DO_AUTO_MUTE: AutoMute? by lazy {
-    val autoMuteFile = File("tests/automute")
-    if (autoMuteFile.exists()) {
-        val lines = autoMuteFile.readLines().filter { it.isNotBlank() }.map { it.trim() }
-        AutoMute(
-            lines.getOrNull(0) ?: error("A file path is expected in tne first line"),
-            lines.getOrNull(1) ?: error("An issue description is the second line")
-        )
-    } else {
-        null
+    fun isMuted(testKey: String): Boolean = mutedTests.contains(testKey)
+    fun mute(testKey: String) {
+        System.err.println("MUTED TEST: $testKey")
+        mutedTests.remove(testKey)
     }
 }
 
-fun AutoMute.muteTest(testKey: String) {
-    val file = File(file)
-    val lines = file.readLines()
-    val firstLine = lines[0] // Drop file header
-    val muted = lines.drop(1).toMutableList()
-    muted.add("$testKey, $issue")
-    val newMuted: List<String> = mutableListOf<String>() + firstLine + muted.sorted()
-    file.writeText(newMuted.joinToString("\n"))
-}
+val DO_AUTO_MUTE: AutoMute by lazy { AutoMute() }
 
 internal fun wrapWithAutoMute(f: () -> Unit, testKey: String): (() -> Unit)? {
-    val doAutoMute = DO_AUTO_MUTE
-    if (doAutoMute != null) {
-        return {
-            try {
-                f()
-            } catch (e: Throwable) {
-                doAutoMute.muteTest(testKey)
-                throw e
-            }
+    return {
+        try {
+            f()
+        } catch (e: Throwable) {
+            DO_AUTO_MUTE.muteTest(testKey)
+            throw e
         }
-    } else {
-        return null
     }
 }
diff --git a/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/muteWithDatabaseWrapper.kt b/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/muteWithDatabaseWrapper.kt
index fe0c22d..cde0432 100644
--- a/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/muteWithDatabaseWrapper.kt
+++ b/compiler/tests-mutes/src/org/jetbrains/kotlin/test/mutes/muteWithDatabaseWrapper.kt
@@ -40,14 +40,14 @@
         }
     } else if (isPresentedInDatabaseWithoutFailMarker(mutedTest)) {
         if (mutedTest?.isFlaky == true) {
-            return f
+            return wrapWithAutoMute(f, testKey)
         } else {
             return {
                 invertMutedTestResultWithLog(f, testKey)
             }
         }
     } else {
-        return wrapWithAutoMute(f, testKey)
+        return f
     }
 }
 
diff --git a/tests/mute-common.csv b/tests/mute-common.csv
index 1cdd099..eaa5f20 100644
--- a/tests/mute-common.csv
+++ b/tests/mute-common.csv
@@ -1,2 +1,6 @@
 Test key, Issue, State (optional: MUTE or FAIL), Status (optional: FLAKY)
 org.jetbrains.kotlin.daemon.CompilerDaemonTest.testParallelDaemonStart,,,
+org.jetbrains.kotlin.compose.compiler.gradle.EnabledPlatformsConfigurationTest.allKotlinPlatformsAreUsedByDefault, KTI-1993,,FLAKY
+org.jetbrains.kotlin.compose.compiler.gradle.EnabledPlatformsConfigurationTest.disableKotlinPlatforms, KTI-1993,,FLAKY
+org.jetbrains.kotlin.gradle.native.NativeIrLinkerIssuesIT.shouldBuildIrLinkerWithCache,,,FLAKY
+org.jetbrains.kotlin.gradle.native.NativeIrLinkerIssuesIT.shouldBuildIrLinkerWithoutCache,,,FLAKY