Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

test: avoid platform leaks in cli tool tests

JerrettDavis96c7e940fb27
diff --git a/headroom/cli/tools.py b/headroom/cli/tools.py
index 39e767b8c..1cc0b8673 100644
--- a/headroom/cli/tools.py
+++ b/headroom/cli/tools.py
@@ -34,6 +34,10 @@ _PASSTHROUGH_CTX = {
}
+def _is_windows() -> bool:
+ return sys.platform.startswith("win")
+
+
def _exec_tool(tool: str, argv: Sequence[str]) -> None:
try:
path = binaries.resolve(tool)
@@ -58,7 +62,7 @@ def _exec_tool(tool: str, argv: Sequence[str]) -> None:
# that needs to clean up on shell exit must be handled elsewhere (e.g.
# the parent `headroom` process, not these thin passthroughs).
cmd = [str(path), *argv]
- if os.name == "posix":
+ if not _is_windows():
os.execv(cmd[0], cmd) # never returns
else:
completed = subprocess.run(cmd, check=False)
diff --git a/tests/test_cli_tools.py b/tests/test_cli_tools.py
index 913749bdf..a4ca0a0bc 100644
--- a/tests/test_cli_tools.py
+++ b/tests/test_cli_tools.py
@@ -51,7 +51,7 @@ def install_fake_rich(monkeypatch: pytest.MonkeyPatch) -> None:
def test_exec_tool_windows_and_posix_paths(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(cli_tools.binaries, "resolve", lambda tool: Path("C:\\bin\\sg.exe"))
- monkeypatch.setattr(cli_tools.os, "name", "nt", raising=False)
+ monkeypatch.setattr(cli_tools.sys, "platform", "win32")
captured: dict[str, object] = {}
def fake_run(cmd, check=False): # noqa: ANN001
@@ -64,7 +64,7 @@ def test_exec_tool_windows_and_posix_paths(monkeypatch: pytest.MonkeyPatch) -> N
assert excinfo.value.code == 7
assert captured["cmd"] == ["C:\\bin\\sg.exe", "--json"]
- monkeypatch.setattr(cli_tools.os, "name", "posix", raising=False)
+ monkeypatch.setattr(cli_tools.sys, "platform", "linux")
def fake_execv(path: str, cmd: list[str]) -> None:
raise SystemExit((path, cmd))