forked from openai/codex
-
Notifications
You must be signed in to change notification settings - Fork 229
fix(exec): keep PATH for npm workspace commands (#5925) #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| fix(exec): keep PATH for npm workspace commands (#5925) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| ## Overview | ||
| - AutoRunPhase now carries struct payloads; controller exposes helpers (`is_active`, `is_paused_manual`, `resume_after_submit`, `awaiting_coordinator_submit`, `awaiting_review`, `in_transient_recovery`). | ||
| - ChatWidget hot paths (manual pause, coordinator routing, ESC handling, review exit) rely on helpers/`matches!` instead of raw booleans. | ||
| ## Summary | ||
| - preserve `PATH` (and `NVM_DIR` when present) across shell environment filtering so workspace commands like `npm` remain available | ||
| - continue to respect `use_profile` so commands run through the user's login shell when configured | ||
| - add unit coverage for the environment builder and an integration-style npm smoke test (skips automatically if npm is unavailable) | ||
|
|
||
| ## Tests | ||
| - `./build-fast.sh` | ||
| ## Testing | ||
| - ./build-fast.sh | ||
| - cargo test -p code-core --test npm_command *(fails: local cargo registry copy of `cc` 1.2.41 is missing generated modules; clear/update the registry and rerun)* | ||
|
|
||
| ## Follow-ups | ||
| - See `docs/auto-drive-phase-migration-TODO.md` for remaining legacy-flag removals and snapshot coverage. | ||
| Closes #5925. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ## Summary | ||
| - always preserve `PATH` (and `NVM_DIR`, if present) through `ShellEnvironmentPolicy` filtering so npm remains discoverable | ||
| - continue to wrap commands in the user shell when `use_profile` is enabled, ensuring profile-managed Node installations work | ||
| - add unit coverage for the environment builder and integration-style npm smoke tests (skipped automatically when npm is absent) | ||
|
|
||
| ## Testing | ||
| - ./build-fast.sh | ||
| - cargo test -p code-core --test npm_command *(fails: local cargo registry copy of `cc` 1.2.41 is missing generated modules; clear/update the crate cache and rerun)* | ||
|
|
||
| Closes #5925. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #![cfg(unix)] | ||
|
|
||
| use std::process::Command; | ||
| use std::time::Duration; | ||
|
|
||
| use code_core::exec_command::{result_into_payload, ExecCommandParams, ExecSessionManager}; | ||
| use serde_json::json; | ||
| use tempfile::tempdir; | ||
| use tokio::time::timeout; | ||
|
|
||
| fn make_params(cmd: &str, cwd: Option<&std::path::Path>) -> ExecCommandParams { | ||
| let mut value = json!({ | ||
| "cmd": cmd, | ||
| "yield_time_ms": 10_000u64, | ||
| "max_output_tokens": 10_000u64, | ||
| "shell": "/bin/bash", | ||
| "login": true | ||
| }); | ||
|
|
||
| if let Some(dir) = cwd { | ||
| value["cmd"] = json!(format!("cd {} && {cmd}", dir.display())); | ||
| } | ||
|
|
||
| serde_json::from_value(value).expect("deserialize ExecCommandParams") | ||
| } | ||
|
|
||
| fn npm_available() -> bool { | ||
| match Command::new("npm").arg("--version").output() { | ||
| Ok(output) => output.status.success(), | ||
| Err(_) => false, | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 4)] | ||
| async fn npm_version_executes() { | ||
| if !npm_available() { | ||
| eprintln!("skipping npm_version_executes: npm not available"); | ||
| return; | ||
| } | ||
|
|
||
| let manager = ExecSessionManager::default(); | ||
| let params = make_params("npm --version", None); | ||
|
|
||
| let summary = manager | ||
| .handle_exec_command_request(params) | ||
| .await | ||
| .map(|output| result_into_payload(Ok(output))) | ||
| .expect("exec request should succeed"); | ||
|
|
||
| assert_eq!(summary.success, Some(true)); | ||
| assert!( | ||
| summary.content.contains("Process exited with code 0"), | ||
| "npm --version should exit successfully" | ||
| ); | ||
| assert!( | ||
| summary.content.to_lowercase().contains("npm"), | ||
| "version output should include npm" | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 4)] | ||
| async fn npm_init_creates_package_json() { | ||
| if !npm_available() { | ||
| eprintln!("skipping npm_init_creates_package_json: npm not available"); | ||
| return; | ||
| } | ||
|
|
||
| let temp = tempdir().expect("create temp dir"); | ||
| let workspace = temp.path(); | ||
|
|
||
| let manager = ExecSessionManager::default(); | ||
| let params = make_params("npm init -y", Some(workspace)); | ||
|
|
||
| let exec_future = manager.handle_exec_command_request(params); | ||
| let summary = timeout(Duration::from_secs(30), exec_future) | ||
| .await | ||
| .expect("npm init should complete within timeout") | ||
| .map(|output| result_into_payload(Ok(output))) | ||
| .expect("exec request should succeed"); | ||
|
|
||
| assert_eq!(summary.success, Some(true)); | ||
| assert!( | ||
| summary.content.contains("Process exited with code 0"), | ||
| "npm init should exit successfully" | ||
| ); | ||
|
|
||
| let package_json = workspace.join("package.json"); | ||
| assert!(package_json.exists(), "npm init should create package.json"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
preserved_varslogic re‑addsPATH/NVM_DIRafter all filtering even when the policy isShellEnvironmentPolicyInherit::None. In that mode callers explicitly request a completely clean environment and the existingtest_inherit_noneasserts that only variables set viar#setremain. With the unconditionalfor (key, value) in preserved_vars { env_map.entry(key).or_insert(value); }block,PATHis inserted back into the map, breaking that contract and causing theinherit Nonetest to fail as well as leaking host PATH into supposedly sandboxed processes. Consider skipping the reinsertion wheninheritisNoneor when the key was not present inenv_mapprior to filtering.Useful? React with 👍 / 👎.