Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

Fix Vault avault TPM stderr noise (#767)

Call White324ed58a4da2
diff --git a/tests/test_vault_api.py b/tests/test_vault_api.py
index c5fa189ca..4b66fe75a 100644
--- a/tests/test_vault_api.py
+++ b/tests/test_vault_api.py
@@ -623,6 +623,104 @@ def test_pubkey_wrapper_parses_avault(monkeypatch):
assert api.avault_pubkey() == {"public_key": "pk", "fingerprint": "fp"}
+def test_avault_args_uses_file_store_only_on_linux_without_tpm(monkeypatch, tmp_path):
+ missing_tpm = tmp_path / "missing-tpm0"
+ existing_tpm = tmp_path / "tpmrm0"
+ existing_tpm.touch()
+ monkeypatch.setattr(api, "_AVAULT_LINUX_TPM_DEVICE_PATHS", (missing_tpm,))
+ monkeypatch.setattr(api.platform, "system", lambda: "Linux")
+ assert api._avault_args(["pubkey"]) == ["--store", "file", "pubkey"]
+
+ monkeypatch.setattr(api, "_AVAULT_LINUX_TPM_DEVICE_PATHS", (existing_tpm,))
+ assert api._avault_args(["pubkey"]) == ["pubkey"]
+
+ monkeypatch.setattr(api.platform, "system", lambda: "Darwin")
+ assert api._avault_args(["pubkey"]) == ["pubkey"]
+
+
+def test_one_shot_avault_uses_file_store_for_linux_without_tpm(monkeypatch, tmp_path):
+ from types import SimpleNamespace
+
+ seen: dict[str, object] = {}
+
+ def fake_run(argv, **kwargs):
+ seen["argv"] = argv
+ seen["kwargs"] = kwargs
+ return SimpleNamespace(returncode=0, stdout=b"{}", stderr=b"")
+
+ monkeypatch.setattr(api, "_require_avault_path", lambda: "/tmp/avault")
+ monkeypatch.setattr(api, "_command_env_for", lambda path: {"AVAULT_PATH": path})
+ monkeypatch.setattr(api.platform, "system", lambda: "Linux")
+ monkeypatch.setattr(api, "_AVAULT_LINUX_TPM_DEVICE_PATHS", (tmp_path / "missing-tpm0",))
+ monkeypatch.setattr(api.subprocess, "run", fake_run)
+
+ api._run_avault(["pubkey"], stdin=b"{}", timeout=3)
+
+ assert seen["argv"] == ["/tmp/avault", "--store", "file", "pubkey"]
+ kwargs = seen["kwargs"]
+ assert kwargs["input"] == b"{}"
+ assert kwargs["capture_output"] is True
+ assert kwargs["timeout"] == 3
+ assert kwargs["env"] == {"AVAULT_PATH": "/tmp/avault"}
+
+
+def test_deliver_run_uses_file_store_for_linux_without_tpm(monkeypatch, tmp_path):
+ seen: dict[str, object] = {}
+
+ class FakeStdin:
+ def write(self, payload):
+ seen["stdin"] = payload
+
+ def close(self):
+ seen["stdin_closed"] = True
+
+ class FakeProcess:
+ stdin = FakeStdin()
+
+ def wait(self):
+ return 7
+
+ def fake_popen(argv, **kwargs):
+ seen["argv"] = argv
+ seen["kwargs"] = kwargs
+ return FakeProcess()
+
+ monkeypatch.setattr(api, "_require_avault_path", lambda: "/tmp/avault")
+ monkeypatch.setattr(api, "_command_env_for", lambda path: {"AVAULT_PATH": path})
+ monkeypatch.setattr(api.platform, "system", lambda: "Linux")
+ monkeypatch.setattr(api, "_AVAULT_LINUX_TPM_DEVICE_PATHS", (tmp_path / "missing-tpm0",))
+ monkeypatch.setattr(api.subprocess, "Popen", fake_popen)
+
+ result = api.avault_deliver_run(
+ [{"name": "API_KEY", "env": "API_KEY", "envelope": _sealed("api")}],
+ ["python3", "-c", "pass"],
+ )
+
+ assert result == {"exit_code": 7, "delivered": True}
+ assert seen["argv"] == [
+ "/tmp/avault",
+ "--store",
+ "file",
+ "deliver",
+ "run",
+ "--",
+ "python3",
+ "-c",
+ "pass",
+ ]
+ kwargs = seen["kwargs"]
+ assert kwargs["stdin"] == api.subprocess.PIPE
+ assert kwargs["env"] == {"AVAULT_PATH": "/tmp/avault"}
+ assert seen["stdin_closed"] is True
+ assert json.loads(seen["stdin"]) == [
+ {
+ "name": "API_KEY",
+ "env": "API_KEY",
+ "envelope": {"ciphertext": "ct-api", "nonce": "n-api", "wrap_meta": "wm-api"},
+ }
+ ]
+
+
def test_blind_box_wrapper_relays_json_to_avault(monkeypatch):
from types import SimpleNamespace
diff --git a/vibe/api.py b/vibe/api.py
index 68197ca95..7d4c85bad 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -3,6 +3,7 @@ import contextlib
import json
import logging
import os
+import platform
import re
import shutil
import ssl
@@ -5328,6 +5329,10 @@ def _require_avault_grant_delivery_surface(feature: str) -> None:
# avibe's wait must outlast avault's own fetch timeout (10s connect + 30s total).
_AVAULT_TIMEOUT_SECONDS = 20.0
_AVAULT_FETCH_TIMEOUT_SECONDS = 60.0
+_AVAULT_STORE = "file"
+_AVAULT_LINUX_TPM_DEVICE_PATHS = (Path("/dev/tpm0"), Path("/dev/tpmrm0"))
+
+
class AvaultError(Exception):
"""An ``avault`` invocation failed. Messages never carry secret material —
avault is designed to keep secrets out of its stdout/stderr and errors."""
@@ -5370,6 +5375,18 @@ def _avault_agent_manager():
return manager
+def _avault_store_args() -> list[str]:
+ if platform.system().lower() != "linux":
+ return []
+ if any(path.exists() for path in _AVAULT_LINUX_TPM_DEVICE_PATHS):
+ return []
+ return ["--store", _AVAULT_STORE]
+
+
+def _avault_args(args: list[str]) -> list[str]:
+ return [*_avault_store_args(), *args]
+
+
def _run_avault(
args: list[str],
*,
@@ -5380,7 +5397,7 @@ def _run_avault(
path = _require_avault_path()
try:
return subprocess.run(
- [path, *args],
+ [path, *_avault_args(args)],
input=stdin,
capture_output=True,
timeout=timeout,
@@ -5521,7 +5538,7 @@ def avault_deliver_run(secrets: list[dict], command: list[str]) -> dict:
).encode("utf-8")
try:
proc = subprocess.Popen(
- [path, "deliver", "run", "--", *command],
+ [path, *_avault_args(["deliver", "run"]), "--", *command],
stdin=subprocess.PIPE,
env=_command_env_for(path),
**isolated_subprocess_kwargs(),