Skip to content

bazel: run wrapped Rust unit test shards#18913

Merged
bolinfest merged 1 commit intomainfrom
pr18913
Apr 22, 2026
Merged

bazel: run wrapped Rust unit test shards#18913
bolinfest merged 1 commit intomainfrom
pr18913

Conversation

@bolinfest
Copy link
Copy Markdown
Collaborator

@bolinfest bolinfest commented Apr 22, 2026

Why

The codex-tui Cargo test suite was catching stale snapshot expectations, but the matching Bazel unit-test target was still green. The TUI unit target is wrapped by workspace_root_test so tests run from the repository root and Insta can resolve Cargo-like snapshot paths. After native Bazel sharding was enabled for that wrapped target, rules_rust also inserted its own sharding wrapper around the Rust test binary.

Those two wrappers did not compose: rules_rust's sharding wrapper expects to run from its own runfiles cwd, while workspace_root_test deliberately changes cwd to the repo root before invoking the test. In that configuration, the inner wrapper could fail to enumerate the Rust tests and exit successfully with empty shards, so snapshot regressions were not being exercised by Bazel.

What Changed

  • Stop enabling rules_rust's inner experimental_enable_sharding for unit-test binaries created by codex_rust_crate.
  • Keep the configured shard_count on the outer workspace_root_test target.
  • Add libtest sharding directly to workspace_root_test_launcher.sh.tpl and workspace_root_test_launcher.bat.tpl after the launcher has resolved the actual test binary and established the intended repository-root cwd.
  • Partition tests by a stable FNV-1a hash of each libtest test name, matching the stable-shard behavior we wanted without depending on the inner rules_rust wrapper.
  • Preserve ad-hoc local test filters by running the resolved test binary directly when explicit test args are supplied.
  • On Windows, run selected libtest names from the shard list in bounded PowerShell batches instead of concatenating every selected test into one cmd.exe command line.

This PR is stacked on top of #18912, which contains only the snapshot expectation updates exposed once the Bazel target actually runs the TUI unit tests. It is also the reason #18916 becomes visible: once this wrapper fix makes Bazel execute the affected codex-core test, that test needs its own executable-path setup fixed.

Verification

  • cargo test -p codex-tui
  • bazel test //codex-rs/tui:tui-unit-tests --test_output=errors
  • bazel test //codex-rs/tui:all --test_output=errors
  • bash -n workspace_root_test_launcher.sh.tpl
  • Exercised the Windows PowerShell batching fragment locally with a fake test binary and shard-list file.

Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 960d5145fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread workspace_root_test_launcher.bat.tpl Outdated
exit /b 0
)

"%test_bin%" !SHARD_TESTS! --exact
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid cmd.exe argument overflow for sharded test names

This launcher concatenates every selected test into SHARD_TESTS and invokes one command ("%test_bin%" !SHARD_TESTS! --exact), which can exceed cmd.exe’s ~8191-character command-line limit on large shards (for example, crates like tui with many long test paths). When that happens, the shard fails before running tests, so Windows sharded unit-test runs become unreliable as suites grow.

Useful? React with 👍 / 👎.

bolinfest added a commit that referenced this pull request Apr 22, 2026
…mpt_snapshot did not match windows output (#18915)

Fix a snapshot test that is failing on Windows, but is currently missed
by Bazel due to #18913. We see this
failing on Cargo builds on Windows, though.

This Bazel vs. Cargo inconsistency explains why
#18768 did not fix the Cargo Windows
build.
@bolinfest bolinfest requested a review from a team as a code owner April 22, 2026 00:43
@bolinfest bolinfest changed the base branch from pr18912 to pr18916 April 22, 2026 00:43
Base automatically changed from pr18916 to main April 22, 2026 01:08
bolinfest added a commit that referenced this pull request Apr 22, 2026
## Why

`build_prompt_input` now initializes `ExecServerRuntimePaths`, which
requires a configured Codex executable path. The previous inline unit
test in `core/src/prompt_debug.rs` built a bare `test_config()` and then
failed before it could assert anything useful:

```text
Codex executable path is not configured
```

This coverage is also integration-shaped: it drives the public
`build_prompt_input` entry point through config, thread, and session
setup rather than testing a small internal helper in isolation.

Bazel CI did not catch this earlier because the affected test was behind
the same wrapped Rust unit-test path fixed by #18913. Before that
launcher/sharding fix, the outer `workspace_root_test` changed the
working directory for Insta compatibility while the inner `rules_rust`
sharding wrapper still expected its runfiles working directory. In
practice, Bazel could report success without executing the Rust test
cases in that shard. Once #18913 makes the wrapper run the Rust test
binary directly and shard with libtest arguments, this stale unit test
actually runs and exposes the missing `codex_self_exe` setup.

## What Changed

- Moved `build_prompt_input_includes_context_and_user_message` out of
`core/src/prompt_debug.rs`.
- Added `core/tests/suite/prompt_debug_tests.rs` and registered it from
`core/tests/suite/mod.rs`.
- Builds the test config with `ConfigBuilder` and provides
`codex_self_exe` using the current test executable, matching the
runtime-path invariant required by prompt debug setup.
- Preserves the existing assertions that the generated prompt input
includes both the debug user message and project-specific user
instructions.

## Verification

- `cargo test -p codex-core --test all
prompt_debug_tests::build_prompt_input_includes_context_and_user_message`
- `bazel test //codex-rs/core:core-all-test
--test_arg=prompt_debug_tests::build_prompt_input_includes_context_and_user_message
--test_output=errors`

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/18916).
* #18913
* __->__ #18916
@bolinfest bolinfest enabled auto-merge (squash) April 22, 2026 01:13
@bolinfest bolinfest disabled auto-merge April 22, 2026 01:35
@bolinfest bolinfest merged commit 536952e into main Apr 22, 2026
45 of 46 checks passed
@bolinfest bolinfest deleted the pr18913 branch April 22, 2026 01:35
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants