Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app/endpoints/conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def get_conversations_list_endpoint_handler(
"""Handle request to retrieve all conversations for the authenticated user."""
check_configuration_loaded(configuration)

user_id, _, _ = auth
user_id = auth[0]

logger.info("Retrieving conversations for user %s", user_id)

Expand Down Expand Up @@ -249,7 +249,7 @@ async def get_conversation_endpoint_handler(
},
)

user_id, _, _ = auth
user_id = auth[0]

user_conversation = validate_conversation_ownership(
user_id=user_id,
Expand Down Expand Up @@ -371,7 +371,7 @@ async def delete_conversation_endpoint_handler(
},
)

user_id, _, _ = auth
user_id = auth[0]

user_conversation = validate_conversation_ownership(
user_id=user_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/app/endpoints/test_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from configuration import AppConfig
from tests.unit.utils.auth_helpers import mock_authorization_resolvers

MOCK_AUTH = ("mock_user_id", "mock_username", "mock_token")
MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Make auth shape explicit to avoid positional brittleness

Consider a NamedTuple to document fields and reduce future breakage if order changes.

+from typing import NamedTuple
+
+class MockAuth(NamedTuple):
+    user_id: str
+    username: str
+    is_admin: bool
+    token: str
+
-MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
+MOCK_AUTH = MockAuth("mock_user_id", "mock_username", False, "mock_token")

Run to spot any lingering tuple-unpacking of auth or assumptions about a 3-tuple:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Potential outdated 3-item destructuring of auth:"
rg -nP --type=py -C2 '\b(?:\w+|_)\s*,\s*(?:\w+|_)\s*,\s*(?:\w+|_)\s*=\s*auth\b'

echo
echo "Any tuple destructuring of auth (manual review recommended):"
rg -nP --type=py -C1 '\(\s*[^()]+\s*(?:,\s*[^()]+){2,}\s*\)\s*=\s*auth\b'

echo
echo "Common legacy pattern (user_id, _, _ = auth):"
rg -nP --type=py -C2 '\buser_id\s*,\s*_\s*,\s*_\s*=\s*auth\b'

echo
echo "Callers using 4th element (index 3) of auth:"
rg -nP --type=py -C2 'auth\[\s*3\s*\]'

echo
echo "All MOCK_AUTH definitions:"
rg -n --type=py 'MOCK_AUTH\s*='

Length of output: 2361


Define MockAuth NamedTuple and replace positional auth unpacking with attribute access

+from typing import NamedTuple
+
+class MockAuth(NamedTuple):
+    user_id: str
+    username: str
+    is_admin: bool
+    token: str
+
-MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
+MOCK_AUTH = MockAuth("mock_user_id", "mock_username", False, "mock_token")

Detected residual positional destructuring in:

  • src/authorization/resolvers.py:84 (_, _, _, token = auth)
  • src/app/endpoints/authorized.py:53 (user_id, user_name, skip_userid_check, _ = auth)
  • src/app/endpoints/feedback.py:113 & 198 (user_id, _, _, _ = auth)
  • src/app/endpoints/query.py:183 (user_id, _, _, token = auth)
  • src/app/endpoints/streaming_query.py:559 (user_id, _user_name, _skip_userid_check, token = auth)

Update each to use auth.user_id, auth.username, auth.is_admin, and auth.token instead of tuple unpacking.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token")
from typing import NamedTuple
class MockAuth(NamedTuple):
user_id: str
username: str
is_admin: bool
token: str
MOCK_AUTH = MockAuth("mock_user_id", "mock_username", False, "mock_token")
🤖 Prompt for AI Agents
In tests/unit/app/endpoints/test_conversations.py around line 24 and in the
listed resolver/endpoints (src/authorization/resolvers.py around line 84,
src/app/endpoints/authorized.py around line 53, src/app/endpoints/feedback.py
around lines 113 and 198, src/app/endpoints/query.py around line 183, and
src/app/endpoints/streaming_query.py around line 559) the code still unpacks a
positional auth tuple; define a NamedTuple (e.g., MockAuth with fields user_id,
username, is_admin, token) and replace all positional destructuring with
attribute access (auth.user_id, auth.username, auth.is_admin, auth.token) and
update tests to use MockAuth(...) instead of a plain tuple to keep usage clear
and type-safe.

VALID_CONVERSATION_ID = "123e4567-e89b-12d3-a456-426614174000"
INVALID_CONVERSATION_ID = "invalid-id"

Expand Down