def test_thread_preserves_original_tool_name(self, mock_get_thread, mock_redis):
        """Test that the thread's original tool_name is preserved even when other tools contribute"""
        mock_client = Mock()
        mock_redis.return_value = mock_client

        # Create existing thread from analysis tool
        existing_context = ThreadContext(
            thread_id="test-thread-id",
            created_at="2023-01-01T00:00:00Z",
            last_updated_at="2023-01-01T00:01:00Z",
            tool_name="test_analysis",  # Original tool
            turns=[
                ConversationTurn(
                    role="assistant",
                    content="Initial analysis",
                    timestamp="2023-01-01T00:01:00Z",
                    tool_name="test_analysis",
                )
            ],
            initial_context={"code": "test"},
        )

        # Mock get_thread to return the existing context
        mock_get_thread.return_value = existing_context

        # Add turn from review tool
        from utils.conversation_memory import add_turn

        success = add_turn(
            "test-thread-id",
            "assistant",
            "Review completed",
            tool_name="test_review",  # Different tool
        )

        # Verify the add_turn succeeded (basic cross-tool functionality test)
        assert success

        # Verify thread's original tool_name is preserved
        setex_calls = mock_client.setex.call_args_list
        updated_thread_data = setex_calls[-1][0][2]
        updated_context = json.loads(updated_thread_data)

        assert updated_context["tool_name"] == "test_analysis"  # Original preserved
        assert len(updated_context["turns"]) == 2
        assert updated_context["turns"][0]["tool_name"] == "test_analysis"
        assert updated_context["turns"][1]["tool_name"] == "test_review"
Test that the thread's original tool_name is preserved even when other tools contribute
tests/test_cross_tool_continuation.py