3434
3535@pytest .fixture
3636def dummy_request () -> Request :
37- """Mock request object for testing."""
37+ """Mock request object for testing.
38+
39+ Create a mock FastAPI Request configured for tests with full authorization.
40+
41+ The returned Request has state.authorized_actions set to a set containing
42+ every member of Action.
43+ """
3844 request = Request (
3945 scope = {
4046 "type" : "http" ,
@@ -56,7 +62,35 @@ def create_mock_conversation(
5662 last_used_provider : str ,
5763 topic_summary : Optional [str ] = None ,
5864) -> MockType :
59- """Helper function to create a mock conversation object with all required attributes."""
65+ """Helper function to create a mock conversation object with all required attributes.
66+
67+ Create a mock conversation object with the attributes used by the
68+ conversations list and detail tests.
69+
70+ The returned mock has the following attributes:
71+ - id: the conversation identifier (string)
72+ - created_at.isoformat(): returns the provided created_at string
73+ - last_message_at.isoformat(): returns the provided last_message_at string
74+ - message_count: number of messages in the conversation
75+ - last_used_model: model identifier last used in the conversation
76+ - last_used_provider: provider identifier last used in the conversation
77+ - topic_summary: optional topic summary (may be None or empty string)
78+
79+ Parameters:
80+ mocker (MockerFixture): pytest mocker fixture used to build the mock object.
81+ conversation_id (str): Conversation identifier to assign to the mock.
82+ created_at (str): ISO-formatted created-at timestamp to be returned by
83+ created_at.isoformat().
84+ last_message_at (str): ISO-formatted last-message timestamp to be
85+ returned by last_message_at.isoformat().
86+ message_count (int): Message count to assign to the mock.
87+ last_used_model (str): Last used model string to assign to the mock.
88+ last_used_provider (str): Last used provider string to assign to the mock.
89+ topic_summary (Optional[str]): Optional topic summary to assign to the mock.
90+
91+ Returns:
92+ mock_conversation: A mock object configured with the above attributes.
93+ """
6094 mock_conversation = mocker .Mock ()
6195 mock_conversation .id = conversation_id
6296 mock_conversation .created_at = mocker .Mock ()
@@ -73,7 +107,20 @@ def create_mock_conversation(
73107def mock_database_session (
74108 mocker : MockerFixture , query_result : Optional [list [MockType ]] = None
75109) -> MockType :
76- """Helper function to mock get_session with proper context manager support."""
110+ """Helper function to mock get_session with proper context manager support.
111+
112+ Create and patch a mocked database session and a context-manager-compatible get_session.
113+
114+ Parameters:
115+ mocker (pytest.MockerFixture): Fixture used to create and patch mocks.
116+ query_result (Optional[list]): If provided, configures the
117+ session.query().all() and session.query().filter_by().all() to return
118+ this list.
119+
120+ Returns:
121+ Mock: The mocked session object that will be yielded by the patched
122+ get_session context manager.
123+ """
77124 mock_session = mocker .Mock ()
78125 if query_result is not None :
79126 # Mock both the filtered and unfiltered query paths
@@ -94,7 +141,16 @@ def mock_database_session(
94141
95142@pytest .fixture (name = "setup_configuration" )
96143def setup_configuration_fixture () -> AppConfig :
97- """Set up configuration for tests."""
144+ """Set up configuration for tests.
145+
146+ Create an AppConfig prepopulated with test-friendly default settings.
147+
148+ Returns:
149+ AppConfig: An AppConfig instance initialized from a dictionary
150+ containing defaults suitable for tests (local service host/port,
151+ disabled auth and user-data collection, test Llama Stack API key and
152+ URL, and single worker).
153+ """
98154 config_dict : dict [str , Any ] = {
99155 "name" : "test" ,
100156 "service" : {
@@ -123,7 +179,29 @@ def setup_configuration_fixture() -> AppConfig:
123179
124180@pytest .fixture (name = "mock_session_data" )
125181def mock_session_data_fixture () -> dict [str , Any ]:
126- """Create mock session data for testing."""
182+ """Create mock session data for testing.
183+
184+ Provide a representative mock session data payload used by tests to
185+ simulate a conversation session.
186+
187+ The returned dictionary contains:
188+ - session_id: conversation identifier.
189+ - session_name: human-readable session name.
190+ - started_at: ISO 8601 timestamp when the session started.
191+ - turns: list of turn objects; each turn includes:
192+ - turn_id: identifier for the turn.
193+ - input_messages: list of input message objects with `content`, `role`,
194+ and optional `context`.
195+ - output_message: assistant response object with `content`, `role`, and
196+ auxiliary fields (e.g., `stop_reason`, `tool_calls`) that tests
197+ expect to be filtered by simplification logic.
198+ - started_at / completed_at: ISO 8601 timestamps for the turn.
199+ - steps: detailed internal steps included to verify they are removed by simplification.
200+
201+ Returns:
202+ dict: A mock session data structure matching the shape produced by the
203+ Llama Stack client for use in unit tests.
204+ """
127205 return {
128206 "session_id" : VALID_CONVERSATION_ID ,
129207 "session_name" : "test-session" ,
@@ -165,7 +243,17 @@ def mock_session_data_fixture() -> dict[str, Any]:
165243
166244@pytest .fixture (name = "expected_chat_history" )
167245def expected_chat_history_fixture () -> list [dict [str , Any ]]:
168- """Create expected simplified chat history for testing."""
246+ """Create expected simplified chat history for testing.
247+
248+ Expected simplified chat history used by tests.
249+
250+ Returns:
251+ list[dict[str, Any]]: A list of conversation turns. Each turn contains:
252+ - messages: list of message dicts with `content` (str) and `type`
253+ (`"user"` or `"assistant"`)
254+ - started_at: ISO 8601 UTC timestamp string for the turn start
255+ - completed_at: ISO 8601 UTC timestamp string for the turn end
256+ """
169257 return [
170258 {
171259 "messages" : [
@@ -188,7 +276,14 @@ def expected_chat_history_fixture() -> list[dict[str, Any]]:
188276
189277@pytest .fixture (name = "mock_conversation" )
190278def mock_conversation_fixture () -> UserConversation :
191- """Create a mock UserConversation object for testing."""
279+ """Create a mock UserConversation object for testing.
280+
281+ Returns:
282+ mock_conv (UserConversation): A UserConversation initialized with
283+ VALID_CONVERSATION_ID, user_id set to "another_user", message_count 2,
284+ last_used_model "mock-model", last_used_provider "mock-provider", and
285+ topic_summary "Mock topic".
286+ """
192287 mock_conv = UserConversation ()
193288 mock_conv .id = VALID_CONVERSATION_ID
194289 mock_conv .user_id = "another_user" # Different from test auth
@@ -366,7 +461,15 @@ async def test_llama_stack_not_found_error(
366461 setup_configuration : AppConfig ,
367462 dummy_request : Request ,
368463 ) -> None :
369- """Test the endpoint when LlamaStack returns NotFoundError."""
464+ """Test the endpoint when LlamaStack returns NotFoundError.
465+
466+ Verify the GET /conversations/{conversation_id} handler raises an HTTP
467+ 404 when the Llama Stack client reports the session as not found.
468+
469+ Asserts that the raised HTTPException contains a response message
470+ indicating the conversation was not found and a cause that includes
471+ "does not exist" and the conversation ID.
472+ """
370473 mock_authorization_resolvers (mocker )
371474 mocker .patch ("app.endpoints.conversations.configuration" , setup_configuration )
372475 mocker .patch ("app.endpoints.conversations.check_suid" , return_value = True )
0 commit comments