Files
Celes Renata 898f89926d feat: beta API integration test suite — 85 new tests across 6 modules
Extends integration test coverage from 108 to 193 tests for the beta gate.

New test modules:
- test_query_api_extended.py (33 tests): documents, evidence, macro/competitive, ops/admin, agents, analytics
- test_registry_write_paths.py (16 tests): write paths, validation, duplicates, competitor/exposure CRUD
- test_risk_approval_lifecycle.py (8 tests): evaluation edge cases, full approval lifecycle
- test_trading_extended.py (12 tests): config round-trips, decision filtering, override validation
- test_cross_service_roundtrip.py (4 tests): cross-service data consistency
- test_error_handling.py (12 tests): 404s, 422s, empty states, health checks

Seed script extended with watchlists, approvals, lockouts, notifications,
ingestion runs, saved queries, and daily risk snapshots.
2026-04-20 02:34:19 +00:00

8.5 KiB

Tasks

Task 1: Extend Seed Script with New Test Data

  • 1.1 Add deterministic UUID constants for watchlists, approvals, lockouts, notifications, ingestion runs, saved queries, and daily risk snapshots
  • 1.2 Add _seed_watchlists function to insert 2 watchlists with 3 watchlist members
  • 1.3 Add _seed_operator_approvals function to insert 1 pending and 1 approved approval record
  • 1.4 Add _seed_symbol_lockouts function to insert 1 active and 1 expired lockout
  • 1.5 Add _seed_notifications function to insert 1 delivered notification record
  • 1.6 Add _seed_ingestion_runs function to insert 2 ingestion runs (completed + failed)
  • 1.7 Add _seed_saved_queries function to insert 1 saved query record
  • 1.8 Add _seed_daily_risk_snapshots function to insert 1 daily risk snapshot
  • 1.9 Export new seed ID lookup dictionaries (SEED_WATCHLIST_IDS, SEED_APPROVAL_IDS, SEED_LOCKOUT_IDS, etc.)
  • 1.10 Call all new seed functions from the main seed() function
  • 1.11 Update conftest.py to import and expose new seed IDs in the seed_ids fixture

Task 2: Query API Extended Tests — Documents and Evidence

  • 2.1 Create tests/integration/test_query_api_extended.py with test class for document filtering (by ticker, by doc_type)
  • 2.2 Add test for document detail with non-existent UUID returning 404
  • 2.3 Add test for recommendation evidence drill-down endpoint (/api/recommendations/{id}/evidence)
  • 2.4 Add test for trend evidence drill-down endpoint (/api/trends/{id}/evidence)
  • 2.5 Add test for trend projection endpoint (/api/trends/{id}/projection)
  • 2.6 Add test for trend projection with no projection returning appropriate response

Task 3: Query API Extended Tests — Macro and Competitive Layer

  • 3.1 Add test for macro status endpoint (/api/admin/macro/status)
  • 3.2 Add test for macro events list endpoint (/api/macro/events) verifying seeded events
  • 3.3 Add test for macro event detail endpoint (/api/macro/events/{id}) with impacts
  • 3.4 Add test for macro impacts by ticker endpoint (/api/macro/impacts/AAPL)
  • 3.5 Add test for competitive status endpoint (/api/admin/competitive/status)
  • 3.6 Add test for competitive signals endpoint (/api/patterns/{ticker}/competitive-signals)
  • 3.7 Add test for patterns endpoint (/api/patterns/{ticker})

Task 4: Query API Extended Tests — Operational and Admin Endpoints

  • 4.1 Add test for pipeline health endpoint verifying all required fields
  • 4.2 Add test for ingestion summary endpoint verifying total_runs and by_source_type
  • 4.3 Add test for coverage gaps endpoint verifying missing_source_types and stale_sources
  • 4.4 Add test for source toggle endpoint (PUT /api/admin/sources/{id}/toggle)
  • 4.5 Add test for trading config endpoint (GET /api/admin/trading/config)
  • 4.6 Add test for pending approvals endpoint (GET /api/admin/trading/approvals)
  • 4.7 Add test for active lockouts endpoint (GET /api/admin/trading/lockouts)
  • 4.8 Add test for lockout create and delete lifecycle (POST then DELETE /api/admin/trading/lockouts)

Task 5: Query API Extended Tests — Agents and Analytics

  • 5.1 Add test for agent detail endpoint (GET /api/agents/{id}) verifying system_prompt, temperature, max_tokens
  • 5.2 Add test for agent create endpoint (POST /api/agents) verifying 201 and slug generation
  • 5.3 Add test for agent update endpoint (PUT /api/agents/{id})
  • 5.4 Add test for variant create endpoint (POST /api/agents/{id}/variants) verifying 201
  • 5.5 Add test for variant activate endpoint (POST /api/agents/{id}/variants/{vid}/activate)
  • 5.6 Add test for agent performance endpoint (GET /api/agents/{id}/performance)
  • 5.7 Add test for variant performance endpoint (GET /api/agents/{id}/variants/{vid}/performance)
  • 5.8 Add test for PostgreSQL schema endpoint (GET /api/analytics/pg-schema)
  • 5.9 Add test for saved queries list endpoint (GET /api/analytics/saved-queries)
  • 5.10 Add test for saved query create and delete lifecycle
  • 5.11 Add test for pg-query endpoint with a valid read-only SQL query

Task 6: Symbol Registry Write Path and Edge Case Tests

  • 6.1 Create tests/integration/test_registry_write_paths.py with test for duplicate company creation returning 409
  • 6.2 Add test for company not found returning 404
  • 6.3 Add test for alias creation (POST /companies/{id}/aliases) returning 201
  • 6.4 Add test for source creation (POST /companies/{id}/sources) returning 201
  • 6.5 Add test for source creation with invalid source_type returning 422
  • 6.6 Add test for watchlist creation (POST /watchlists) returning 201
  • 6.7 Add test for watchlist member addition (POST /watchlists/{id}/members/{company_id}) returning 201
  • 6.8 Add test for watchlist members list (GET /watchlists/{id}/members) with ticker and legal_name
  • 6.9 Add test for duplicate watchlist creation returning 409

Task 7: Symbol Registry — Competitor and Exposure Write Paths

  • 7.1 Add test for competitor creation (POST /companies/{id}/competitors) returning 201
  • 7.2 Add test for self-referencing competitor returning 400
  • 7.3 Add test for competitor update (PUT /companies/{id}/competitors/{rel_id})
  • 7.4 Add test for competitor soft-delete (DELETE /companies/{id}/competitors/{rel_id}) returning 200
  • 7.5 Add test for exposure profile upsert (PUT /companies/{id}/exposure) with version increment
  • 7.6 Add test for exposure history endpoint (GET /companies/{id}/exposure/history)
  • 7.7 Add test for exposure profile not found returning 404

Task 8: Risk Engine — Evaluation Edge Cases and Approval Lifecycle

  • 8.1 Create tests/integration/test_risk_approval_lifecycle.py with test for minimal order evaluation
  • 8.2 Add test for order exceeding position cap returning eligible: false
  • 8.3 Add test for evaluation with custom config override
  • 8.4 Add test for pending approvals list from seeded data
  • 8.5 Add test for approval detail endpoint (GET /approvals/{id}) with seeded pending approval
  • 8.6 Add test for approval review (POST /approvals/{id}/review with approved: true)
  • 8.7 Add test for review of non-existent approval returning 404
  • 8.8 Add test for approval expiry endpoint (POST /approvals/expire)

Task 9: Trading Engine — Configuration Round-Trips and Extended Tests

  • 9.1 Create tests/integration/test_trading_extended.py with config round-trip test (PUT config → GET status)
  • 9.2 Add test for pause/resume round-trip (POST pause → GET status → POST resume → GET status)
  • 9.3 Add test for metrics consistency (total_portfolio_value ≈ active_pool + reserve_pool + unrealized_pnl)
  • 9.4 Add test for metrics history returning portfolio snapshots
  • 9.5 Add test for notification config update round-trip (PUT → GET)
  • 9.6 Add test for notification history endpoint
  • 9.7 Add test for decisions filtering by ticker
  • 9.8 Add test for decisions filtering by limit
  • 9.9 Add test for decisions filtering by decision type
  • 9.10 Add test for override order with invalid ticker returning 422
  • 9.11 Add test for override order with zero/negative quantity returning 422
  • 9.12 Add test for valid override order returning 202 or structured error

Task 10: Cross-Service Round-Trip Tests

  • 10.1 Create tests/integration/test_cross_service_roundtrip.py with test creating company via registry then reading via query API
  • 10.2 Add test for exposure profile round-trip (PUT via registry → GET via registry)
  • 10.3 Add test for competitor relationship bidirectional visibility
  • 10.4 Add test for risk evaluation schema matching what query API returns for recommendations

Task 11: Error Handling and Empty-State Tests

  • 11.1 Create tests/integration/test_error_handling.py with test for empty list endpoints returning 200 with []
  • 11.2 Add test for non-existent UUID detail endpoints returning 404 with JSON body
  • 11.3 Add test for invalid JSON body returning 422 with validation details
  • 11.4 Add test for trend projection with no projection returning appropriate response (not 500)
  • 11.5 Add test for macro impacts with no data returning 200 with empty impacts list
  • 11.6 Add test verifying all four service health endpoints return {"status": "ok"}
  • 11.7 Add test for override order structured error when Redis unavailable (503 with JSON, not unhandled exception)