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
9 changes: 4 additions & 5 deletions dev-tools/mcp-mock-server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import sys
import threading
from http.server import HTTPServer, BaseHTTPRequestHandler
from datetime import datetime
from datetime import datetime, UTC
from pathlib import Path
from typing import Any

Expand All @@ -38,21 +38,20 @@ class MCPMockHandler(BaseHTTPRequestHandler):

def log_message(self, format: str, *args: Any) -> None:
"""Log requests with timestamp.""" # pylint: disable=redefined-builtin
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
timestamp = datetime.now(tz=UTC).strftime("%Y-%m-%d %H:%M:%S")
print(f"[{timestamp}] {format % args}")

def _capture_headers(self) -> None:
"""Capture all headers from the request."""
last_headers.clear()

# Capture all headers for debugging
for header_name, value in self.headers.items():
last_headers[header_name] = value
last_headers.update(dict(self.headers.items()))

# Log the request
request_log.append(
{
"timestamp": datetime.now().isoformat(),
"timestamp": datetime.now(tz=UTC).isoformat(),
"method": self.command,
"path": self.path,
"headers": dict(last_headers),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ disable = ["R0801"]
extend-exclude = ["tests/profiles/syntax_error.py"]

[tool.ruff.lint]
extend-select = ["TID251", "UP006", "UP007", "UP010", "UP017", "UP035", "RUF100", "B009", "B010"]
extend-select = ["TID251", "UP006", "UP007", "UP010", "UP017", "UP035", "RUF100", "B009", "B010", "DTZ005"]

[tool.ruff.lint.flake8-tidy-imports.banned-api]
unittest = { msg = "use pytest instead of unittest" }
Expand Down
2 changes: 1 addition & 1 deletion scripts/gen_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def generate_docfile(directory):
f"# List of source files stored in `{directory}` directory",
file=indexfile,
)
print("", file=indexfile)
print(file=indexfile)
files = sorted(os.listdir())

for file in files:
Expand Down
4 changes: 2 additions & 2 deletions src/app/endpoints/rlsapi_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import functools
import time
from datetime import datetime
from datetime import datetime, UTC
from typing import Annotated, Any, Optional, cast

import jinja2
Expand Down Expand Up @@ -123,7 +123,7 @@ def _build_instructions(systeminfo: RlsapiV1SystemInfo) -> str:
Returns:
The rendered instructions string for the LLM.
"""
date_today = datetime.now().strftime("%B %d, %Y")
date_today = datetime.now(tz=UTC).strftime("%B %d, %Y")

return _get_prompt_template().render(
date=date_today,
Expand Down
10 changes: 5 additions & 5 deletions src/quota/revokable_quota_limiter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Simple quota limiter where quota can be revoked."""

from datetime import datetime
from datetime import datetime, UTC

from models.config import QuotaHandlersConfiguration
from log import get_logger
Expand Down Expand Up @@ -140,7 +140,7 @@ def _revoke_quota(self, set_statement: str, subject_id: str) -> None:
revoked.
"""
# timestamp to be used
revoked_at = datetime.now()
revoked_at = datetime.now(tz=UTC)

cursor = self.connection.cursor()
cursor.execute(
Expand Down Expand Up @@ -188,7 +188,7 @@ def _increase_quota(self, set_statement: str, subject_id: str) -> None:
subject_id (str): Identifier of the subject whose quota will be increased.
"""
# timestamp to be used
updated_at = datetime.now()
updated_at = datetime.now(tz=UTC)

cursor = self.connection.cursor()
cursor.execute(
Expand Down Expand Up @@ -286,7 +286,7 @@ def _consume_tokens(
change.
"""
# timestamp to be used
updated_at = datetime.now()
updated_at = datetime.now(tz=UTC)

to_be_consumed = input_tokens + output_tokens

Expand Down Expand Up @@ -329,7 +329,7 @@ def _init_quota(self, subject_id: str = "") -> None:
initialize. Defaults to empty string.
"""
# timestamp to be used
revoked_at = datetime.now()
revoked_at = datetime.now(tz=UTC)

if self.sqlite_connection_config is not None:
cursor = self.connection.cursor()
Expand Down
4 changes: 2 additions & 2 deletions src/quota/token_usage_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import sqlite3
from datetime import datetime
from datetime import datetime, UTC
from typing import Any, Optional

import psycopg2
Expand Down Expand Up @@ -135,7 +135,7 @@ def consume_tokens( # pylint: disable=too-many-arguments,too-many-positional-ar
return

# timestamp to be used
updated_at = datetime.now()
updated_at = datetime.now(tz=UTC)

# it is not possible to use context manager there, because SQLite does
# not support it
Expand Down
21 changes: 14 additions & 7 deletions tests/unit/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,49 +446,56 @@ def test_configuration_not_loaded() -> None:
"""Test that accessing configuration before loading raises an error."""
cfg = AppConfig()
with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
cfg.configuration # pylint: disable=pointless-statement
c = cfg.configuration
assert c is not None
Comment on lines +449 to +450

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Dead code: assertion after exception-raising property access.

The assertion assert c is not None on line 450 will never execute because accessing cfg.configuration on line 449 raises LogicError (which is what this test verifies). The same pattern repeats in the subsequent test functions.

The previous pattern using _ = cfg.property was sufficient and clearer about intent.

🧹 Suggested fix to remove dead code
 def test_configuration_not_loaded() -> None:
     """Test that accessing configuration before loading raises an error."""
     cfg = AppConfig()
     with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
-        c = cfg.configuration
-        assert c is not None
+        _ = cfg.configuration  # pylint: disable=pointless-statement

Apply similar changes to:

  • test_service_configuration_not_loaded (lines 457-458)
  • test_llama_stack_configuration_not_loaded (lines 465-466)
  • test_user_data_collection_configuration_not_loaded (lines 473-474)
  • test_mcp_servers_not_loaded (lines 481-482)
  • test_authentication_configuration_not_loaded (lines 489-490)
  • test_customization_not_loaded (lines 497-498)
📝 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
c = cfg.configuration
assert c is not None
_ = cfg.configuration # pylint: disable=pointless-statement
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/test_configuration.py` around lines 449 - 450, The assertion after
accessing the exception-raising property is dead code; remove the trailing
`assert c is not None` and replace the access pattern with a discard (e.g., `_ =
cfg.configuration`) in the test function `test_configuration_not_loaded`, and
apply the same change to the other listed tests
(`test_service_configuration_not_loaded`,
`test_llama_stack_configuration_not_loaded`,
`test_user_data_collection_configuration_not_loaded`,
`test_mcp_servers_not_loaded`, `test_authentication_configuration_not_loaded`,
`test_customization_not_loaded`) so each test only accesses the property to
trigger the LogicError and does not include an unreachable assertion.



def test_service_configuration_not_loaded() -> None:
"""Test that accessing service_configuration before loading raises an error."""
cfg = AppConfig()
with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
cfg.service_configuration # pylint: disable=pointless-statement
c = cfg.service_configuration
assert c is not None


def test_llama_stack_configuration_not_loaded() -> None:
"""Test that accessing llama_stack_configuration before loading raises an error."""
cfg = AppConfig()
with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
cfg.llama_stack_configuration # pylint: disable=pointless-statement
c = cfg.llama_stack_configuration
assert c is not None


def test_user_data_collection_configuration_not_loaded() -> None:
"""Test that accessing user_data_collection_configuration before loading raises an error."""
cfg = AppConfig()
with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
cfg.user_data_collection_configuration # pylint: disable=pointless-statement
c = cfg.user_data_collection_configuration
assert c is not None


def test_mcp_servers_not_loaded() -> None:
"""Test that accessing mcp_servers before loading raises an error."""
cfg = AppConfig()
with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
cfg.mcp_servers # pylint: disable=pointless-statement
c = cfg.mcp_servers
assert c is not None


def test_authentication_configuration_not_loaded() -> None:
"""Test that accessing authentication_configuration before loading raises an error."""
cfg = AppConfig()
with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
cfg.authentication_configuration # pylint: disable=pointless-statement
c = cfg.authentication_configuration
assert c is not None


def test_customization_not_loaded() -> None:
"""Test that accessing customization before loading raises an error."""
cfg = AppConfig()
with pytest.raises(LogicError, match="logic error: configuration is not loaded"):
cfg.customization # pylint: disable=pointless-statement
c = cfg.customization
assert c is not None


def test_load_configuration_with_customization_system_prompt_path(tmpdir: Path) -> None:
Expand Down
Loading