Skip to content

Commit f540385

Browse files
committed
fix: CI failures — ruff format, docker ENCRYPTION_KEY
- Run ruff format on 4 backend files - Add ENCRYPTION_KEY to docker-compose.yml (required since Phase 1)
1 parent 4dc83fa commit f540385

File tree

5 files changed

+25
-27
lines changed

5 files changed

+25
-27
lines changed

apps/api/app/core/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ def validate_secrets(self) -> None:
111111
if len(self.ENCRYPTION_KEY) < 32:
112112
raise ValueError(
113113
"ENCRYPTION_KEY must be at least 32 bytes long for Fernet encryption. "
114-
"Generate one with: python -c \"from cryptography.fernet import Fernet; "
115-
"print(Fernet.generate_key().decode())\" and set as export ENCRYPTION_KEY=<key>"
114+
'Generate one with: python -c "from cryptography.fernet import Fernet; '
115+
'print(Fernet.generate_key().decode())" and set as export ENCRYPTION_KEY=<key>'
116116
)
117117

118118
# Production and staging environments must use explicit key (not default)
119119
if (self.is_production or self.is_staging) and self.is_using_default_secrets:
120120
raise ValueError(
121121
f"Cannot use default encryption key in {self.ENVIRONMENT} environment. "
122122
"Please set ENCRYPTION_KEY environment variable explicitly. "
123-
"Generate with: python -c \"from cryptography.fernet import Fernet; "
124-
"print(Fernet.generate_key().decode())\" and export ENCRYPTION_KEY=<generated_key>"
123+
'Generate with: python -c "from cryptography.fernet import Fernet; '
124+
'print(Fernet.generate_key().decode())" and export ENCRYPTION_KEY=<generated_key>'
125125
)
126126

127127

apps/api/app/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,11 @@ async def global_exception_handler(request: Request, exc: Exception) -> JSONResp
250250
if settings.DEBUG:
251251
# In debug mode: include request path but NOT full stack trace
252252
response_data["debug_detail"] = str(exc)
253-
logger.debug("Debug error details", request_path=str(request.url.path), full_exception=traceback.format_exc())
253+
logger.debug(
254+
"Debug error details",
255+
request_path=str(request.url.path),
256+
full_exception=traceback.format_exc(),
257+
)
254258

255259
return JSONResponse(
256260
status_code=status_code,

apps/api/app/services/result_processor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ async def extract_results(
106106
chart_config = extract_chart_config(ai_content)
107107
if chart_config:
108108
result["chart_config"] = chart_config
109-
logger.info("Extracted chart configuration", chart_type=chart_config.get("type"))
109+
logger.info(
110+
"Extracted chart configuration", chart_type=chart_config.get("type")
111+
)
110112
except Exception as exc:
111113
logger.warning("Failed to extract chart config", error=str(exc))
112114
result["errors"].append(f"Chart extraction: {exc}")
113115

114116
artifact_count = sum(
115-
1
116-
for k, v in result.items()
117-
if k != "errors" and k != "thinking" and v is not None
117+
1 for k, v in result.items() if k != "errors" and k != "thinking" and v is not None
118118
)
119119
logger.info(
120120
"Result extraction completed",

apps/api/tests/test_services.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ async def test_execute_sql_programming_error(self, executor):
9090
with patch("app.services.database.create_database_manager") as mock_create_db:
9191
mock_db = MagicMock()
9292
mock_db.execute_query = MagicMock(
93-
side_effect=ProgrammingError(
94-
"syntax error", None, None
95-
)
93+
side_effect=ProgrammingError("syntax error", None, None)
9694
)
9795
mock_create_db.return_value = mock_db
9896

@@ -109,9 +107,7 @@ async def test_execute_sql_value_error(self, executor):
109107
"""Test SQL execution with ValueError (validation error)"""
110108
with patch("app.services.database.create_database_manager") as mock_create_db:
111109
mock_db = MagicMock()
112-
mock_db.execute_query = MagicMock(
113-
side_effect=ValueError("Read-only check failed")
114-
)
110+
mock_db.execute_query = MagicMock(side_effect=ValueError("Read-only check failed"))
115111
mock_create_db.return_value = mock_db
116112

117113
result, count = await executor.execute_sql(
@@ -152,9 +148,7 @@ async def test_inject_sql_data_custom_variable_name(self, executor):
152148
sql = "SELECT * FROM users"
153149
data = [{"id": 1}]
154150

155-
code = await executor.inject_sql_data(
156-
sql, data, variable_name="custom_var"
157-
)
151+
code = await executor.inject_sql_data(sql, data, variable_name="custom_var")
158152

159153
assert "custom_var" in code
160154
assert isinstance(code, str)
@@ -194,10 +188,7 @@ async def test_execute_safe_code(self, sandbox):
194188
mock_runtime.inject_sql_data = MagicMock()
195189
mock_runtime_class.return_value = mock_runtime
196190

197-
with patch.object(
198-
sandbox, "_execute_with_timeout",
199-
return_value=("3", [])
200-
):
191+
with patch.object(sandbox, "_execute_with_timeout", return_value=("3", [])):
201192
output, images = await sandbox.execute(safe_code)
202193

203194
assert output == "3"
@@ -260,8 +251,7 @@ async def test_execute_with_sql_data(self, sandbox):
260251
mock_runtime_class.return_value = mock_runtime
261252

262253
with patch.object(
263-
sandbox, "_execute_with_timeout",
264-
return_value=("[{'id': 1}]", [])
254+
sandbox, "_execute_with_timeout", return_value=("[{'id': 1}]", [])
265255
):
266256
output, images = await sandbox.execute(code, sql_data=sql_data)
267257

@@ -373,7 +363,9 @@ async def test_extract_results_malformed_response(self, processor):
373363
with patch("app.services.engine_content.extract_sql_block", return_value=None):
374364
with patch("app.services.engine_content.extract_python_block", return_value=None):
375365
with patch("app.services.engine_content.extract_chart_config", return_value=None):
376-
with patch("app.services.engine_content.parse_thinking_markers", return_value=[]):
366+
with patch(
367+
"app.services.engine_content.parse_thinking_markers", return_value=[]
368+
):
377369
result = await processor.extract_results(ai_content)
378370

379371
assert result["sql_code"] is None
@@ -397,7 +389,6 @@ async def test_extract_chart_config_valid(self, processor):
397389
"yKeys": ["revenue"],
398390
}
399391

400-
401392
await processor.extract_results(ai_content)
402393

403394
# Since extract_chart_config is mocked, verify the mock is set up
@@ -423,7 +414,9 @@ def test_build_chart_payload(self, processor):
423414
"data": data,
424415
}
425416

426-
with patch("app.services.engine_visualization.build_chart_from_config", return_value=expected_chart):
417+
with patch(
418+
"app.services.engine_visualization.build_chart_from_config", return_value=expected_chart
419+
):
427420
result = processor.build_chart_payload(chart_config, data)
428421

429422
assert result is not None

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ services:
2828
PORT: "8000"
2929
ENVIRONMENT: development
3030
DEBUG: "true"
31+
ENCRYPTION_KEY: "docker-dev-key-min-32-bytes-long!!"
3132
LOG_FORMAT: console
3233
CORS_ORIGINS_STR: http://localhost:3000,http://127.0.0.1:3000
3334
MPLBACKEND: Agg

0 commit comments

Comments
 (0)