cq-test / test_phase3.py
NANI-Nithin's picture
Phase 3: add live session intelligence
3ee7cb0
Raw
History Blame Contribute Delete
3.12 kB
"""End-to-end test for Phase 3: Session Intelligence."""
import uuid
from app.services.retrieval import load_games_dataset, normalize_game_record, retrieve_examples
from app.services.generator import generate_game
from app.services.validator import validate_game, repair_game
from app.services.tracing import log_event, load_events
from app.services.journal import create_journal_entry, save_journal_entry, summarize_journal, load_journal_entries
from app.services.scoring import compute_scores
from app.services.story import build_story_packet, generate_story
# 1. Load dataset
raw = load_games_dataset("app/data/games_dataset.json")
records = [normalize_game_record(r) for r in raw]
print(f"βœ“ Loaded {len(records)} records")
# 2. Config
config = {
"game_type": "scavenger_hunt",
"city": "Paris",
"area": "Le Marais",
"location_type": "mixed",
"duration_minutes": 60,
"num_players": 4,
"difficulty": "medium",
"age_group": "adults",
"energy_level": "medium",
"photo_enabled": True,
}
# 3. Retrieve + Generate
retrieved = retrieve_examples(config, records, k=3)
game = generate_game(config, retrieved)
print(f"βœ“ Generated: {game['title']} with {len(game['tasks'])} tasks")
# 4. Validate
is_valid, failures = validate_game(game, config)
status = "PASS" if is_valid else f"FAIL ({len(failures)} issues)"
print(f"βœ“ Validation: {status}")
# 5. Session
session_id = f"test-{uuid.uuid4().hex[:8]}"
# 6. Log events
for t in game["tasks"]:
log_event(session_id, "task_revealed", {"task_id": t["task_id"], "title": t["title"]})
log_event(session_id, "task_completed", {"task_id": "t1", "summary": "Completed first task"}, team_id="team-a")
log_event(session_id, "task_completed", {"task_id": "t2", "summary": "Completed second task"}, team_id="team-a")
log_event(session_id, "hint_used", {"task_id": "t2", "summary": "Used hint"}, team_id="team-a")
log_event(session_id, "task_skipped", {"task_id": "t3", "summary": "Skipped"}, team_id="team-a")
events = load_events(session_id)
print(f"βœ“ Logged {len(events)} events")
# 7. Journal
entry = create_journal_entry(
transcript="We found the mural near the canal, it was incredible! The whole team cheered.",
session_id=session_id,
team_id="team-a",
task_id="t1",
location_note="Canal area",
)
summary = summarize_journal(entry["transcript"], task_id="t1")
entry.update(summary)
save_journal_entry(entry)
journals = load_journal_entries(session_id)
print(f"βœ“ Journal mood={entry['mood']}, story_value={entry['story_value']}")
# 8. Score
scores = compute_scores(events, game)
print(f"βœ“ Winner: {scores['winner']}")
for s in scores["team_scores"]:
print(f" - {s['team_id']}: {s['points']} pts ({s['completed_tasks']}/{s['total_tasks']} tasks)")
# 9. Story
packet = build_story_packet(game, events, scores, journals)
story = generate_story(packet, session_id=session_id)
print(f"βœ“ Story recap: {len(story['short_recap'])} chars short, {len(story['long_summary'])} chars long")
print()
print("=== SHORT RECAP ===")
print(story["short_recap"])
print()
print("=== PIPELINE COMPLETE βœ“ ===")