Test repository-wide Rust formatter discovery (#41925)

## What changed

- Exercise Rust source discovery through a mocked `git ls-files` call, including files outside `codex-rs`, paths containing spaces, and stale entries that no longer exist.
- Assert that the formatter invokes `rustfmt` from `codex-rs` with the repository configuration in both format and check modes.
- Keep the multiline argument-comment lint fixture stable under formatting and update affected Rust test files to the expected style.

GitOrigin-RevId: 0cfffde1bb91bf620d2118bed1efc68466c0cca6
This commit is contained in:
Adam Perry @ OpenAI
2026-08-31 22:47:53 +00:00
committed by copyberry
parent 64c9cde458
commit 9127f21890
6 changed files with 109 additions and 79 deletions
@@ -141,9 +141,18 @@ def test_root_fmt_recipes_use_shared_formatter_driver() -> None:
def test_root_format_driver_covers_all_formatter_groups(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
) -> None:
"""The shared driver should retain every formatter in both modes."""
script = _load_root_format_script_module()
for name in (
"bazel/rules/example.rs",
"codex-rs/src/lib.rs",
"codex-rs/new file.rs",
):
path = tmp_path / name
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("")
git_ls_files_args = [
"git",
"ls-files",
@@ -153,11 +162,18 @@ def test_root_format_driver_covers_all_formatter_groups(
"--exclude-standard",
]
# The Python SDK CI image has no Git; keep discovery mocked at the process boundary.
def fake_check_output(args, *, cwd):
assert cwd == tmp_path
if args == git_ls_files_args + ["--", "*.rs"]:
return (
b"codex-rs/src/lib.rs\0bazel/rules/example.rs\0"
b"codex-rs/new file.rs\0codex-rs/deleted.rs\0"
)
assert args == git_ls_files_args
assert cwd == script.REPO_ROOT
return b"MODULE.bazel\0README.md\0third_party/v8/libcxx.BUILD.bazel\0"
monkeypatch.setattr(script, "REPO_ROOT", tmp_path)
monkeypatch.setattr(script.subprocess, "check_output", fake_check_output)
formatters = script.formatter_groups(check=False)
checks = script.formatter_groups(check=True)
@@ -215,20 +231,25 @@ def test_root_format_driver_covers_all_formatter_groups(
)
assert formatters[0].commands[-1].args == ("just", "--unstable", "--fmt")
assert checks[0].commands[-1].args == ("just", "--unstable", "--fmt", "--check")
assert formatters[1].commands[-1].args == (
"cargo",
"fmt",
"--",
rustfmt_args = (
"rustfmt",
"--edition",
"2024",
"--config-path",
str(tmp_path / "codex-rs/rustfmt.toml"),
"--config",
"imports_granularity=Item",
"imports_granularity=Item,skip_children=true",
)
assert checks[1].commands[-1].args == (
"cargo",
"fmt",
"--",
"--config",
"imports_granularity=Item",
"--check",
rust_files = (
os.path.join("..", "bazel", "rules", "example.rs"),
"new file.rs",
os.path.join("src", "lib.rs"),
)
assert formatters[1].commands == (
script.Command(rustfmt_args + rust_files, tmp_path / "codex-rs"),
)
assert checks[1].commands == (
script.Command(rustfmt_args + ("--check",) + rust_files, tmp_path / "codex-rs"),
)
format_buildifier_args = formatters[2].commands[-1].args
check_buildifier_args = checks[2].commands[-1].args