mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-13 05:47:23 -04:00
feat(api): return warnings in /simulate/status response
Parse and return job warnings from database. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
12
api/main.py
12
api/main.py
@@ -292,7 +292,7 @@ def create_app(
|
|||||||
job_id: Job UUID
|
job_id: Job UUID
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Job status, progress, and model-day details
|
Job status, progress, model-day details, and warnings
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
HTTPException 404: If job not found
|
HTTPException 404: If job not found
|
||||||
@@ -314,6 +314,15 @@ def create_app(
|
|||||||
# Calculate pending (total - completed - failed)
|
# Calculate pending (total - completed - failed)
|
||||||
pending = progress["total_model_days"] - progress["completed"] - progress["failed"]
|
pending = progress["total_model_days"] - progress["completed"] - progress["failed"]
|
||||||
|
|
||||||
|
# Parse warnings from JSON if present
|
||||||
|
import json
|
||||||
|
warnings = None
|
||||||
|
if job.get("warnings"):
|
||||||
|
try:
|
||||||
|
warnings = json.loads(job["warnings"])
|
||||||
|
except (json.JSONDecodeError, TypeError):
|
||||||
|
logger.warning(f"Failed to parse warnings for job {job_id}")
|
||||||
|
|
||||||
# Get deployment mode info
|
# Get deployment mode info
|
||||||
deployment_info = get_deployment_mode_dict()
|
deployment_info = get_deployment_mode_dict()
|
||||||
|
|
||||||
@@ -334,6 +343,7 @@ def create_app(
|
|||||||
total_duration_seconds=job.get("total_duration_seconds"),
|
total_duration_seconds=job.get("total_duration_seconds"),
|
||||||
error=job.get("error"),
|
error=job.get("error"),
|
||||||
details=details,
|
details=details,
|
||||||
|
warnings=warnings,
|
||||||
**deployment_info
|
**deployment_info
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -384,5 +384,32 @@ class TestAsyncDownload:
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert "job_id" in response.json()
|
assert "job_id" in response.json()
|
||||||
|
|
||||||
|
def test_status_endpoint_returns_warnings(self, api_client):
|
||||||
|
"""Test that /simulate/status returns warnings field."""
|
||||||
|
from api.database import initialize_database
|
||||||
|
from api.job_manager import JobManager
|
||||||
|
|
||||||
|
# Create job with warnings
|
||||||
|
db_path = api_client.db_path
|
||||||
|
job_manager = JobManager(db_path=db_path)
|
||||||
|
|
||||||
|
job_id = job_manager.create_job(
|
||||||
|
config_path="config.json",
|
||||||
|
date_range=["2025-10-01"],
|
||||||
|
models=["gpt-5"]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add warnings
|
||||||
|
warnings = ["Rate limited", "Skipped 1 date"]
|
||||||
|
job_manager.add_job_warnings(job_id, warnings)
|
||||||
|
|
||||||
|
# Get status
|
||||||
|
response = api_client.get(f"/simulate/status/{job_id}")
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
data = response.json()
|
||||||
|
assert "warnings" in data
|
||||||
|
assert data["warnings"] == warnings
|
||||||
|
|
||||||
|
|
||||||
# Coverage target: 90%+ for api/main.py
|
# Coverage target: 90%+ for api/main.py
|
||||||
|
|||||||
Reference in New Issue
Block a user