fix: backtest submission shows no results — 4 bugs fixed

- ID mismatch: API generated a throwaway UUID while BacktestReplay
  generated its own internally. Frontend polled with wrong ID and
  never found the DB row. Now pre-generate ID in endpoint and pass
  it to BacktestReplay.
- Field name: API returned 'backtest_id' but frontend read 'data.id'.
  Unified to 'id' everywhere.
- No polling: useBacktestResult fired once and never refreshed.
  Added refetchInterval that polls every 2s while status is running.
- Response shape: GET endpoint nested results under 'result' object
  but frontend expected flat fields. Flattened response to match
  BacktestResult type.
- Added running/failed/completed status indicators in BacktestPanel.
This commit is contained in:
Celes Renata
2026-04-17 00:31:17 +00:00
parent f11aa0a1ee
commit f2d8744a4f
5 changed files with 74 additions and 51 deletions
+5 -5
View File
@@ -222,7 +222,7 @@ class TestProperty29PersistenceRoundTrip:
assert isinstance(resp.json()["ready"], bool)
def test_backtest_returns_id(self) -> None:
"""POST /api/trading/backtest returns a backtest_id string."""
"""POST /api/trading/backtest returns an id string."""
client = _get_client()
resp = client.post(
"/api/trading/backtest",
@@ -235,9 +235,9 @@ class TestProperty29PersistenceRoundTrip:
)
assert resp.status_code == 200
data = resp.json()
assert "backtest_id" in data
assert isinstance(data["backtest_id"], str)
assert len(data["backtest_id"]) > 0
assert "id" in data
assert isinstance(data["id"], str)
assert len(data["id"]) > 0
def test_backtest_get_returns_placeholder(self) -> None:
"""GET /api/trading/backtest/{id} returns a result dict."""
@@ -246,7 +246,7 @@ class TestProperty29PersistenceRoundTrip:
resp = client.get(f"/api/trading/backtest/{test_id}")
assert resp.status_code == 200
data = resp.json()
assert data["backtest_id"] == test_id
assert data["id"] == test_id
def test_decisions_returns_list(self) -> None:
"""GET /api/trading/decisions returns a list."""