forked from Rockachopa/Timmy-time-dashboard
Move 97 test files from flat tests/ into 13 subdirectories: tests/dashboard/ (8 files — routes, mobile, mission control) tests/swarm/ (17 files — coordinator, docker, routing, tasks) tests/timmy/ (12 files — agent, backends, CLI, tools) tests/self_coding/ (14 files — git safety, indexer, self-modify) tests/lightning/ (3 files — L402, LND, interface) tests/creative/ (8 files — assembler, director, image/music/video) tests/integrations/ (10 files — chat bridge, telegram, voice, websocket) tests/mcp/ (4 files — bootstrap, discovery, executor) tests/spark/ (3 files — engine, tools, events) tests/hands/ (3 files — registry, oracle, phase5) tests/scripture/ (1 file) tests/infrastructure/ (3 files — router cascade, API) tests/security/ (3 files — XSS, regression) Fix Path(__file__) reference in test_mobile_scenarios.py for new depth. Add __init__.py to all test subdirectories. Tests: 1503 passed, 9 failed (pre-existing), 53 errors (pre-existing) https://claude.ai/code/session_019oMFNvD8uSGSSmBMGkBfQN
111 lines
3.9 KiB
Python
111 lines
3.9 KiB
Python
"""Tests for Spark engine tool-level and creative pipeline event capture.
|
|
|
|
Covers the new on_tool_executed() and on_creative_step() methods added
|
|
in Phase 6.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from spark.engine import SparkEngine
|
|
from spark.memory import get_events, count_events
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def tmp_spark_db(tmp_path, monkeypatch):
|
|
db_path = tmp_path / "spark.db"
|
|
monkeypatch.setattr("spark.memory.DB_PATH", db_path)
|
|
monkeypatch.setattr("spark.eidos.DB_PATH", db_path)
|
|
yield db_path
|
|
|
|
|
|
class TestOnToolExecuted:
|
|
def test_captures_tool_event(self):
|
|
engine = SparkEngine(enabled=True)
|
|
eid = engine.on_tool_executed("agent-a", "git_commit", task_id="t1")
|
|
assert eid is not None
|
|
events = get_events(event_type="tool_executed")
|
|
assert len(events) == 1
|
|
assert "git_commit" in events[0].description
|
|
|
|
def test_captures_tool_failure(self):
|
|
engine = SparkEngine(enabled=True)
|
|
eid = engine.on_tool_executed("agent-a", "generate_image", success=False)
|
|
assert eid is not None
|
|
events = get_events(event_type="tool_executed")
|
|
assert len(events) == 1
|
|
assert "FAIL" in events[0].description
|
|
|
|
def test_captures_duration(self):
|
|
engine = SparkEngine(enabled=True)
|
|
engine.on_tool_executed("agent-a", "generate_song", duration_ms=5000)
|
|
events = get_events(event_type="tool_executed")
|
|
assert len(events) == 1
|
|
|
|
def test_disabled_returns_none(self):
|
|
engine = SparkEngine(enabled=False)
|
|
result = engine.on_tool_executed("agent-a", "git_push")
|
|
assert result is None
|
|
|
|
def test_multiple_tool_events(self):
|
|
engine = SparkEngine(enabled=True)
|
|
engine.on_tool_executed("agent-a", "git_add")
|
|
engine.on_tool_executed("agent-a", "git_commit")
|
|
engine.on_tool_executed("agent-a", "git_push")
|
|
assert count_events("tool_executed") == 3
|
|
|
|
|
|
class TestOnCreativeStep:
|
|
def test_captures_creative_step(self):
|
|
engine = SparkEngine(enabled=True)
|
|
eid = engine.on_creative_step(
|
|
project_id="proj-1",
|
|
step_name="storyboard",
|
|
agent_id="pixel-001",
|
|
output_path="/data/images/frame.png",
|
|
)
|
|
assert eid is not None
|
|
events = get_events(event_type="creative_step")
|
|
assert len(events) == 1
|
|
assert "storyboard" in events[0].description
|
|
|
|
def test_captures_failed_step(self):
|
|
engine = SparkEngine(enabled=True)
|
|
engine.on_creative_step(
|
|
project_id="proj-1",
|
|
step_name="music",
|
|
agent_id="lyra-001",
|
|
success=False,
|
|
)
|
|
events = get_events(event_type="creative_step")
|
|
assert len(events) == 1
|
|
assert "FAIL" in events[0].description
|
|
|
|
def test_disabled_returns_none(self):
|
|
engine = SparkEngine(enabled=False)
|
|
result = engine.on_creative_step("p1", "storyboard", "pixel-001")
|
|
assert result is None
|
|
|
|
def test_full_pipeline_events(self):
|
|
engine = SparkEngine(enabled=True)
|
|
steps = ["storyboard", "music", "video", "assembly"]
|
|
agents = ["pixel-001", "lyra-001", "reel-001", "reel-001"]
|
|
for step, agent in zip(steps, agents):
|
|
engine.on_creative_step("proj-1", step, agent)
|
|
assert count_events("creative_step") == 4
|
|
|
|
|
|
class TestSparkStatusIncludesNewTypes:
|
|
def test_status_includes_tool_executed(self):
|
|
engine = SparkEngine(enabled=True)
|
|
engine.on_tool_executed("a", "git_commit")
|
|
status = engine.status()
|
|
assert "tool_executed" in status["event_types"]
|
|
assert status["event_types"]["tool_executed"] == 1
|
|
|
|
def test_status_includes_creative_step(self):
|
|
engine = SparkEngine(enabled=True)
|
|
engine.on_creative_step("p1", "storyboard", "pixel-001")
|
|
status = engine.status()
|
|
assert "creative_step" in status["event_types"]
|
|
assert status["event_types"]["creative_step"] == 1
|