Files
ai-agent/sidecar/test_launch_tools_env.py
gabrielvidalandClaude Opus 5.5 c6e15991c2 fix(cron,sidecar): a guest's job and pi runs reach their tool proxy
A guest's scheduled job had no tools scope, so the lab's shims (meta,
nanobanana…) saw AIA_GUEST without AIA_TOOLS_TOKEN and refused: Cel's
10:00 Meta recap ran `meta` as nobody and mailed « Récap impossible »
whatever her key. scope_for_job now carries tool_scope() like a chat run.

The pi harness never exported scope.tools (only claude's settings env
did): the sidecar's _launch now sets AIA_TOOLS_URL / AIA_TOOLS_TOKEN from
the scope for every harness, and drops an inherited pair otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:00:34 +01:00

45 lines
2.0 KiB
Python

"""A scoped run's tool proxy (launch._launch): every harness gets the guest's
own ``AIA_TOOLS_URL`` / ``AIA_TOOLS_TOKEN`` from ``scope.tools`` — a pi run
has no settings env to carry them — and never one it inherited."""
import json
import sys
import guest_git
import launch
import pids
PRINT_ENV = [sys.executable, "-c",
"import json, os; print(json.dumps({k: os.environ.get(k) for k in "
"('AIA_GUEST', 'AIA_TOOLS_URL', 'AIA_TOOLS_TOKEN')}))"]
SID = "00000000-0000-0000-0000-00000000c0de"
def _env_of(tmp_path, monkeypatch, scope, inherited=None):
monkeypatch.setattr(launch, "LOG_DIR", tmp_path)
monkeypatch.setattr(pids, "LOG_DIR", tmp_path)
monkeypatch.setattr(guest_git, "STATE_DIR", tmp_path / "state")
monkeypatch.setattr(guest_git, "GLOBAL_CONFIG", tmp_path / "state" / "gitconfig")
env = {"PATH": "/usr/bin:/bin", **(inherited or {})}
launch._launch(PRINT_ENV, SID, str(tmp_path), harness="pi", env=env, scope=scope)
proc = pids._procs.pop(SID)
proc.wait(timeout=10)
return json.loads((tmp_path / f"{SID}.log").read_text().strip().splitlines()[-1])
def test_a_scoped_run_gets_the_guests_tool_proxy(tmp_path, monkeypatch):
scope = {"git": {"user": "cel", "push": []},
"tools": {"url": "https://hub.example/proxy/tools", "token": "tok-cel-0123456789"}}
got = _env_of(tmp_path, monkeypatch, scope,
inherited={"AIA_TOOLS_URL": "http://127.0.0.1:8096/proxy/tools",
"AIA_TOOLS_TOKEN": "owner-token"})
assert got == {"AIA_GUEST": "cel", "AIA_TOOLS_URL": "https://hub.example/proxy/tools",
"AIA_TOOLS_TOKEN": "tok-cel-0123456789"}
def test_a_scoped_run_without_tools_inherits_none(tmp_path, monkeypatch):
got = _env_of(tmp_path, monkeypatch, {"git": {"user": "cel", "push": []}},
inherited={"AIA_TOOLS_URL": "http://127.0.0.1:8096/proxy/tools",
"AIA_TOOLS_TOKEN": "owner-token"})
assert got == {"AIA_GUEST": "cel", "AIA_TOOLS_URL": None, "AIA_TOOLS_TOKEN": None}