Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(api): serve shadow reports from the configured runtime root

Rudy Celekliffefdf0c74e4
diff --git a/agent/src/api/uploads_routes.py b/agent/src/api/uploads_routes.py
index 54903f2c7..9dab1a038 100644
--- a/agent/src/api/uploads_routes.py
+++ b/agent/src/api/uploads_routes.py
@@ -13,7 +13,7 @@ from typing import Any, Awaitable, Callable
from fastapi import Depends, FastAPI, HTTPException, UploadFile
from fastapi.responses import FileResponse
-from src.config.paths import get_uploads_dir
+from src.config.paths import get_runtime_root, get_uploads_dir
# ---------------------------------------------------------------------------
# Constants
@@ -106,14 +106,16 @@ def register_uploads_routes(
async def get_shadow_report(shadow_id: str, format: str = "html"):
"""Serve a rendered Shadow Account report.
- Reports live under ``~/.vibe-trading/shadow_reports/<shadow_id>.{html,pdf}``.
+ Reports live under ``<runtime-root>/shadow_reports/<shadow_id>.{html,pdf}``
+ (``~/.vibe-trading`` unless ``VIBE_TRADING_HOME`` overrides it).
"""
if not _SHADOW_ID_RE.match(shadow_id):
raise HTTPException(status_code=400, detail="invalid shadow_id")
if format not in ("html", "pdf"):
raise HTTPException(status_code=400, detail="format must be html or pdf")
- reports_dir = Path.home() / ".vibe-trading" / "shadow_reports"
+ # Same root the report writer uses, so VIBE_TRADING_HOME is honoured.
+ reports_dir = get_runtime_root() / "shadow_reports"
path = reports_dir / f"{shadow_id}.{format}"
if not path.exists():
raise HTTPException(status_code=404, detail=f"Shadow report not found: {shadow_id}.{format}")
diff --git a/agent/tests/test_shadow_report_route_runtime_root.py b/agent/tests/test_shadow_report_route_runtime_root.py
new file mode 100644
index 000000000..b19cb4641
--- /dev/null
+++ b/agent/tests/test_shadow_report_route_runtime_root.py
@@ -0,0 +1,32 @@
+"""The shadow-report route must read from where reports are written."""
+
+from __future__ import annotations
+
+from pathlib import Path
+
+import pytest
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
+from src.api.uploads_routes import register_uploads_routes
+
+
+def _client() -> TestClient:
+ app = FastAPI()
+ register_uploads_routes(app, require_auth=lambda: None)
+ return TestClient(app)
+
+
+def test_shadow_report_is_served_from_the_configured_runtime_root(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
+) -> None:
+ from src.shadow_account.storage import reports_dir
+
+ monkeypatch.setenv("VIBE_TRADING_HOME", str(tmp_path / "state-root"))
+ report = reports_dir() / "shadow_0123abcd.html"
+ report.write_text("<html>report</html>", encoding="utf-8")
+
+ response = _client().get("/shadow-reports/shadow_0123abcd")
+
+ assert response.status_code == 200
+ assert "report" in response.text