"""Unit tests for DirectorNode v1 — style directives + Opus planning.""" import json from harness import HudCapture, make_history, NodeTestRunner from agent.nodes.director_v1 import DirectorNode async def test_detects_casual_mode(): """Director should detect casual chat mode.""" hud = HudCapture() node = DirectorNode(send_hud=hud) history = make_history([ ("user", "hey, just hanging out"), ("assistant", "Hey! What's up?"), ("user", "not much, just chilling"), ("assistant", "Nice, enjoy the evening!"), ]) await node.update(history, {"user_mood": "happy", "topic": "casual chat"}) assert node.directive["mode"] == "casual", f"mode={node.directive['mode']}" async def test_detects_frustrated_style(): """Director should adjust style when user is frustrated.""" hud = HudCapture() node = DirectorNode(send_hud=hud) history = make_history([ ("user", "this is completely broken, nothing works"), ("assistant", "Let me help fix that."), ]) await node.update(history, {"user_mood": "frustrated", "topic": "debugging"}) style = node.directive.get("style", "").lower() assert any(k in style for k in ["simplif", "patient", "calm", "help", "step"]), \ f"style doesn't address frustration: {style}" async def test_produces_plan_for_complex_request(): """Director.plan() should produce an investigation plan with Opus.""" hud = HudCapture() node = DirectorNode(send_hud=hud) history = make_history([ ("user", "investigate which customers have the most devices"), ]) plan = await node.plan(history, {"topic": "database"}, "investigate which customers have the most devices") assert plan, "empty plan" assert "query_db" in plan.lower() or "select" in plan.lower() or "step" in plan.lower(), \ f"plan doesn't mention DB tools: {plan[:200]}" assert node.current_plan, "plan not stored in current_plan" async def test_directive_has_required_fields(): """Directive should have mode, style, proactive.""" hud = HudCapture() node = DirectorNode(send_hud=hud) history = make_history([("user", "hello"), ("assistant", "hi")]) await node.update(history, {"user_mood": "neutral"}) assert "mode" in node.directive assert "style" in node.directive assert "proactive" in node.directive async def test_context_line_includes_plan(): """get_context_line() should include the plan when set.""" hud = HudCapture() node = DirectorNode(send_hud=hud) node.current_plan = "Step 1: query kunden table" line = node.get_context_line() assert "Step 1" in line, f"plan not in context line: {line}" assert "DIRECTOR PLAN" in line, f"missing plan header: {line}" if __name__ == "__main__": runner = NodeTestRunner() print("\n=== DirectorNode v1 ===") runner.test("detects casual mode", test_detects_casual_mode()) runner.test("detects frustrated style", test_detects_frustrated_style()) runner.test("produces plan for complex request", test_produces_plan_for_complex_request()) runner.test("directive has required fields", test_directive_has_required_fields()) runner.test("context line includes plan", test_context_line_includes_plan()) p, f = runner.summary() print(f"\n {p} passed, {f} failed")