mirror of
https://github.com/openai/codex.git
synced 2026-08-23 13:09:46 +00:00
## Why Windows Cargo and Bazel jobs spend significant time in filesystem-heavy build and cache directories. Route those directories through one CI build root so Windows can use its Dev Drive and Unix can use a stable cache root. ## What - Have `setup-ci` define `CI_BUILD_ROOT`, `CARGO_TARGET_DIR`, Bazel cache/output paths, and temp paths. - Require Windows to find or provision a verified Dev Drive instead of falling back to `C:`. - Pass the shared Bazel output base to `setup-bazel` so its explicit `output_base` does not defeat Dev Drive routing. - Point nextest, release, and V8 source-build paths at the shared environment contract. ## Benchmark results One-off cold-cache WPR/ETW traces show the explicit Bazel output-base routing removes the dominant `C:` traffic: | sample | `C:\_bazel` | summed `C:` traffic | traced test step | |---|---:|---:|---:| | shard 1 before | 62.2 GiB | 85.2 GiB | 16m22s | | shard 1 updated | 0 | 16.5 GiB | 12m05s | | shard 3 before | 67.2 GiB | 84.6 GiB | 16m48s | | shard 3 updated | 0 | 13.5 GiB | 11m08s | For a cold x64 V8 source build, the retained build-tail sample showed `D:\cargo-target` at ~1.29 GiB while measured `C:` roots totaled ~0.45 GiB (`C:\Users` ~0.33 GiB, `C:\Program Files` ~0.06 GiB, `C:\Windows` ~0.03 GiB). The full cold build took 2h20m36s. The Bazel timing improvement is directional because both refreshed shards failed tests. The V8 trace is a bounded build-tail sample, not the full build. All final samples had zero lost ETW events; VHDX traffic was excluded from the optimization ranking. Runs: [baseline Bazel](https://github.com/openai/codex/actions/runs/28911908527), [updated Bazel](https://github.com/openai/codex/actions/runs/28917133701), [V8 build tail](https://github.com/openai/codex/actions/runs/28933626678). ## Manual validation - Ran `just fmt`. - Ran `just test-github-scripts` (35 tests). - Parsed GitHub Actions YAML with `yq`. - Ran `git diff --check`. ## Stack - [#31332](https://github.com/openai/codex/pull/31332) — parameterize Cargo target paths - [#31356](https://github.com/openai/codex/pull/31356) — Windows 2025 runner bump - [#31357](https://github.com/openai/codex/pull/31357) — Dev Drive I/O routing
291 lines
9.7 KiB
Python
291 lines
9.7 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import json
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import run_bazel_with_buildbuddy
|
|
|
|
|
|
class RunBazelWithBuildBuddyTest(unittest.TestCase):
|
|
def github_env(
|
|
self,
|
|
temp_dir: str,
|
|
*,
|
|
repository: str = "openai/codex",
|
|
fork: bool = False,
|
|
event_name: str = "pull_request",
|
|
) -> dict[str, str]:
|
|
event_path = Path(temp_dir) / "event.json"
|
|
event_path.write_text(
|
|
json.dumps({"pull_request": {"head": {"repo": {"fork": fork}}}}),
|
|
encoding="utf-8",
|
|
)
|
|
return {
|
|
"BUILDBUDDY_API_KEY": "token",
|
|
"GITHUB_ACTIONS": "true",
|
|
"GITHUB_EVENT_NAME": event_name,
|
|
"GITHUB_EVENT_PATH": str(event_path),
|
|
"GITHUB_REPOSITORY": repository,
|
|
}
|
|
|
|
def test_keyless_invocation_drops_remote_ci_configuration(self) -> None:
|
|
self.assertIsNone(
|
|
run_bazel_with_buildbuddy.remote_config(
|
|
["build", "--config=ci-linux", "//codex-rs/cli:codex"],
|
|
{},
|
|
)
|
|
)
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_args_with_remote_config(
|
|
["build", "--config=ci-linux", "--", "//codex-rs/cli:codex"],
|
|
{},
|
|
),
|
|
["build", "--", "//codex-rs/cli:codex"],
|
|
)
|
|
|
|
def test_program_arguments_after_separator_do_not_select_or_lose_rbe(self) -> None:
|
|
args = ["run", "//codex-rs/cli:codex", "--", "--config=remote"]
|
|
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_args_with_remote_config(args, {}),
|
|
args,
|
|
)
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.remote_config(
|
|
args, {"BUILDBUDDY_API_KEY": "fork-token"}
|
|
),
|
|
"buildbuddy-generic",
|
|
)
|
|
|
|
def test_upstream_push_selects_openai_rbe_before_target_separator(self) -> None:
|
|
with TemporaryDirectory() as temp_dir:
|
|
env = self.github_env(temp_dir, event_name="push")
|
|
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_args_with_remote_config(
|
|
["build", "--config=ci-linux", "--", "//codex-rs/cli:codex"],
|
|
env,
|
|
),
|
|
[
|
|
"build",
|
|
"--config=buildbuddy-openai-rbe",
|
|
"--remote_header=x-buildbuddy-api-key=token",
|
|
"--config=ci-linux",
|
|
"--",
|
|
"//codex-rs/cli:codex",
|
|
],
|
|
)
|
|
|
|
def test_windows_cross_ci_configuration_follows_remote_configuration(self) -> None:
|
|
env = {"BUILDBUDDY_API_KEY": "fork-token"}
|
|
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_args_with_remote_config(
|
|
["build", "--config=ci-windows-cross", "//codex-rs/cli:codex"],
|
|
env,
|
|
),
|
|
[
|
|
"build",
|
|
"--config=buildbuddy-generic-rbe",
|
|
"--remote_header=x-buildbuddy-api-key=fork-token",
|
|
"--config=ci-windows-cross",
|
|
"//codex-rs/cli:codex",
|
|
],
|
|
)
|
|
|
|
def test_query_remote_configuration_is_inserted_before_expression(self) -> None:
|
|
expression = 'kind("rust_library rule", //codex-rs/...)'
|
|
env = {"BUILDBUDDY_API_KEY": "fork-token"}
|
|
|
|
for command in ("query", "cquery", "aquery"):
|
|
with self.subTest(command=command):
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_args_with_remote_config(
|
|
[
|
|
command,
|
|
"--config=ci-windows-cross",
|
|
"--output=label",
|
|
expression,
|
|
],
|
|
env,
|
|
),
|
|
[
|
|
command,
|
|
"--config=buildbuddy-generic-rbe",
|
|
"--remote_header=x-buildbuddy-api-key=fork-token",
|
|
"--config=ci-windows-cross",
|
|
"--output=label",
|
|
expression,
|
|
],
|
|
)
|
|
|
|
def test_same_repository_pull_request_selects_openai_host(self) -> None:
|
|
with TemporaryDirectory() as temp_dir:
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.remote_config(
|
|
["build", "--config=ci-v8"], self.github_env(temp_dir)
|
|
),
|
|
"buildbuddy-openai-rbe",
|
|
)
|
|
|
|
def test_fork_pull_request_cannot_select_openai_host(self) -> None:
|
|
with TemporaryDirectory() as temp_dir:
|
|
env = self.github_env(temp_dir, fork=True)
|
|
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.remote_config(
|
|
["build", "--config=ci-v8"], env
|
|
),
|
|
"buildbuddy-generic-rbe",
|
|
)
|
|
|
|
def test_run_in_fork_repository_cannot_select_openai_host(self) -> None:
|
|
with TemporaryDirectory() as temp_dir:
|
|
env = self.github_env(temp_dir, repository="contributor/codex")
|
|
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.remote_config(
|
|
["build", "--config=ci-v8"], env
|
|
),
|
|
"buildbuddy-generic-rbe",
|
|
)
|
|
|
|
def test_pull_request_without_readable_event_payload_fails_closed(self) -> None:
|
|
for event_path in (None, "missing-event.json"):
|
|
env = {
|
|
"BUILDBUDDY_API_KEY": "token",
|
|
"GITHUB_ACTIONS": "true",
|
|
"GITHUB_EVENT_NAME": "pull_request",
|
|
"GITHUB_REPOSITORY": "openai/codex",
|
|
}
|
|
if event_path is not None:
|
|
env["GITHUB_EVENT_PATH"] = event_path
|
|
|
|
with self.subTest(event_path=event_path):
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.remote_config(["build"], env),
|
|
"buildbuddy-generic",
|
|
)
|
|
|
|
def test_bazel_command_uses_configured_binary_locally(self) -> None:
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_command(
|
|
"info",
|
|
"execution_root",
|
|
env={"CODEX_BAZEL_BIN": "fake-bazel"},
|
|
),
|
|
["fake-bazel", "info", "execution_root"],
|
|
)
|
|
|
|
def test_bazel_command_normalizes_github_actions_startup_options(self) -> None:
|
|
env = {
|
|
"BAZEL_OUTPUT_USER_ROOT": "/tmp/bazel-output",
|
|
"GITHUB_ACTIONS": "true",
|
|
}
|
|
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_command("build", "//codex-rs/...", env=env),
|
|
[
|
|
"bazel",
|
|
"--output_user_root=/tmp/bazel-output",
|
|
"--noexperimental_remote_repo_contents_cache",
|
|
"build",
|
|
"//codex-rs/...",
|
|
],
|
|
)
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_command(
|
|
"--experimental_remote_repo_contents_cache",
|
|
"build",
|
|
"//codex-rs/...",
|
|
env=env,
|
|
),
|
|
[
|
|
"bazel",
|
|
"--output_user_root=/tmp/bazel-output",
|
|
"--experimental_remote_repo_contents_cache",
|
|
"build",
|
|
"//codex-rs/...",
|
|
],
|
|
)
|
|
|
|
def test_bazel_command_uses_configured_local_caches(self) -> None:
|
|
env = {
|
|
"BAZEL_REPO_CONTENTS_CACHE": "/tmp/bazel-repo-contents",
|
|
"BAZEL_REPOSITORY_CACHE": "/tmp/bazel-repository",
|
|
}
|
|
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_command(
|
|
"build",
|
|
"--config=local",
|
|
"//codex-rs/...",
|
|
env=env,
|
|
),
|
|
[
|
|
"bazel",
|
|
"build",
|
|
"--config=local",
|
|
"//codex-rs/...",
|
|
"--repo_contents_cache=/tmp/bazel-repo-contents",
|
|
"--repository_cache=/tmp/bazel-repository",
|
|
],
|
|
)
|
|
|
|
def test_bazel_command_adds_local_caches_before_separator(self) -> None:
|
|
self.assertEqual(
|
|
run_bazel_with_buildbuddy.bazel_command(
|
|
"build",
|
|
"//codex-rs/...",
|
|
"--",
|
|
"--program-arg",
|
|
env={"BAZEL_REPOSITORY_CACHE": "/tmp/bazel-repository"},
|
|
),
|
|
[
|
|
"bazel",
|
|
"build",
|
|
"//codex-rs/...",
|
|
"--repository_cache=/tmp/bazel-repository",
|
|
"--",
|
|
"--program-arg",
|
|
],
|
|
)
|
|
|
|
def test_main_preserves_spaced_argument_and_child_exit_status(self) -> None:
|
|
spaced_arg = (
|
|
r"--test_env=PATH=C:\Program Files\PowerShell\7;C:\Program Files\Git\bin"
|
|
)
|
|
child_code = (
|
|
f"import sys; sys.exit(37 if sys.argv[1] == {spaced_arg!r} else 91)"
|
|
)
|
|
env = os.environ.copy()
|
|
env["CODEX_BAZEL_BIN"] = sys.executable
|
|
env.pop("BAZEL_OUTPUT_USER_ROOT", None)
|
|
env.pop("BUILDBUDDY_API_KEY", None)
|
|
env.pop("GITHUB_ACTIONS", None)
|
|
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
str(Path(run_bazel_with_buildbuddy.__file__)),
|
|
"-c",
|
|
child_code,
|
|
spaced_arg,
|
|
],
|
|
env=env,
|
|
check=False,
|
|
capture_output=True,
|
|
text=True,
|
|
)
|
|
|
|
self.assertEqual(result.returncode, 37, result.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|