Skip to content

mock_command: add new_command_with_env so compiler children get only the client environment - #3016

Merged
sylvestre merged 3 commits into
mozilla:mainfrom
loganrosen:loganrosen-run-command-explicit-env
Nov 27, 2026
Merged

sylvestre merged 3 commits into
mozilla:mainfrom
loganrosen:loganrosen-run-command-explicit-env

Conversation

@loganrosen

Copy link
Copy Markdown
Contributor

Every compiler invocation had to remember to call env_clear() before envs(env_vars). Forgetting it leaks the server's environment into the compiler without any error.

This adds CommandCreatorSync::new_command_with_env, which does both, and moves every call site that passes the client environment over to it. The client's direct compile and compiler/assembler detection are left alone, since they deliberately build on the inherited environment.

MockCommand now records env, env_clear and current_dir instead of ignoring them. next_command_inspects lets a test see the whole command. There are new tests for SingleCompileCommand::execute and gcc preprocessing. I checked that both fail if the env_clear is removed.

Fixes #95

Locally, fmt and the lib tests pass. Clippy fails on rustc 1.99 with pre-existing lints, and does the same on main. tests/sccache_cargo.rs fails intermittently both with and without this change.

@codecov-commenter

codecov-commenter commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.67925% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.02%. Comparing base (1c7b8fc) to head (013cf41).

Files with missing lines Patch % Lines
src/compiler/tasking_vx.rs 0.00% 6 Missing ⚠️
src/compiler/nvhpc.rs 0.00% 5 Missing ⚠️
src/compiler/diab.rs 0.00% 3 Missing ⚠️
src/compiler/msvc.rs 50.00% 3 Missing ⚠️
src/compiler/gcc.rs 97.56% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3016      +/-   ##
==========================================
+ Coverage   79.99%   80.02%   +0.02%     
==========================================
  Files          76       76              
  Lines       47374    47413      +39     
==========================================
+ Hits        37898    37942      +44     
+ Misses       9476     9471       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sylvestre

Copy link
Copy Markdown
Collaborator

sorry but it needs to be rebased

Comment thread src/mock_command.rs Outdated
dead_code,
reason = "Read in the async_trait below, but rustc doesn't see it as used"
)]
Inspect(Box<dyn Fn(&MockCommand) -> Result<MockChild> + Send>),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could Call just take the &MockCommand instead of adding a second variant? it is almost the same thing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good call. Call now takes &MockCommand, and next_command_calls just forwards &cmd.args so the existing callers didn't need to change.

Comment thread src/compiler/compiler.rs

#[test]
#[cfg(unix)]
fn test_single_compile_command_uses_only_client_env() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is almost the same test as test_new_command_with_env_hides_server_env in mock_command.rs, do we need both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, dropped the one in mock_command.rs. This one is more useful since it actually goes through a call site. Also rebased on main.

@loganrosen
loganrosen force-pushed the loganrosen-run-command-explicit-env branch from d41ba8d to e1087b8 Compare November 14, 2026 22:57
loganrosen and others added 3 commits November 24, 2026 22:46
Every compiler invocation had to remember to call env_clear() before
envs(), and forgetting it silently leaks the server's environment into
the compiler. new_command_with_env does both, and all the call sites
that pass the client's environment now go through it. The few places
that deliberately layer onto the server environment (direct client
compile, compiler/assembler detection) are left alone.

MockCommand now records env, env_clear and current_dir so tests can see
what a command would have run with.

Fixes mozilla#95

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
MockCommandCreator::next_command_inspects lets a test see the whole
command, not just its arguments.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@loganrosen
loganrosen force-pushed the loganrosen-run-command-explicit-env branch from e1087b8 to 013cf41 Compare November 25, 2026 03:55
@loganrosen
loganrosen requested a review from sylvestre November 25, 2026 04:08
@sylvestre
sylvestre merged commit c6092c3 into mozilla:main Nov 27, 2026
51 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a higher-level interface to RunCommand

3 participants