test(api): keep test_endpoints hermetic after /dm/narrate wiring

/dm/narrate now makes a real Ollama call (Task 7). The role-endpoint
loop tests in test_endpoints.py had no mock, so every default pytest
run was silently hitting a live Ollama instance on localhost:11434 —
breaking the hermetic-suite constraint. Add an autouse fixture that
stubs narrate.ollama_client.chat and narrate.call_log.record so all
five endpoints stay hermetic; assertions (200 on valid, 422 on
invalid) are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-10 08:31:42 -05:00
parent 5a35802075
commit 45d5f0360b

View File

@@ -1,8 +1,10 @@
import json
from pathlib import Path
import pytest
from fastapi.testclient import TestClient
import app.narrate as narrate
from app.main import app
client = TestClient(app)
@@ -14,6 +16,15 @@ ROLE_ENDPOINTS = [
]
@pytest.fixture(autouse=True)
def _stub_narrate_model_call(monkeypatch):
# /dm/narrate is wired to a real Ollama call (Task 7). These tests exercise
# canon-log validation across ALL role endpoints, not model behavior, so
# stub the model boundary — keeps the default suite hermetic (no network).
monkeypatch.setattr(narrate.ollama_client, "chat", lambda *a, **k: "stubbed prose")
monkeypatch.setattr(narrate.call_log, "record", lambda **kw: None)
def test_health_ok():
assert client.get("/health").json() == {"status": "ok"}