Shell
Prediction Markets Feature - Complete Fix & Verification Plan
Overview
Complete the prediction markets E2E audit by extracting shared utilities, starting the backend, verifying all fixes, and adding integration tests.
Current Status
- Bug #1 (NaN%): Fixed in frontend API routes
- Bug #2 (50% prices): Fixed in Python backend (needs restart to verify)
- Bug #3 (Search): Fixed in Python backend (needs restart to verify)
Phase 1: Extract Shared Transform Utility
Task 1.1: Create shared transform utility
File: web/src/lib/utils/prediction-market-transform.ts
// Transform snake_case backend response to camelCase frontend types
export function transformMarket(market: Record<string, unknown>) {
return {
id: market.id,
platform: market.platform,
title: market.title,
category: market.category || 'Unknown',
yesPrice: market.yes_price ?? market.yesPrice ?? 0,
noPrice: market.no_price ?? market.noPrice ?? 0,
volume: market.volume ?? 0,
volume24h: market.volume_24h ?? market.volume24h,
openInterest: market.open_interest ?? market.openInterest,
endDate: market.end_date ?? market.endDate,
status: market.status || 'active',
url: market.url || '',
description: market.description,
};
}
Task 1.2: Update API routes to use shared utility
Files to modify:
web/src/app/api/prediction-markets/route.ts- Import and usetransformMarketweb/src/app/api/prediction-markets/search/route.ts- Import and usetransformMarket
Phase 2: Start Python Backend & Verify Fixes
Task 2.1: Start Python backend
Command: cd /Users/eddiebelaval/Development/deepstack && python -m core.api.api_server
Task 2.2: Verify API responses
Verification commands:
Check trending markets have real prices:
curl -s "http://localhost:8000/api/predictions/trending?limit=3" | jq '.markets[0] | {title, yes_price, no_price}'Check search returns relevant results:
curl -s "http://localhost:8000/api/predictions/search?q=Bitcoin" | jq '.markets[:3] | .[].title'
Task 2.3: E2E UI verification with Playwright
- Navigate to prediction markets panel
- Verify prices are NOT 50% (should be real probabilities)
- Search for "Bitcoin" - verify results contain "Bitcoin" in title
- Click a market - verify it opens on Polymarket (not 404)
- Take screenshots as evidence
Phase 3: Write Integration Tests
Task 3.1: Create API route tests
File: web/src/app/api/prediction-markets/__tests__/route.test.ts
Tests to write:
should transform snake_case to camelCaseshould handle missing fields gracefullyshould return mock data on backend failure
Task 3.2: Create transform utility tests
File: web/src/lib/utils/__tests__/prediction-market-transform.test.ts
Tests to write:
should transform snake_case keysshould handle null/undefined valuesshould preserve existing camelCase keys
Task 3.3: Create Python backend tests
File: core/tests/test_prediction_markets.py
Tests to write:
test_polymarket_normalize_market_parses_json_string_pricestest_polymarket_search_filters_by_querytest_polymarket_search_excludes_closed_markets
Phase 4: Run Tests & Final Verification
Task 4.1: Run frontend tests
cd web && npm run test
Task 4.2: Run Python tests
cd /Users/eddiebelaval/Development/deepstack && python -m pytest core/tests/test_prediction_markets.py -v
Task 4.3: Final E2E verification
Use Playwright to:
- Load prediction markets
- Verify real prices display
- Test search functionality
- Test watchlist persistence
- Screenshot final working state
Execution Plan (Parallel Strategy)
Wave 1 (Parallel)
| Agent | Task | Tools |
|---|---|---|
| fullstack-developer | Create shared transform utility, update API routes | Write, Edit |
| Main (Claude) | Start Python backend, verify API responses | Bash |
Wave 2 (Parallel - after Wave 1)
| Agent | Task | Tools |
|---|---|---|
| test-engineer | Write comprehensive frontend tests | Write, Edit, Bash |
| Main (Claude) | Write Python backend tests | Write, Bash |
Wave 3 (Sequential)
| Agent | Task | Tools |
|---|---|---|
| Main (Claude) | Run all tests, E2E Playwright verification | Bash, Playwright |
Oversight Strategy
- Claude watches over all agents
- After each wave, verify outputs before proceeding
- Use Playwright for visual verification at each milestone
Files to Modify/Create
New Files:
web/src/lib/utils/prediction-market-transform.tsweb/src/lib/utils/__tests__/prediction-market-transform.test.tsweb/src/app/api/prediction-markets/__tests__/route.test.tscore/tests/test_prediction_markets.py
Modified Files:
web/src/app/api/prediction-markets/route.tsweb/src/app/api/prediction-markets/search/route.ts
Already Fixed (verify only):
core/data/prediction_markets.py
Success Criteria
- All prediction markets show real probabilities (not 50%)
- Search returns only relevant, active markets
- Clicking market opens valid Polymarket page
- All tests pass
- No TypeScript errors
- No Python errors