Generic platform points for the `diff-viewer` and `commits` plugins (ai-agent-plugins): a `conversation.tab` slot (Thread | Changes N) with setTab/openTab/closeTab/reply bridges; stackable + pullOut tool cards and match.hasReport; `pathShims` (a git PATH shim for every harness) with out-of-band reports (lab: /api/plugin-reports, worker: outbox `report`); `conversations.reports` and `diff.read` hub bridges; ui.pages[].opens for Project/Service "Recent commits". The core commit card, Changes view, diff page and review store are gone; bash_diff.py keeps bashDiff only. Legacy gitCommits / commit-line parsing stays for past transcripts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
152 lines
6.8 KiB
Python
152 lines
6.8 KiB
Python
"""Shared by every sidecar test.
|
|
|
|
1. Nothing a test launches may leave files in the real home — a run's
|
|
settings holding a credential go to a 0600 file
|
|
(``claude_proxy.secrets_out_of_argv``), by default under ``~/.cache``.
|
|
|
|
2. **The harnesses are the real plugins.** The sidecar has no built-in driver
|
|
(strict plugin-only), so the tests run the ``harness-*`` / ``provider-*``
|
|
plugins of ``ai-agent-plugins`` — ``SIDECAR_SEED_PLUGINS_DIR`` (default
|
|
``~/projects/ai-agent-plugins/plugins``). Before any test module imports
|
|
the sidecar, ``SIDECAR_LIVE_HARNESSES_DIR`` / ``SIDECAR_LIVE_PROVIDERS_DIR``
|
|
are pointed at a throw-away live dir whose ``index.json`` names those
|
|
plugin dirs in place (so a test without ``SIDECAR_TOKEN`` — a worker —
|
|
loads them too; nothing is copied, an edit to a plugin is tested at once).
|
|
A test that sets either variable itself keeps its own.
|
|
|
|
3. The suites written against the old sidecar modules (``opencode_cli``,
|
|
``agy_mirror``, ``claude_accounts``, ``pi_runs``…) still import them by
|
|
those names: an import hook hands them the plugin's module that replaced
|
|
each one (``opencode_cli`` → harness-opencode's ``sidecar/cli.py``), loaded
|
|
through ``harness_loader`` / ``usage_loader`` exactly as the sidecar loads
|
|
it. Same tests, the plugins' code. (A plugin's own parity run — its
|
|
``-p legacy_alias`` — installs the names first; the hook then never runs.)
|
|
"""
|
|
|
|
import importlib.abc
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import sys
|
|
import tempfile
|
|
|
|
import pytest
|
|
|
|
PLUGINS = pathlib.Path(os.path.expanduser(
|
|
os.environ.get("SIDECAR_SEED_PLUGINS_DIR") or "~/projects/ai-agent-plugins/plugins"))
|
|
os.environ.setdefault("SIDECAR_SEED_PLUGINS_DIR", str(PLUGINS))
|
|
|
|
# legacy module name → (loader kind, plugin id, the plugin's module)
|
|
LEGACY = {
|
|
"claude_cli": ("harness", "harness-claude", "cli"),
|
|
"claude_accounts": ("harness", "harness-claude", "accounts"),
|
|
"pi_runs": ("harness", "harness-pi", "driver"),
|
|
"opencode_cli": ("harness", "harness-opencode", "cli"),
|
|
"opencode_mirror": ("harness", "harness-opencode", "mirror"),
|
|
"opencode_tools": ("harness", "harness-opencode", "tools"),
|
|
"opencode_usage": ("harness", "harness-opencode", "usage"),
|
|
"agy_cli": ("harness", "harness-agy", "cli"),
|
|
"agy_mirror": ("harness", "harness-agy", "mirror"),
|
|
"agy_tools": ("harness", "harness-agy", "tools"),
|
|
"agy_usage": ("harness", "harness-agy", "usage"),
|
|
"claude_usage": ("provider", "provider-anthropic", "usage"),
|
|
# harness-claude's since 2026-11-26 (they were the sidecar's own)
|
|
"stop_guard": ("harness", "harness-claude", "stop_guard"),
|
|
"bgtasks": ("harness", "harness-claude", "bgtasks"),
|
|
"turn_hook": ("harness", "harness-claude", "turn_hook"),
|
|
"conv_ref_hook": ("harness", "harness-claude", "conv_ref_hook"),
|
|
"claude_launch": ("harness", "harness-claude", "claude_launch"),
|
|
"gen_progress": ("provider", "provider-evox2", "gen_progress"),
|
|
"local_room": ("provider", "provider-evox2", "local_room"),
|
|
"local_ready": ("provider", "provider-evox2", "local_ready"),
|
|
}
|
|
|
|
|
|
def _live_index(kind: str, plural: str, key: str, id_key: str) -> pathlib.Path:
|
|
"""A live dir whose index.json names every plugin of ``kind`` under
|
|
PLUGINS, in place."""
|
|
d = pathlib.Path(tempfile.mkdtemp(prefix=f"sidecar-tests-live-{plural}-"))
|
|
items = {}
|
|
for pdir in sorted(PLUGINS.glob(f"{kind}-*")) if PLUGINS.is_dir() else []:
|
|
try:
|
|
man = json.loads((pdir / "plugin.json").read_text())
|
|
except (OSError, ValueError):
|
|
continue
|
|
obj = man.get(key) if isinstance(man, dict) else None
|
|
if not isinstance(obj, dict) or not isinstance(obj.get(id_key), str):
|
|
continue
|
|
code = obj.get("sidecar") if kind == "harness" else (obj.get("usageReader")
|
|
or obj.get("sidecar"))
|
|
items[obj[id_key]] = {
|
|
"pluginId": man.get("id") or pdir.name, "dir": str(pdir),
|
|
"entry": (code or {}).get("entry") if isinstance(code, dict) else None,
|
|
"guestAllowed": bool(obj.get("guestAllowed"))}
|
|
(d / "index.json").write_text(json.dumps({"version": 1, plural: items}))
|
|
return d
|
|
|
|
|
|
if "SIDECAR_LIVE_HARNESSES_DIR" not in os.environ:
|
|
os.environ["SIDECAR_LIVE_HARNESSES_DIR"] = str(
|
|
_live_index("harness", "harnesses", "harness", "harnessId"))
|
|
if "SIDECAR_LIVE_PROVIDERS_DIR" not in os.environ:
|
|
os.environ["SIDECAR_LIVE_PROVIDERS_DIR"] = str(
|
|
_live_index("provider", "providers", "provider", "vendorId"))
|
|
if "SIDECAR_LIVE_HOOKS_DIR" not in os.environ:
|
|
# no plugin's harnessHooks unless a test writes some (test_plugin_hooks.py)
|
|
import tempfile as _tempfile
|
|
os.environ["SIDECAR_LIVE_HOOKS_DIR"] = str(
|
|
pathlib.Path(_tempfile.mkdtemp(prefix="live-hooks-")) / "live-hooks")
|
|
if "SIDECAR_SHIMS_DIR" not in os.environ:
|
|
# path shims' wrappers and report spool (path_shims.py): never ~/.cache
|
|
import tempfile as _tempfile
|
|
os.environ["SIDECAR_SHIMS_DIR"] = _tempfile.mkdtemp(prefix="shims-")
|
|
|
|
|
|
def plugin_module(kind: str, plugin_id: str, name: str):
|
|
"""A plugin's own module, loaded the way the sidecar loads it."""
|
|
pkg = f"sidecar_ext.{kind}.{plugin_id.replace('-', '_')}"
|
|
full = f"{pkg}.{name}"
|
|
if full not in sys.modules:
|
|
loader = (__import__("harness_loader") if kind == "harness"
|
|
else __import__("usage_loader")).LOADER
|
|
loader._ensure()
|
|
if full not in sys.modules and pkg in sys.modules:
|
|
importlib.import_module(full)
|
|
mod = sys.modules.get(full)
|
|
if mod is None:
|
|
raise ImportError(f"{plugin_id} isn't loaded (no {PLUGINS / plugin_id}?) — "
|
|
f"no {name} module for the legacy name")
|
|
return mod
|
|
|
|
|
|
class _LegacyLoader(importlib.abc.Loader):
|
|
def create_module(self, spec):
|
|
return None
|
|
|
|
def exec_module(self, module):
|
|
kind, pid, name = LEGACY[module.__name__]
|
|
# A module may replace itself in sys.modules: the import returns it.
|
|
sys.modules[module.__name__] = plugin_module(kind, pid, name)
|
|
|
|
|
|
class _LegacyFinder(importlib.abc.MetaPathFinder):
|
|
def find_spec(self, fullname, path=None, target=None):
|
|
if fullname in LEGACY and fullname not in sys.modules:
|
|
return importlib.util.spec_from_loader(fullname, _LegacyLoader())
|
|
return None
|
|
|
|
|
|
if not any(isinstance(f, _LegacyFinder) for f in sys.meta_path):
|
|
sys.meta_path.append(_LegacyFinder())
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _run_settings_in_tmp(tmp_path, monkeypatch):
|
|
try:
|
|
import claude_proxy
|
|
except Exception: # a test that stubs the sidecar's imports
|
|
return
|
|
monkeypatch.setattr(claude_proxy, "RUN_SETTINGS_DIR", tmp_path / "run-settings")
|
|
monkeypatch.setattr(claude_proxy, "_swept_at", 0.0)
|