title: Under what conditions can a remotely cached test result be drawn from in bazel?
body: <p>I'm trying to understand why these test executions I'm running never secure a remote cache hit on the first try. These tests are configured to pull in some remote cache configuration when executed and yet never windup presenting a cache hit on the first try.</p>
  <p>Consider the following: starting from a completely fresh bazel cache, the test runs and passes</p>
  <pre class="lang-sh prettyprint-override"><code>$ ls ~/.cache/bazel
  ls: cannot access /home/USERX/.cache/bazel: No such file or directory
  $
  $
  $ bazel test --config=remote //foo:bar
  Starting local Bazel server and connecting to it...
  INFO: Invocation ID: c3aca338-7093-4d17-aafb-928411575ae1
  INFO: Analyzed target //foo:bar (327 packages loaded, 33610 targets configured).
  INFO: Found 1 test target...
  INFO: 11902 processes: 9086 remote cache hit (76.34%), 2815 internal (23.65%), 1 local (0.01%).
  INFO: Cache hit rate for remote actions: 100.00% (9086 / 9086)
  INFO: Total action wall time 1.35s
  INFO: Critical path 3.56s (setup 2.08s, action wall time 1.35s)
  INFO: Elapsed time 109.13s (preparation 78.29s, execution 30.84s)
  INFO: Build completed successfully, 11902 total actions
  //foo:bar                          PASSED in 1.4s
  
  Executed 1 out of 1 test: 1 test passes.
  INFO: Build completed successfully, 11902 total actions
  </code></pre>
  <p>Executing a second time finally do we see the <code>(cached)</code> designation pop up</p>
  <pre><code>$ bazel test --config=remote //foo:bar
  INFO: Invocation ID: 253212e5-e5a9-435b-96db-2ac23d5510ea
  INFO: Analyzed target //foo:bar (0 packages loaded, 0 targets configured).
  INFO: Found 1 test target...
  INFO: 1 process: 1 internal (100.00%).
  INFO: Cache hit rate for remote actions: -- (0 / 0)
  INFO: Total action wall time 0.00s
  INFO: Critical path 0.79s (setup 0.00s, action wall time 0.00s)
  INFO: Elapsed time 1.32s (preparation 0.42s, execution 0.90s)
  INFO: Build completed successfully, 1 total action
  //foo:bar                 (cached) PASSED in 1.4s
  </code></pre>
  <p>Am I mistaken in assuming that I could ever have a <code>(cached)</code> test result land on the very first test execution of a never before built or tested bazel workspace? Under what conditions if any would it be possible to land a cached test result on the very first run? Would it help to understand where the bazel retains the state necessary to determine a <code>(cached)</code> hit? Where does that information reside, on the filesystem, in the working memory of the bazel server process, in an environment variable?</p>
  <hr />
  <h2>Context</h2>
  <p>I'm running some HIL tests on some dedicated hardware that operate off a bamboo plan whereby bamboo creates its own workspace from scratch on an agent, clones the repo to it, and executes some <code>bazel test</code> commands in that workspace. The goal was to leverage the bazel remote cache to avoid even running tests which are not warranted, but it seems that can only be possible if the tests were executed at least once on that tester machine.</p>