Add functionality to make certain SkyValues unshareable, meaning they are not serialized. Tag TestCompletionValue and any ActionExecutionValue coming from a NotifyOnActionCacheHit (i.e., tests) like that. To make such values really not shared, request the ActionExecutionValue from TestCompletionFunction as opposed to the ArtifactValue (propagating the unshareable bit up seemed like too much fuss, and I have a dream of getting rid of ArtifactValue anyway).

PiperOrigin-RevId: 200504358
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java
index cbbe9f9..9a7d7a6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/TestCompletionFunction.java
@@ -13,6 +13,11 @@
 // limitations under the License.
 package com.google.devtools.build.lib.skyframe;
 
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+import com.google.devtools.build.lib.actions.ActionLookupData;
+import com.google.devtools.build.lib.actions.ActionLookupValue;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.TopLevelArtifactContext;
@@ -21,6 +26,7 @@
 import com.google.devtools.build.skyframe.SkyFunction;
 import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.SkyValue;
+import java.util.Map;
 
 /**
  * TestCompletionFunction builds all relevant test artifacts of a {@link
@@ -45,14 +51,40 @@
 
     ConfiguredTarget ct = ctValue.getConfiguredTarget();
     if (key.exclusiveTesting()) {
-      // Request test artifacts iteratively if testing exclusively.
+      // Request test execution iteratively if testing exclusively.
       for (Artifact testArtifact : TestProvider.getTestStatusArtifacts(ct)) {
-        if (env.getValue(ArtifactSkyKey.key(testArtifact, /*isMandatory=*/ true)) == null) {
+        ActionLookupValue.ActionLookupKey actionLookupKey =
+            ArtifactFunction.getActionLookupKey(testArtifact);
+        ActionLookupValue actionLookupValue =
+            ArtifactFunction.getActionLookupValue(actionLookupKey, env, testArtifact);
+        if (actionLookupValue == null) {
+          return null;
+        }
+        env.getValue(getActionLookupData(testArtifact, actionLookupKey, actionLookupValue));
+        if (env.valuesMissing()) {
           return null;
         }
       }
     } else {
-      env.getValues(TestProvider.getTestStatusArtifacts(ct));
+      Multimap<ActionLookupValue.ActionLookupKey, Artifact> keyToArtifactMap =
+          Multimaps.index(
+              TestProvider.getTestStatusArtifacts(ct), ArtifactFunction::getActionLookupKey);
+      Map<SkyKey, SkyValue> actionLookupValues = env.getValues(keyToArtifactMap.keySet());
+      if (env.valuesMissing()) {
+        return null;
+      }
+      env.getValues(
+          keyToArtifactMap
+              .entries()
+              .stream()
+              .map(
+                  entry ->
+                      getActionLookupData(
+                          entry.getValue(),
+                          entry.getKey(),
+                          (ActionLookupValue) actionLookupValues.get(entry.getKey())))
+              .distinct()
+              .collect(ImmutableSet.toImmutableSet()));
       if (env.valuesMissing()) {
         return null;
       }
@@ -60,6 +92,14 @@
     return TestCompletionValue.TEST_COMPLETION_MARKER;
   }
 
+  private static ActionLookupData getActionLookupData(
+      Artifact artifact,
+      ActionLookupValue.ActionLookupKey actionLookupKey,
+      ActionLookupValue actionLookupValue) {
+    return ActionExecutionValue.key(
+        actionLookupKey, actionLookupValue.getGeneratingActionIndex(artifact));
+  }
+
   @Override
   public String extractTag(SkyKey skyKey) {
     return Label.print(((ConfiguredTargetKey) skyKey.argument()).getLabel());