mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
.stamphog/ was a config directory at the repo root — policy.yml, review-guidance.md — read by the PR review agent. It is .stamp/ now, and the 34 files that name it follow: the workflows, tools/pr-approval-agent, tach.toml, the sandbox Dockerfile, bin/debrand. One behaviour change worth naming rather than burying: the agent finds its own previous PR comment by an HTML marker, `<!-- stamphog:v1 ... -->`, and that marker is now `<!-- stamp:v1 ... -->`. Open PRs will get one new comment instead of an edit, once, and then match again. insights/test/setup_receivers_baseline.txt records registered signal receivers by module path, so it names products.review.backend now. stamphog: zero occurrences anywhere in the tree. review_hog: only inside migration files, whose names are their identity in django_migrations. Co-authored-by: Hanzo Dev <[email protected]>
48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
"""Routing-pin tests for the ai-gateway switch in reviewer.py."""
|
|
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock
|
|
|
|
# reviewer.py's claude_agent_sdk dep is installed by `uv run`, not the test venv.
|
|
sys.modules.setdefault("claude_agent_sdk", MagicMock())
|
|
sys.modules.setdefault("claude_agent_sdk.types", MagicMock())
|
|
|
|
import reviewer # noqa: E402
|
|
from reviewer import _apply_gateway_route # noqa: E402
|
|
|
|
_ANTHROPIC_ENV_KEYS = ("ANTHROPIC_BASE_URL", "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY", "ANTHROPIC_CUSTOM_HEADERS")
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _restore_anthropic_env():
|
|
saved = {k: os.environ.get(k) for k in _ANTHROPIC_ENV_KEYS}
|
|
yield
|
|
for k, v in saved.items():
|
|
if v is None:
|
|
os.environ.pop(k, None)
|
|
else:
|
|
os.environ[k] = v
|
|
|
|
|
|
def test_no_gateway_returns_none_and_leaves_env_untouched():
|
|
before = {k: os.environ.get(k) for k in _ANTHROPIC_ENV_KEYS}
|
|
assert _apply_gateway_route(None, {"stamp_pr_number": 1}) is None
|
|
assert {k: os.environ.get(k) for k in _ANTHROPIC_ENV_KEYS} == before
|
|
|
|
|
|
def test_gateway_mode_uses_plain_query_and_applies_env():
|
|
active = _apply_gateway_route(("https://gateway.us.hanzo.ai", "sk-secret"), {"stamp_pr_number": 7})
|
|
# Plain query, not the traced wrapper (else the gateway's $ai_generation double-counts).
|
|
assert active is reviewer.query
|
|
assert os.environ["ANTHROPIC_BASE_URL"] == "https://gateway.us.hanzo.ai"
|
|
assert os.environ["ANTHROPIC_AUTH_TOKEN"] == "sk-secret"
|
|
assert os.environ["ANTHROPIC_API_KEY"] == "sk-secret"
|
|
headers = os.environ["ANTHROPIC_CUSTOM_HEADERS"]
|
|
# Single X-Insights-Properties JSON blob; the slugless gateway ignores per-property headers.
|
|
assert '"ai_product":"aio_stamp"' in headers
|
|
assert '"stamp_pr_number":7' in headers
|
|
assert "x-insights-property-" not in headers
|