fix(legacy-meter): guard MCP alias metering off in tests

Alias tests monkeypatch _get/_post but _meter_legacy_mcp uses _client()
directly, so every pytest run recorded real usage and reset zero-window
retirement streaks. STATEHUB_MCP_LEGACY_METER=off skips metering; set in
tests/conftest.py. Verified meter counts flat across the alias suite.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tegwick 2026-07-10 21:47:46 +02:00
parent a18fa13682
commit 54577cd847
3 changed files with 16 additions and 0 deletions

View file

@ -226,6 +226,8 @@ def _meter_legacy_mcp(*, tool: str | None = None, resource: str | None = None) -
(`mcp:<tool_name>` / resource URI). Failures never surface to the caller
the meter gates retirement, it must not break the aliased call itself.
"""
if os.environ.get("STATEHUB_MCP_LEGACY_METER", "on") == "off":
return
if tool:
key = f"mcp:{tool}"
replacement = _LEGACY_MCP_TOOL_REPLACEMENTS[tool]

View file

@ -23,6 +23,10 @@ from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_asyn
# Make api/ importable when running pytest from state-hub/
sys.path.insert(0, str(Path(__file__).parent.parent))
# Tests exercising legacy MCP aliases must not record real usage on the live
# legacy meter — that would reset zero-window retirement streaks every run.
os.environ.setdefault("STATEHUB_MCP_LEGACY_METER", "off")
_ASYNC_URL = os.getenv(
"TEST_DATABASE_URL",
"postgresql+asyncpg://custodian:changeme@127.0.0.1:5432/custodian_test",

View file

@ -119,6 +119,16 @@ zero-window streaks accrue from 2026-07-10. Note: `mcp:list_workstreams` shows
1 verification call in the 2026-07-10 window — streak counts from the next
window. Removal remains gated on 7 consecutive zero windows.
Recheck 2026-07-10: pytest was recording real alias usage on the live meter
(tests monkeypatch `_get`/`_post` but the meter helper uses `_client()`),
which would reset streaks every run. Guarded with
`STATEHUB_MCP_LEGACY_METER=off`, set in `tests/conftest.py`; verified
before/after counts flat across the alias test suite. Stray counts from
verification + first test run (create=2, list=2, resource=1) clear at next
window rollover. **Deploy note:** the long-running dev-hub MCP process
(:8001) predates this change and must be restarted (`make mcp-http`) before
its zero windows are trustworthy — unmetered live usage would look like zero.
## Task: Internal dual-key and param alias cleanup
```task