@@ -579,3 +579,79 @@ def test_callback_failure_does_not_raise(monkeypatch):
579579
580580 # Should not raise
581581 ws .__exit__ (None , None , None )
582+
583+
584+ # --- conversation_id registration tests ---
585+
586+
587+ def test_register_conversation_sets_conversation_id ():
588+ """register_conversation sets the _conversation_id attribute."""
589+ ws = _make_local_workspace ()
590+
591+ ws .register_conversation ("conv-123" )
592+
593+ assert ws ._conversation_id == "conv-123"
594+ assert ws .conversation_id == "conv-123"
595+
596+
597+ def test_conversation_id_property_returns_none_initially ():
598+ """conversation_id property returns None when no conversation registered."""
599+ ws = _make_local_workspace ()
600+
601+ assert ws .conversation_id is None
602+
603+
604+ def test_callback_includes_conversation_id_when_registered (monkeypatch ):
605+ """Callback payload includes conversation_id when registered."""
606+ monkeypatch .setenv ("AUTOMATION_CALLBACK_URL" , "https://svc.test/complete" )
607+ monkeypatch .setenv ("AUTOMATION_RUN_ID" , "run-42" )
608+ ws = _make_local_workspace ()
609+
610+ # Register a conversation
611+ ws .register_conversation ("conv-xyz" )
612+
613+ mock_resp = MagicMock ()
614+ mock_resp .status_code = 200
615+
616+ with patch ("httpx.Client" ) as MockClient :
617+ mock_client = MagicMock ()
618+ mock_client .post .return_value = mock_resp
619+ mock_client .__enter__ = MagicMock (return_value = mock_client )
620+ mock_client .__exit__ = MagicMock (return_value = False )
621+ MockClient .return_value = mock_client
622+
623+ ws .__exit__ (None , None , None )
624+
625+ # Check the POST payload includes conversation_id
626+ mock_client .post .assert_called_once ()
627+ payload = mock_client .post .call_args .kwargs ["json" ]
628+ assert payload ["status" ] == "COMPLETED"
629+ assert payload ["run_id" ] == "run-42"
630+ assert payload ["conversation_id" ] == "conv-xyz"
631+
632+
633+ def test_callback_omits_conversation_id_when_not_registered (monkeypatch ):
634+ """Callback payload omits conversation_id when not registered."""
635+ monkeypatch .setenv ("AUTOMATION_CALLBACK_URL" , "https://svc.test/complete" )
636+ monkeypatch .setenv ("AUTOMATION_RUN_ID" , "run-42" )
637+ ws = _make_local_workspace ()
638+
639+ # Do not register a conversation
640+
641+ mock_resp = MagicMock ()
642+ mock_resp .status_code = 200
643+
644+ with patch ("httpx.Client" ) as MockClient :
645+ mock_client = MagicMock ()
646+ mock_client .post .return_value = mock_resp
647+ mock_client .__enter__ = MagicMock (return_value = mock_client )
648+ mock_client .__exit__ = MagicMock (return_value = False )
649+ MockClient .return_value = mock_client
650+
651+ ws .__exit__ (None , None , None )
652+
653+ # Check the POST payload does NOT include conversation_id
654+ mock_client .post .assert_called_once ()
655+ payload = mock_client .post .call_args .kwargs ["json" ]
656+ assert payload ["status" ] == "COMPLETED"
657+ assert "conversation_id" not in payload
0 commit comments