fix: avoid Windows integration bootstrap crashes

This commit is contained in:
Kazuhiro Sera
2026-08-19 07:16:06 +09:00
parent 32e452671c
commit 21a1f9b4e6
2 changed files with 42 additions and 4 deletions
+3
View File
@@ -100,6 +100,9 @@ def bootstrap_in_uv(
child_env = dict(environ)
child_env[BOOTSTRAPPED_ENV] = "1"
command = ["uv", "run", "python", str(Path(__file__).resolve()), *arguments]
if sys.platform == "win32":
completed = subprocess.run(command, env=child_env, check=False)
raise SystemExit(completed.returncode)
exec_function(command[0], command, child_env)
raise RuntimeError("The uv integration runner bootstrap returned unexpectedly.")
+39 -4
View File
@@ -78,7 +78,7 @@ def test_live_profiles_refuse_untrusted_credentials_before_side_effects(
):
bootstrap_in_uv(
["--profile", profile],
{"OPENAI_API_KEY": "inherited-employee-key"},
{"OPENAI_API_KEY": "placeholder-key"},
lambda *args: child_processes.append("uv"),
)
@@ -89,11 +89,13 @@ def test_live_profiles_refuse_untrusted_credentials_before_side_effects(
"profile",
["packaging", "prospective-contract", "prospective-platform", "security", "mcp-v1", "extras"],
)
def test_local_only_profiles_remove_key_before_uv_child_process(profile: str) -> None:
def test_local_only_profiles_remove_key_before_uv_child_process(
profile: str, monkeypatch: pytest.MonkeyPatch
) -> None:
namespace = runpy.run_path(str(RUNNER))
bootstrap_in_uv = cast(Callable[..., None], namespace["bootstrap_in_uv"])
environment = {
"OPENAI_API_KEY": "inherited-employee-key",
"OPENAI_API_KEY": "placeholder-key",
"OPENAI_API_KEY_SOURCE": "employee",
}
captured: list[tuple[str, list[str], dict[str, str]]] = []
@@ -101,6 +103,8 @@ def test_local_only_profiles_remove_key_before_uv_child_process(profile: str) ->
def capture_exec(file: str, command: list[str], child_env: dict[str, str]) -> None:
captured.append((file, command, child_env))
monkeypatch.setattr(bootstrap_in_uv.__globals__["sys"], "platform", "linux")
with pytest.raises(RuntimeError, match="bootstrap returned unexpectedly"):
bootstrap_in_uv(["--profile", profile], environment, capture_exec)
@@ -112,6 +116,37 @@ def test_local_only_profiles_remove_key_before_uv_child_process(profile: str) ->
assert "OPENAI_API_KEY" not in environment
def test_windows_bootstrap_uses_subprocess_and_propagates_exit_code(
monkeypatch: pytest.MonkeyPatch,
) -> None:
namespace = runpy.run_path(str(RUNNER))
bootstrap_in_uv = cast(Callable[..., None], namespace["bootstrap_in_uv"])
environment = {"OPENAI_API_KEY": "placeholder-key"}
captured: list[tuple[list[str], dict[str, str], bool]] = []
def capture_run(command: list[str], *, env: dict[str, str], check: bool) -> SimpleNamespace:
captured.append((command, env, check))
return SimpleNamespace(returncode=23)
monkeypatch.setattr(bootstrap_in_uv.__globals__["sys"], "platform", "win32")
monkeypatch.setattr(bootstrap_in_uv.__globals__["subprocess"], "run", capture_run)
with pytest.raises(SystemExit) as exc_info:
bootstrap_in_uv(
["--profile", "prospective-platform"],
environment,
lambda *_args: pytest.fail("Windows bootstrap must not call os.execvpe"),
)
assert exc_info.value.code == 23
assert len(captured) == 1
assert captured[0][0][0:3] == ["uv", "run", "python"]
assert "OPENAI_API_KEY" not in captured[0][1]
assert captured[0][1][namespace["BOOTSTRAPPED_ENV"]] == "1"
assert captured[0][2] is False
assert "OPENAI_API_KEY" not in environment
def test_local_only_profile_removes_key_before_cleanup_build_and_children(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,
@@ -144,7 +179,7 @@ def test_local_only_profile_removes_key_before_cleanup_build_and_children(
_ = (args, kwargs)
assert_sanitized("run-suite")
monkeypatch.setenv("OPENAI_API_KEY", "inherited-employee-key")
monkeypatch.setenv("OPENAI_API_KEY", "placeholder-key")
monkeypatch.setenv("OPENAI_API_KEY_SOURCE", "employee")
monkeypatch.setattr(sys, "argv", [str(RUNNER), "--profile", "packaging"])
monkeypatch.setitem(main.__globals__, "build_distributions", fake_build_distributions)