generated from coulomb/repo-seed
Add activity-core LLM endpoint support
This commit is contained in:
92
tests/test_activity_core_smoke.py
Normal file
92
tests/test_activity_core_smoke.py
Normal file
@@ -0,0 +1,92 @@
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from llm_connect.adapter import MockLLMAdapter
|
||||
from llm_connect.models import RunConfig
|
||||
from llm_connect.profiles import CUSTODIAN_TRIAGE_BALANCED, ProfiledLLMAdapter, RuntimeProfile
|
||||
from llm_connect.server import LLMServer
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SCRIPT = ROOT / "scripts" / "smoke_activity_core_endpoint.py"
|
||||
FIXTURE_DIR = ROOT / "fixtures" / "activity_core"
|
||||
|
||||
|
||||
def _load_smoke_module():
|
||||
spec = importlib.util.spec_from_file_location("smoke_activity_core_endpoint", SCRIPT)
|
||||
assert spec is not None
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_daily_triage_fixture_content_matches_schema():
|
||||
smoke = _load_smoke_module()
|
||||
schema = json.loads((FIXTURE_DIR / "daily-triage-report.schema.json").read_text())
|
||||
content = json.loads((FIXTURE_DIR / "daily-triage-valid-content.json").read_text())
|
||||
|
||||
assert smoke.validate_json_schema(content, schema) == []
|
||||
|
||||
|
||||
def test_daily_triage_execute_request_embeds_schema_and_profile_config():
|
||||
request = json.loads((FIXTURE_DIR / "daily-triage-execute-request.json").read_text())
|
||||
schema = json.loads((FIXTURE_DIR / "daily-triage-report.schema.json").read_text())
|
||||
config = request["config"]
|
||||
|
||||
assert request["prompt"]
|
||||
assert config["model_name"] == "custodian-triage-balanced"
|
||||
assert config["temperature"] == 0.2
|
||||
assert config["max_tokens"] == 1800
|
||||
assert config["max_depth"] == 2
|
||||
assert config["timeout_seconds"] == 300
|
||||
assert config["model_params"]["reasoning_effort"] == "medium"
|
||||
assert config["model_params"]["json_schema"] == schema
|
||||
|
||||
|
||||
def test_schema_validator_reports_missing_required_field():
|
||||
smoke = _load_smoke_module()
|
||||
schema = json.loads((FIXTURE_DIR / "daily-triage-report.schema.json").read_text())
|
||||
invalid = {"summary": "missing recommendations"}
|
||||
|
||||
errors = smoke.validate_json_schema(invalid, schema)
|
||||
|
||||
assert "$: missing required property 'recommendations'" in errors
|
||||
|
||||
|
||||
def test_run_smoke_against_profiled_mock_server():
|
||||
smoke = _load_smoke_module()
|
||||
valid_content = (FIXTURE_DIR / "daily-triage-valid-content.json").read_text()
|
||||
|
||||
def factory(provider: str, model: str) -> MockLLMAdapter:
|
||||
assert provider == "mock"
|
||||
assert model == "triage-model"
|
||||
return MockLLMAdapter(mock_response=valid_content)
|
||||
|
||||
adapter = ProfiledLLMAdapter(
|
||||
MockLLMAdapter(mock_response=valid_content),
|
||||
{
|
||||
CUSTODIAN_TRIAGE_BALANCED: RuntimeProfile(
|
||||
name=CUSTODIAN_TRIAGE_BALANCED,
|
||||
provider="mock",
|
||||
model="triage-model",
|
||||
config=RunConfig(model_name="triage-model"),
|
||||
)
|
||||
},
|
||||
adapter_factory=factory,
|
||||
)
|
||||
server = LLMServer(adapter=adapter, port=0)
|
||||
server.start()
|
||||
try:
|
||||
result = smoke.run_smoke(
|
||||
base_url=f"http://127.0.0.1:{server.port}",
|
||||
request_path=FIXTURE_DIR / "daily-triage-execute-request.json",
|
||||
schema_path=FIXTURE_DIR / "daily-triage-report.schema.json",
|
||||
timeout=3,
|
||||
)
|
||||
finally:
|
||||
server.stop()
|
||||
|
||||
assert result["health"] == "ok"
|
||||
assert result["recommendations"] == 1
|
||||
Reference in New Issue
Block a user