- engine/llm.py: Ollama /api/chat client with OpenAI-style tool schema
- engine/reasoning.py: LLM path with 4-tier validation:
1. tool exists in registry
2. tool passes location-gating
3. args parse cleanly
4. otherwise fall back to rule-based engine
- env vars: EMERGENCE_LLM_{URL,MODEL,TIMEOUT,ENABLED}
- Default model: llama3.2:3b (best speed/quality tradeoff for tool use)
- 11 new mock tests in tests/test_llm.py (no network)
- smoke_test_llm.py: live smoke against real Ollama
- README: 'LLM Integration' section with model table + setup
Live-verified: 4/4 decisions via llama3.2:3b in 1-3s, character-consistent
('facilitate honest debate', 'work together', 'urgency and collaboration').
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
"""Shared pytest fixtures: temporary DB, FastAPI client, bootstrapped engine."""
|
|
import os
|
|
import sys
|
|
import shutil
|
|
import tempfile
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
# Make the project root importable
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
# Disable the background engine thread for all tests; tests trigger rounds manually.
|
|
os.environ["EMERGENCE_TEST_MODE"] = "1"
|
|
# Force the rule-based reasoning path; the LLM path is exercised by the
|
|
# dedicated test_llm.py suite with a mocked HTTP client.
|
|
os.environ["EMERGENCE_LLM_ENABLED"] = "0"
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def tmp_db(monkeypatch):
|
|
"""Redirect the DB to a fresh temp file for each test."""
|
|
tmpdir = tempfile.mkdtemp(prefix="emerge-test-")
|
|
db_path = Path(tmpdir) / "test.db"
|
|
# Import here so we can patch the module-level constant
|
|
from engine import db
|
|
monkeypatch.setattr(db, "DB_PATH", db_path)
|
|
# Re-seed
|
|
db.init_db()
|
|
from engine import world, agents as agents_mod, tools
|
|
# Force re-bootstrap by clearing the seeded flag
|
|
db.set_world_state("landmarks_seeded", False)
|
|
db.set_world_state("agents_seeded", False)
|
|
world.bootstrap()
|
|
agents_mod.bootstrap()
|
|
tools.bootstrap()
|
|
yield db_path
|
|
shutil.rmtree(tmpdir, ignore_errors=True)
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def client(tmp_db):
|
|
"""FastAPI TestClient bound to the temp DB."""
|
|
# Ensure the app's startup hooks are run
|
|
from server import app
|
|
from fastapi.testclient import TestClient
|
|
with TestClient(app) as c:
|
|
yield c
|