diff --git a/.github/actions/setup-bazel/action.yml b/.github/actions/setup-bazel/action.yml index 6c5263cd67..d216aca7f2 100644 --- a/.github/actions/setup-bazel/action.yml +++ b/.github/actions/setup-bazel/action.yml @@ -55,20 +55,24 @@ runs: fi - name: Configure the remote cache credential helper uses: ./.github/actions/remote-cache-helper - - name: Point Bazel at a registry file cache + - name: Point Bazel at a registry file cache and the shared nested cache root shell: bash run: | cache="$RUNNER_TEMP/dx-repository-cache" contents="$RUNNER_TEMP/dx-repo-contents" - mkdir -p "$cache" "$contents" + nested="$RUNNER_TEMP/dx-nested" + mkdir -p "$cache" "$contents" "$nested" if [ "$RUNNER_OS" = Windows ]; then cache="$(cygpath -m "$cache")" contents="$(cygpath -m "$contents")" + nested="$(cygpath -m "$nested")" fi { echo "common --repository_cache=$cache" echo "common --repo_contents_cache=$contents" + echo "test --sandbox_writable_path=$nested" } >> user.bazelrc + echo "DX_NESTED_SHARED=$nested" >> "$GITHUB_ENV" - uses: bazel-contrib/setup-bazel@104e3eea9447cdaa4b00d0fb46191a3985d26ab3 # v0.19.1 with: bazelisk-version: ${{ steps.pin.outputs.version }} diff --git a/docs/design/nested-tests.md b/docs/design/nested-tests.md index ac58927377..52884b7e92 100644 --- a/docs/design/nested-tests.md +++ b/docs/design/nested-tests.md @@ -1,6 +1,6 @@ # Nested tests design -This page fixes which tests may run Bazel inside a test, and how they run. Conversions follow it. +This page fixes which tests may run Bazel inside a test, and how they run. ## Kinds @@ -26,7 +26,7 @@ Measured on Linux x86_64 with the pinned Bazel 9.3.1, an empty module and one wr | Second build, same server | 0.04 s | - A cold nested test takes 7 seconds before it loads rules_dx. No nested test runs under 1 second. -- The 1 second target is met by a nested test only as a cached result. +- Only a cached result meets the 1 second target. - A test that must run under 1 second uncached is converted. ## Decisions @@ -60,15 +60,17 @@ Measured on Linux x86_64 with the pinned Bazel 9.3.1, an empty module and one wr - Bazel is `//tools/testing:nested_bazel_bin`, the binary pinned by sha256 for the `.bazelversion` release, read from runfiles. - The harness starts it through `//tools/testing:nested_bazel_shim`. -- No bazelisk. No `DX_NESTED_BAZEL`. No lookup on `PATH`. +- No bazelisk, no `DX_NESTED_BAZEL`, no `PATH` lookup. ### Environment -- The test sets `PATH=/dx_no_path` and inherits no host variable. `NESTED_BAZEL_ENV_INHERIT` is deleted. +- The test sets `PATH=/dx_no_path` and inherits no host variable but `DX_NESTED_SHARED`. `NESTED_BAZEL_ENV_INHERIT` is deleted. - `HOME`, the output user root and every workspace are under `TEST_TMPDIR`. - No slot root on the host. `DX_NESTED_BAZEL_ROOT`, `DX_NESTED_BAZEL_DISK_CACHE` and `DX_NESTED_BAZEL_REPOSITORY_CACHE` are deleted. - The nested Bazel reads one rc file that the harness writes. It reads no home, system or workspace rc of the host. -- The nested Bazel uses no disk cache and no remote cache. +- The nested Bazel uses no remote cache. +- setup-bazel exports `DX_NESTED_SHARED`, a root outside the sandbox. Servers share its install base and disk cache; fetch caches are per cache set. A starting test trims it to 6 GB, least recently used first, sparing what running tests hold. +- `nested_bazel_test(caches = "private")` opts out, for cold or fetch-failure tests. Record mode is private. - Nested actions run with `--spawn_strategy=local`. The test sandbox is the boundary. ### Repository inputs @@ -78,17 +80,17 @@ Measured on Linux x86_64 with the pinned Bazel 9.3.1, an empty module and one wr - Every file the consumer downloads is a test input: registry files, module archives, toolchain archives. - `nested_repository_cache` declares them. It reads a checked-in list of URL and hex digest, one `http_file` per entry, and gives a manifest of digest to runfile. - The digest is the checksum Bazel keys the repository cache with: sha256, or sha384 or sha512 for a download with that integrity. -- The harness builds a repository cache under `TEST_TMPDIR` from the manifest and passes `--repository_cache`. +- The harness builds a repository cache from the manifest and passes `--repository_cache`. - A nested test declares one cache set with `nested_bazel_test(cache = "")`. - The downloader config blocks every host, `bcr.bazel.build` included. -- A missing entry fails the test with the URL. +- A missing entry fails with the URL. - `bazel run //tools/testing:nested_cache_update -- ` runs the tests online with `DX_NESTED_BAZEL_NETWORK=1`. In that record mode the test writes `.txt` and `.MODULE.bazel.lock` to its undeclared outputs, and the tool copies them to `tools/testing/nested_cache`. - Other hosts record through evidence.yml with `flags=--config=nested_record`; `harness.txt` is the union of the host records. - The test calls `case.use_lock("")` where it needs the checked-in lock; in record mode that call removes the lock and registers the workspace. - Each case that ends rewrites the record from every workspace registered so far, so a failing test still uploads its record. The exit hook rewrites it once more and fails on a missing lock. - `bazel run //tools/testing:nested_cache_update -- --from ...` merges the records of several hosts. Each `` holds `.txt` and a `.MODULE.bazel.lock` per `use_lock` stem: an unpacked evidence artifact's `test.outputs/nested_cache` or the local testlogs. The tool unions the lists by URL, fails when one URL has two digests, fails when the locks of one stem differ, and writes the result to `tools/testing/nested_cache`. - A full re-record is one `lock-refresh.yml` dispatch with `nested=true` and `pr=` on the pull request branch. It records the nested tests on linux_x86_64, macos_arm64 and windows_x86_64, merges the three hosts with `--from` and pushes `tools/testing/nested_cache` to that branch with the root lock. -- The list is the registry files, module archives, patches and overlays of the lock, and every checksummed download in the Bazel workspace rules log. Nothing is edited by hand. +- The list is the registry files, module archives, patches and overlays of the lock, and every checksummed download in the Bazel workspace rules log. None is hand-edited. - `//core/modules:consumer_deps_test` fails a PR that bumps a registry `bazel_dep` until the same PR re-records every nested cache set. ### Tags @@ -96,7 +98,7 @@ Measured on Linux x86_64 with the pinned Bazel 9.3.1, an empty module and one wr - No `local`, `no-sandbox`, `no-cache`, `no-remote`, `external`, `requires-network` or `manual`. - `NESTED_BAZEL_NETWORK_TAGS`, `NESTED_BAZEL_NETWORK_ENV`, `STARTER_CONSUMER_TAGS` and `QUALIFICATION_TAGS` are deleted. - A nested test keeps `resources:nested_bazel:1`, `resources:cpu:2` and `resources:memory:2560`. -- The result is cached like any other test. Its inputs are the pinned Bazel, the shim, `module_srcs`, the cache sets and the fixture. +- The result is cached. Its inputs are the pinned Bazel, the shim, `module_srcs`, the cache sets and the fixture. ### Size diff --git a/docs/design/test-budget.md b/docs/design/test-budget.md index e1fe176d96..3a3ae03dcb 100644 --- a/docs/design/test-budget.md +++ b/docs/design/test-budget.md @@ -33,7 +33,7 @@ Every test call follows these rules. `//tools/ci:test_budget_test` checks them. ## Nested tests - `tools/testing/nested_smoke.txt` holds one sorted line per nested test: `