diff --git a/.bazelrc b/.bazelrc index 2239e75c0f..1f804fcd9f 100644 --- a/.bazelrc +++ b/.bazelrc @@ -13,6 +13,9 @@ startup --experimental_remote_repo_contents_cache # rules_python 2.x requires symlink support for Windows Python launchers. startup --windows_enable_symlinks +# Start Python launchers with their declared interpreter on lean workers. +common --@rules_python//python/config_settings:bootstrap_impl=script + common --experimental_platform_in_output_dir # Match Cargo's MSVC static CRT policy and V8's allocator linkage. Only the diff --git a/codex-rs/core/BUILD.bazel b/codex-rs/core/BUILD.bazel index 723cee347c..5c8219b94d 100644 --- a/codex-rs/core/BUILD.bazel +++ b/codex-rs/core/BUILD.bazel @@ -18,6 +18,7 @@ codex_rust_crate( "//codex-rs/windows-sandbox-rs:codex-command-runner", "//codex-rs/windows-sandbox-rs:codex-windows-managed-deny-probe", "//codex-rs/windows-sandbox-rs:codex-windows-sandbox-setup", + "@python_3_12//:python3", ], integration_compile_data_extra = glob(["assets/**"]) + [ "//codex-rs/message-board:tests/common/mod.rs", @@ -33,6 +34,7 @@ codex_rust_crate( test_data_extra = [ "//codex-rs/message-board-mcp:package-files", "config.schema.json", + "@python_3_12//:files", ] + glob(["src/**/snapshots/**"]) + [ ], test_shard_counts = { diff --git a/codex-rs/core/src/mcp_tool_call_tests.rs b/codex-rs/core/src/mcp_tool_call_tests.rs index e11bf8e32a..cd6005254f 100644 --- a/codex-rs/core/src/mcp_tool_call_tests.rs +++ b/codex-rs/core/src/mcp_tool_call_tests.rs @@ -293,15 +293,8 @@ print({hook_output:?}) ); std::fs::write(&script_path, script).expect("write MCP permission hook script"); - let python = if cfg!(windows) { "python" } else { "python3" }; - let script_path_arg = if cfg!(windows) { - script_path.display().to_string() - } else { - format!( - "'{}'", - script_path.display().to_string().replace('\'', "'\\''") - ) - }; + let python = std::env::var("CARGO_BIN_EXE_python3") + .unwrap_or_else(|_| if cfg!(windows) { "python" } else { "python3" }.to_owned()); std::fs::write( turn_context.config.codex_home.join("hooks.json"), serde_json::json!({ @@ -310,7 +303,7 @@ print({hook_output:?}) "matcher": matcher, "hooks": [{ "type": "command", - "command": format!("{python} {script_path_arg}"), + "command": script_path.to_str().expect("UTF-8 hook script path"), "timeout_sec": 5, }] }] @@ -334,12 +327,7 @@ print({hook_output:?}) let hooks = session.hooks().reconfigured(HooksConfig { feature_enabled: true, config_layer_stack: Some(trusted_config_layer_stack), - shell_program: (!cfg!(windows)).then_some("/bin/sh".to_string()), - shell_args: if cfg!(windows) { - Vec::new() - } else { - vec!["-c".to_string()] - }, + shell_program: Some(python), ..HooksConfig::default() }); session.services.hooks.store(Arc::new(hooks)); @@ -3154,22 +3142,26 @@ async fn permission_request_hook_allows_mcp_tool_call() { openai_file_input_optional_fields: None, }; - let decision = maybe_request_mcp_tool_approval( - &session, - &StepContext::for_test(Arc::clone(&turn_context)), - &CancellationToken::new(), - "call-mcp-hook", - &invocation, - &ToolName::namespaced(&invocation.server, &invocation.tool), - &HookToolName::new("mcp__memory__create_entities"), - &metadata, - &approval_config(&turn_context), - thread_permission_source(&turn_context), - test_environment_id(&turn_context), - &McpServerKey::unscoped(&invocation.server), - McpToolApprovalPolicy::for_server(AppToolApproval::Auto), + let decision = tokio::time::timeout( + Duration::from_secs(15), + maybe_request_mcp_tool_approval( + &session, + &StepContext::for_test(Arc::clone(&turn_context)), + &CancellationToken::new(), + "call-mcp-hook", + &invocation, + &ToolName::namespaced(&invocation.server, &invocation.tool), + &HookToolName::new("mcp__memory__create_entities"), + &metadata, + &approval_config(&turn_context), + thread_permission_source(&turn_context), + test_environment_id(&turn_context), + &McpServerKey::unscoped(&invocation.server), + McpToolApprovalPolicy::for_server(AppToolApproval::Auto), + ), ) - .await; + .await + .expect("permission hook should resolve approval without waiting for a reviewer"); assert_eq!( decision, @@ -3235,22 +3227,26 @@ async fn permission_request_hook_uses_hook_tool_name_without_metadata() { /*tool_description*/ None, ); - let decision = maybe_request_mcp_tool_approval( - &session, - &StepContext::for_test(Arc::clone(&turn_context)), - &CancellationToken::new(), - "call-mcp-hook-no-metadata", - &invocation, - &ToolName::namespaced(&invocation.server, &invocation.tool), - &HookToolName::new("mcp__memory__create_entities"), - &metadata, - &approval_config(&turn_context), - thread_permission_source(&turn_context), - test_environment_id(&turn_context), - &McpServerKey::unscoped(&invocation.server), - McpToolApprovalPolicy::for_server(AppToolApproval::Auto), + let decision = tokio::time::timeout( + Duration::from_secs(15), + maybe_request_mcp_tool_approval( + &session, + &StepContext::for_test(Arc::clone(&turn_context)), + &CancellationToken::new(), + "call-mcp-hook-no-metadata", + &invocation, + &ToolName::namespaced(&invocation.server, &invocation.tool), + &HookToolName::new("mcp__memory__create_entities"), + &metadata, + &approval_config(&turn_context), + thread_permission_source(&turn_context), + test_environment_id(&turn_context), + &McpServerKey::unscoped(&invocation.server), + McpToolApprovalPolicy::for_server(AppToolApproval::Auto), + ), ) - .await; + .await + .expect("permission hook should resolve approval without waiting for a reviewer"); assert_eq!( decision, diff --git a/defs.bzl b/defs.bzl index caca84b315..1217f89f06 100644 --- a/defs.bzl +++ b/defs.bzl @@ -164,6 +164,7 @@ workspace_root_test = rule( "env": attr.string_dict(), "env_inherit": attr.string_list(), "runfile_env": attr.label_keyed_string_dict( + allow_files = True, cfg = "target", ), "test_bin": attr.label(