Skip to content
Shell
5.2 KB
Raw Blame

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 use transformMarket
  • web/src/app/api/prediction-markets/search/route.ts - Import and use transformMarket

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:

  1. Check trending markets have real prices:

    curl -s "http://localhost:8000/api/predictions/trending?limit=3" | jq '.markets[0] | {title, yes_price, no_price}'
    
  2. 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

  1. Navigate to prediction markets panel
  2. Verify prices are NOT 50% (should be real probabilities)
  3. Search for "Bitcoin" - verify results contain "Bitcoin" in title
  4. Click a market - verify it opens on Polymarket (not 404)
  5. 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 camelCase
  • should handle missing fields gracefully
  • should 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 keys
  • should handle null/undefined values
  • should 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_prices
  • test_polymarket_search_filters_by_query
  • test_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:

  1. Load prediction markets
  2. Verify real prices display
  3. Test search functionality
  4. Test watchlist persistence
  5. 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.ts
  • web/src/lib/utils/__tests__/prediction-market-transform.test.ts
  • web/src/app/api/prediction-markets/__tests__/route.test.ts
  • core/tests/test_prediction_markets.py

Modified Files:

  • web/src/app/api/prediction-markets/route.ts
  • web/src/app/api/prediction-markets/search/route.ts

Already Fixed (verify only):

  • core/data/prediction_markets.py

Success Criteria

  1. All prediction markets show real probabilities (not 50%)
  2. Search returns only relevant, active markets
  3. Clicking market opens valid Polymarket page
  4. All tests pass
  5. No TypeScript errors
  6. No Python errors