Add one more unit test for `---strategy_regexp` (description filter).

PiperOrigin-RevId: 395836801
diff --git a/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java b/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java
index 6f7e2fc..0f7d64d 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/SpawnStrategyRegistryTest.java
@@ -13,7 +13,6 @@
 // limitations under the License.
 package com.google.devtools.build.lib.exec;
 
-
 import static com.google.common.truth.Truth.assertThat;
 import static org.junit.Assert.assertThrows;
 
@@ -46,6 +45,8 @@
 
   private static final RegexFilter ELLO_MATCHER =
       new RegexFilter(ImmutableList.of("ello"), ImmutableList.of());
+  private static final RegexFilter LLO_MATCHER =
+      new RegexFilter(ImmutableList.of("llo"), ImmutableList.of());
 
   private static void noopEventHandler(Event event) {}
 
@@ -157,6 +158,7 @@
         .containsExactly(strategy2);
   }
 
+  /** If an action matches multiple filters, the latter one gets the priority. */
   @Test
   public void testMultipleDescriptionFilter() throws Exception {
     NoopStrategy strategy1 = new NoopStrategy("1");
@@ -166,9 +168,7 @@
             .registerStrategy(strategy1, "foo")
             .registerStrategy(strategy2, "bar")
             .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("foo"))
-            .addDescriptionFilter(
-                new RegexFilter(ImmutableList.of("ll"), ImmutableList.of()),
-                ImmutableList.of("bar"))
+            .addDescriptionFilter(LLO_MATCHER, ImmutableList.of("bar"))
             .build();
 
     assertThat(
@@ -178,6 +178,30 @@
         .containsExactly(strategy2);
   }
 
+  /**
+   * This demostrate a legacy behavior that the latter description filter doesn't override
+   * preceeding one of same regexp. filter=val_1 filter=val_2 is equivalent to filter=val_2,val_1
+   * TODO: b/196025286 will fix this legacy behavior.
+   */
+  @Test
+  public void testDuplicatedDescriptionFilter() throws Exception {
+    NoopStrategy strategy1 = new NoopStrategy("1");
+    NoopStrategy strategy2 = new NoopStrategy("2");
+    SpawnStrategyRegistry strategyRegistry =
+        SpawnStrategyRegistry.builder()
+            .registerStrategy(strategy1, "foo")
+            .registerStrategy(strategy2, "bar")
+            .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("foo"))
+            .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("bar"))
+            .build();
+
+    assertThat(
+            strategyRegistry.getStrategies(
+                createSpawnWithMnemonicAndDescription("", "hello"),
+                SpawnStrategyRegistryTest::noopEventHandler))
+        .containsExactly(strategy2, strategy1);
+  }
+
   @Test
   public void testMultipleDefaultStrategies() throws Exception {
     NoopStrategy strategy1 = new NoopStrategy("1");
@@ -276,6 +300,10 @@
     assertThat(exception).hasMessageThat().containsMatch("bar.*Valid.*foo");
   }
 
+  /**
+   * TODO: b/196025286 will gracefully ignore unregistered strategy, which changes the expected
+   * outcome here.
+   */
   @Test
   public void testDescriptionStrategyNotPresent() {
     NoopStrategy strategy1 = new NoopStrategy("1");
@@ -292,6 +320,21 @@
   }
 
   @Test
+  public void testDescriptionStrategyAllNotPresent() {
+    NoopStrategy strategy1 = new NoopStrategy("1");
+    AbruptExitException exception =
+        assertThrows(
+            AbruptExitException.class,
+            () ->
+                SpawnStrategyRegistry.builder()
+                    .registerStrategy(strategy1, "foo")
+                    .addDescriptionFilter(ELLO_MATCHER, ImmutableList.of("bar", "food"))
+                    .build());
+
+    assertThat(exception).hasMessageThat().containsMatch("bar.*Valid.*foo");
+  }
+
+  @Test
   public void testDefaultStrategyNotPresent() {
     NoopStrategy strategy1 = new NoopStrategy("1");
     AbruptExitException exception =