In FileSystemValueChecker, only check TreeArtfacts that are in the
passed-in modified file sets.

--
MOS_MIGRATED_REVID=125173579
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
index b457c00..54b65cb 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java
@@ -411,6 +411,9 @@
     Artifact outUnchanging = createTreeArtifact("untouched");
     FileSystemUtils.createDirectoryAndParents(outUnchanging.getPath());
 
+    Artifact last = createTreeArtifact("zzzzzzzzzz");
+    FileSystemUtils.createDirectoryAndParents(last.getPath());
+
     Action action1 =
         new TestAction(
             Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out1));
@@ -423,6 +426,9 @@
     Action actionUnchanging =
         new TestAction(
             Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(outUnchanging));
+    Action lastAction =
+        new TestAction(
+            Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(last));
     differencer.inject(
         ImmutableMap.<SkyKey, SkyValue>of(
             ActionExecutionValue.key(action1),
@@ -432,7 +438,9 @@
             ActionExecutionValue.key(actionEmpty),
             actionValueWithEmptyDirectory(outEmpty),
             ActionExecutionValue.key(actionUnchanging),
-            actionValueWithEmptyDirectory(outUnchanging)));
+            actionValueWithEmptyDirectory(outUnchanging),
+            ActionExecutionValue.key(lastAction),
+            actionValueWithEmptyDirectory(last)));
 
     assertFalse(
         driver
@@ -510,6 +518,48 @@
                 .build()))
         .containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2),
             ActionExecutionValue.key(actionEmpty));
+    // We also check that if the modified file set does not contain our modified files on disk,
+    // we are not going to check and return them.
+    assertThat(
+        new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(),
+            batchStatter,
+            new ModifiedFileSet.Builder()
+                .modify(file21.getExecPath())
+                .modify(outEmptyNew.getExecPath())
+                .build()))
+        .containsExactly(ActionExecutionValue.key(action2), ActionExecutionValue.key(actionEmpty));
+    assertThat(
+        new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(),
+            batchStatter,
+            new ModifiedFileSet.Builder()
+                .modify(file21.getExecPath())
+                .modify(out1new.getExecPath())
+                .build()))
+        .containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2));
+    // Check modifying the last (lexicographically) tree artifact.
+    last.getPath().delete();
+    assertThat(
+        new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(),
+            batchStatter,
+            new ModifiedFileSet.Builder()
+                .modify(file21.getExecPath())
+                .modify(out1new.getExecPath())
+                .modify(last.getExecPath())
+                .build()))
+        .containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2),
+            ActionExecutionValue.key(lastAction));
+    // Check ModifiedFileSet without the last (lexicographically) tree artifact.
+    assertThat(
+        new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(),
+            batchStatter,
+            new ModifiedFileSet.Builder()
+                .modify(file21.getExecPath())
+                .modify(out1new.getExecPath())
+                .build()))
+        .containsExactly(ActionExecutionValue.key(action1), ActionExecutionValue.key(action2));
+    // Restore
+    last.getPath().delete();
+    FileSystemUtils.createDirectoryAndParents(last.getPath());
     // We add a test for NOTHING_MODIFIED, because FileSystemValueChecker doesn't
     // pay attention to file sets for TreeArtifact directory listings.
     assertThat(