"""Unit tests for the scenario runtime + flows spec (TASK-03-03, TASK-03-07).""" from __future__ import annotations import pytest from server.scenarios.runtime import ( ScenarioRuntime, build_runtime, build_runtime_from_id, ) from server.scenarios.loader import load def test_runtime_uses_scenario_system_prompt(): s = load("customer_service_refund_ca_v01") rt = build_runtime(s) assert "Jordan" in rt.system_prompt assert "cracked" in rt.opening_line def test_runtime_set_branch_escalate(): rt = build_runtime_from_id("customer_service_refund_ca_v01") b = rt.set_branch("escalate") assert b.outcome == "failure" assert b.failure_mode == "escalates_unresolved" assert rt.outcome == "failure" assert rt.branch_id == "escalate" def test_runtime_set_branch_accept(): rt = build_runtime_from_id("customer_service_refund_ca_v01") b = rt.set_branch("accept_resolution") assert b.outcome == "success" assert rt.outcome == "success" def test_runtime_set_branch_unknown_raises(): rt = build_runtime_from_id("customer_service_refund_ca_v01") with pytest.raises(ValueError, match="Unknown branch id"): rt.set_branch("nonexistent_branch") def test_runtime_debrief_focus_per_branch(): rt = build_runtime_from_id("customer_service_refund_ca_v01") # No branch set → default focus. assert "General" in rt.debrief_focus() rt.set_branch("escalate") assert "escalated" in rt.debrief_focus().lower() rt.set_branch("accept_resolution") assert "did well" in rt.debrief_focus().lower() def test_runtime_as_flow_spec_has_branches(): rt = build_runtime_from_id("customer_service_refund_ca_v01") spec = rt.as_flow_spec() assert spec["initial_state"] == "conversation" assert "system_prompt" in spec["states"]["conversation"] assert len(spec["states"]["conversation"]["branches"]) == 2 # v0.1: no in-flight transitions (G-002 — post-hoc classification). assert spec["transitions"] == [] def test_runtime_default_debrief_model(): """The scenario's debrief config uses deepseek-v4-flash:cloud no_think (D-020).""" rt = build_runtime_from_id("customer_service_refund_ca_v01") assert rt.scenario.debrief.model == "deepseek-v4-flash:cloud" assert rt.scenario.debrief.mode == "no_think"