Files
Shane a1d59580f7 fix: ChatContext is not a sequence — use .items for len/list; add test suite
Bug fix:
- GemmaLLM.chat(): len(chat_ctx) → len(chat_ctx.items)
- GemmaLLM._compact_context(): list(chat_ctx) → list(chat_ctx.items)
  ChatContext in livekit-agents 1.7 is not iterable or sized directly;
  it exposes an .items list. The TypeError was silently killing all LLM
  responses (agent heard user but never spoke back).

Test suite (tests/):
- test_web_ui.py: static assets, token endpoint, LiveKit WS proxy
- test_llm_api.py: completion, tool calling, thinking-disabled latency, streaming
- test_mcp_tools.py: weather (Fahrenheit), time, memory, skills — all via
  docker exec + in-container MCP client
- test_agent_integration.py: process alive, worker registered, supervisord,
  container health, LiveKit API
- test_compaction.py: size-triggered compaction, system prompt preservation,
  short-context no-op
- conftest.py: shared fixtures (HTTPS client, token, LLM, docker exec helpers)
- Run with: .venv-tests/bin/python -m pytest tests/ -v
2026-08-22 17:09:29 -04:00

75 lines
2.2 KiB
Python

"""Tests for the web UI served by nginx (HTTPS :8090) and the token endpoint."""
import json
import httpx
def test_index_serves(client):
resp = client.get("/")
assert resp.status_code == 200
body = resp.text
assert "Hope" in body
assert "livekit-client.umd.js" in body
assert "app.js" in body
def test_app_js_serves(client):
resp = client.get("/app.js")
assert resp.status_code == 200
assert "LiveKitClient" in resp.text or "Room" in resp.text
def test_style_css_serves(client):
resp = client.get("/style.css")
assert resp.status_code == 200
body = resp.text
assert "{" in body and "}" in body
assert "color" in body or "background" in body
def test_manifest_serves(client):
resp = client.get("/manifest.json")
assert resp.status_code == 200
manifest = json.loads(resp.text)
assert "name" in manifest
def test_favicon_serves(client):
resp = client.get("/favicon.svg")
assert resp.status_code == 200
assert "svg" in resp.headers.get("content-type", "")
assert "<svg" in resp.text
def test_livekit_client_bundle_serves(client):
resp = client.get("/livekit-client.umd.js")
assert resp.status_code == 200
assert len(resp.text) > 100_000 # vendored UMD bundle is large
def test_token_endpoint_direct():
"""Token server on 127.0.0.1:8091 (host network mode)."""
resp = httpx.post("http://127.0.0.1:8091/token", json={}, timeout=10)
assert resp.status_code == 200
data = resp.json()
assert "token" in data and data["token"].count(".") == 2 # JWT shape
def test_token_endpoint_via_nginx(client):
"""nginx proxies /token to the token server."""
resp = client.post("/token", json={})
assert resp.status_code == 200
data = resp.json()
assert "token" in data and data["token"].count(".") == 2
def test_livekit_ws_proxy(client):
"""The /livekit/ path is proxied to the LiveKit server (HTTP :7880)."""
resp = client.get("/livekit/")
# LiveKit's HTTP API answers on /; a 200 or an API error JSON both prove
# the proxy reaches the LiveKit server rather than nginx serving statics.
assert resp.status_code in (200, 404, 405)
if resp.headers.get("content-type", "").startswith("application/json"):
json.loads(resp.text)