Include command line for TestRunnerAction.

We achieve this by making TestRunnerAction implements the CommandAction
interface.

Fixes #7647
RELNOTES: None
PiperOrigin-RevId: 283306323
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java b/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java
index f5c9123..4db8d46 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/test/TestRunnerAction.java
@@ -33,6 +33,7 @@
 import com.google.devtools.build.lib.actions.ActionResult;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.ArtifactPathResolver;
+import com.google.devtools.build.lib.actions.CommandAction;
 import com.google.devtools.build.lib.actions.CommandLineExpansionException;
 import com.google.devtools.build.lib.actions.EnvironmentalExecException;
 import com.google.devtools.build.lib.actions.ExecException;
@@ -51,6 +52,7 @@
 import com.google.devtools.build.lib.buildeventstream.TestFileNameConstants;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.collect.ImmutableIterable;
+import com.google.devtools.build.lib.exec.TestStrategy;
 import com.google.devtools.build.lib.util.Fingerprint;
 import com.google.devtools.build.lib.util.LoggingUtil;
 import com.google.devtools.build.lib.util.Pair;
@@ -76,7 +78,7 @@
  */
 // Not final so that we can mock it in tests.
 public class TestRunnerAction extends AbstractAction
-    implements NotifyOnActionCacheHit, ExecutionInfoSpecifier {
+    implements NotifyOnActionCacheHit, ExecutionInfoSpecifier, CommandAction {
   public static final PathFragment COVERAGE_TMP_ROOT = PathFragment.create("_coverage");
 
   // Used for selecting subset of testcase / testmethods.
@@ -870,6 +872,22 @@
     return configuration.runfilesEnabled();
   }
 
+  @Override
+  public List<String> getArguments() throws CommandLineExpansionException {
+    return TestStrategy.expandedArgsFromAction(this);
+  }
+
+  @Override
+  public ImmutableMap<String, String> getIncompleteEnvironmentForTesting()
+      throws ActionExecutionException {
+    return getEnvironment().getFixedEnv().toMap();
+  }
+
+  @Override
+  public Iterable<Artifact> getPossibleInputsForTesting() {
+    return getInputs();
+  }
+
   /** The same set of paths as the parent test action, resolved against a given exec root. */
   public final class ResolvedPaths {
     private final Path execRoot;
diff --git a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
index 3430486..561c6e1 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/TestStrategy.java
@@ -164,11 +164,31 @@
    * Generates a command line to run for the test action, taking into account coverage and {@code
    * --run_under} settings.
    *
+   * <p>Basically {@code expandedArgsFromAction}, but throws ExecException instead. This should be
+   * used in action execution.
+   *
    * @param testAction The test action.
    * @return the command line as string list.
    * @throws ExecException
    */
   public static ImmutableList<String> getArgs(TestRunnerAction testAction) throws ExecException {
+    try {
+      return expandedArgsFromAction(testAction);
+    } catch (CommandLineExpansionException e) {
+      throw new UserExecException(e);
+    }
+  }
+
+  /**
+   * Generates a command line to run for the test action, taking into account coverage and {@code
+   * --run_under} settings.
+   *
+   * @param testAction The test action.
+   * @return the command line as string list.
+   * @throws CommandLineExpansionException
+   */
+  public static ImmutableList<String> expandedArgsFromAction(TestRunnerAction testAction)
+      throws CommandLineExpansionException {
     List<String> args = Lists.newArrayList();
     // TODO(ulfjack): `executedOnWindows` is incorrect for remote execution, where we need to
     // consider the target configuration, not the machine Bazel happens to run on. Change this to
@@ -201,11 +221,7 @@
 
     // Execute the test using the alias in the runfiles tree, as mandated by the Test Encyclopedia.
     args.add(execSettings.getExecutable().getRootRelativePath().getCallablePathString());
-    try {
-      Iterables.addAll(args, execSettings.getArgs().arguments());
-    } catch (CommandLineExpansionException e) {
-      throw new UserExecException(e);
-    }
+    Iterables.addAll(args, execSettings.getArgs().arguments());
     return ImmutableList.copyOf(args);
   }