import json import pytest from fastapi.testclient import TestClient from app import main from app.model_runtime import Completion VALID_REQUEST = { "version": "v1", "knowledge_submission": "I completed the task.", "wisdom": { "content": "I learned something before.", "chapterTitle": "Past learning", "BookTypeName": "Testimony", "BookType": "Personal Record", }, "village_goal": "Learn the skill", "previous_activity_title": "Practice the skill", } VALID_OUTPUT = { "progression": { "knowledge_state": "COMPLETED", "demonstrated_state": ["Completed the task"], "next_gap": "Apply it in a new setting", "activity_plan": { "action": "Apply", "target": "A new setting", "avoid_repeating": ["Completing the same task"], }, } } class FakeRuntime: """Stands in for ModelRuntime so tests never load the GGUF.""" def __init__(self) -> None: self.is_ready = True self.output = json.dumps(VALID_OUTPUT) self.prompts: list[str] = [] async def start(self) -> None: pass async def stop(self) -> None: pass def ready(self) -> bool: return self.is_ready async def complete(self, prompt: str) -> Completion: self.prompts.append(prompt) return Completion( text=self.output, input_tokens=len(prompt.split()), output_tokens=len(self.output.split()), ) @pytest.fixture def fake_runtime(monkeypatch): fake = FakeRuntime() monkeypatch.setattr(main, "runtime", fake) return fake @pytest.fixture def client(fake_runtime): with TestClient(main.app) as test_client: yield test_client @pytest.fixture def valid_request(): return json.loads(json.dumps(VALID_REQUEST))