mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-17 01:26:40 +03:00
fix(cli): isolate management subprocess environments
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
|
||||
from nanobot.apps.cli.service import CliAppManager
|
||||
|
||||
|
||||
@@ -67,3 +69,22 @@ def test_run_passes_filtered_env(monkeypatch, tmp_path) -> None:
|
||||
env = captured.get("env")
|
||||
assert isinstance(env, dict)
|
||||
assert "OPENAI_API_KEY" not in env
|
||||
|
||||
|
||||
def test_management_subprocesses_use_filtered_env(monkeypatch, tmp_path) -> None:
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "sk-should-not-leak")
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
def fake_run(*args, **kwargs):
|
||||
captured.update(kwargs)
|
||||
return subprocess.CompletedProcess(args[0], 0, stdout="ok", stderr="")
|
||||
|
||||
monkeypatch.setattr("nanobot.apps.cli.service.subprocess.run", fake_run)
|
||||
manager = CliAppManager(workspace=tmp_path, data_dir=tmp_path / "cli-apps")
|
||||
|
||||
manager._run_argv(["example-cli", "--help"], timeout=5)
|
||||
|
||||
env = captured.get("env")
|
||||
assert isinstance(env, dict)
|
||||
assert "OPENAI_API_KEY" not in env
|
||||
assert env["PYTHONUNBUFFERED"] == "1"
|
||||
|
||||
Reference in New Issue
Block a user