Files
stonks-oracle/frontend/src/test/pages.test.tsx
T
Celes Renata 7fcc8a6c07
ci/woodpecker/push/test Pipeline failed
ci/woodpecker/push/build-1 unknown status
ci/woodpecker/push/build-3 unknown status
ci/woodpecker/push/build-2 unknown status
ci/woodpecker/push/finalize unknown status
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
Build and Push / beta-gate (push) Has been cancelled
feat: model validation, calibration, and signal quality layer
- Migration 035: prediction_snapshots, prediction_outcomes, signal_evidence_links, model_metric_snapshots tables + SQL views
- Prediction snapshot writer with canonical evidence keys, duplicate detection, contribution scores
- Outcome evaluator across 5 horizons (1h, 6h, 1d, 7d, 30d)
- Metrics engine: ECE, Brier score, IC, Rank IC, benchmark comparison
- Attribution engine: per-source, per-catalyst, per-layer performance
- Calibration engine: Bayesian shrinkage source reliability
- Quality gate for live trading eligibility with configurable thresholds
- 7 new /api/validation/* endpoints
- Upgraded OpsModel dashboard with validation tab
- Enhanced recommendation display with calibration context
- Backtest replay validation mode
- 86 Python tests (unit + property-based), 179 frontend tests passing
2026-05-01 03:04:58 +00:00

260 lines
8.3 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderRoute } from './render';
describe('Home page', () => {
it('renders the title and key metrics', async () => {
renderRoute('/');
await waitFor(() => {
expect(screen.getByText('Stonks Oracle')).toBeInTheDocument();
});
});
});
describe('Companies page', () => {
it('renders company list with tickers', async () => {
renderRoute('/companies');
await waitFor(() => {
expect(screen.getByText('AAPL')).toBeInTheDocument();
expect(screen.getByText('MSFT')).toBeInTheDocument();
});
});
it('filters companies by search', async () => {
renderRoute('/companies');
await waitFor(() => expect(screen.getByText('AAPL')).toBeInTheDocument());
const filter = screen.getByLabelText('Filter table');
await userEvent.type(filter, 'micro');
expect(screen.getByText('MSFT')).toBeInTheDocument();
expect(screen.queryByText('AAPL')).not.toBeInTheDocument();
});
it('shows add company form on button click', async () => {
renderRoute('/companies');
await waitFor(() => expect(screen.getByText('Add Company')).toBeInTheDocument());
await userEvent.click(screen.getByText('Add Company'));
expect(screen.getByLabelText('Ticker')).toBeInTheDocument();
expect(screen.getByLabelText('Legal Name')).toBeInTheDocument();
});
it('submits new company form', async () => {
renderRoute('/companies');
await waitFor(() => expect(screen.getByText('Add Company')).toBeInTheDocument());
await userEvent.click(screen.getByText('Add Company'));
await userEvent.type(screen.getByLabelText('Ticker'), 'TSLA');
await userEvent.type(screen.getByLabelText('Legal Name'), 'Tesla Inc.');
await userEvent.click(screen.getByText('Create'));
// Form should close on success
await waitFor(() => {
expect(screen.queryByLabelText('Ticker')).not.toBeInTheDocument();
});
});
});
describe('Documents page', () => {
it('renders document list', async () => {
renderRoute('/documents');
await waitFor(() => {
expect(screen.getByText('Apple Q4 Earnings Beat')).toBeInTheDocument();
});
});
});
describe('Trends page', () => {
it('renders trend cards with direction', async () => {
renderRoute('/trends');
await waitFor(() => {
expect(screen.getByText('AAPL')).toBeInTheDocument();
});
});
});
describe('Recommendations page', () => {
it('renders recommendation list', async () => {
renderRoute('/recommendations');
await waitFor(() => {
expect(screen.getByText('AAPL')).toBeInTheDocument();
});
});
});
describe('Orders page', () => {
it('renders order list', async () => {
renderRoute('/orders');
await waitFor(() => {
expect(screen.getByText('AAPL')).toBeInTheDocument();
});
});
});
describe('Positions page', () => {
it('renders positions with PnL', async () => {
renderRoute('/positions');
await waitFor(() => {
expect(screen.getByText('AAPL')).toBeInTheDocument();
expect(screen.getByText('$185.50')).toBeInTheDocument();
});
});
});
describe('Trading page', () => {
it('renders trading mode buttons', async () => {
renderRoute('/trading');
await waitFor(() => {
expect(screen.getByText('paper')).toBeInTheDocument();
expect(screen.getByText('live')).toBeInTheDocument();
expect(screen.getByText('disabled')).toBeInTheDocument();
});
});
});
describe('Ops pages', () => {
it('pipeline health renders', async () => {
renderRoute('/ops/pipeline');
await waitFor(() => {
expect(screen.getByText('Pipeline Health')).toBeInTheDocument();
});
});
it('ingestion monitor renders', async () => {
renderRoute('/ops/ingestion');
await waitFor(() => {
expect(screen.getByText('Ingestion Monitor')).toBeInTheDocument();
});
});
it('model performance renders', async () => {
renderRoute('/ops/model');
await waitFor(() => {
expect(screen.getByText('Model Performance')).toBeInTheDocument();
});
});
it('source coverage renders', async () => {
renderRoute('/ops/coverage');
await waitFor(() => {
expect(screen.getByText('Source Coverage')).toBeInTheDocument();
});
});
});
describe('Watchlists page', () => {
it('renders watchlists page with new button', async () => {
renderRoute('/watchlists');
await waitFor(() => {
expect(screen.getByText('New Watchlist')).toBeInTheDocument();
});
});
});
describe('Global Events page', () => {
it('renders global events list with severity filter', async () => {
renderRoute('/macro/events');
await waitFor(() => {
expect(screen.getByText('Global Events')).toBeInTheDocument();
});
});
it('renders event summary from mock data', async () => {
renderRoute('/macro/events');
await waitFor(() => {
expect(screen.getByText(/US tariffs on Chinese semiconductors/)).toBeInTheDocument();
});
});
});
describe('OpsModel validation tab', () => {
it('renders Model Validation tab with summary cards', async () => {
renderRoute('/ops/model');
await waitFor(() => expect(screen.getByText('Model Performance')).toBeInTheDocument());
// The tab buttons should be present
expect(screen.getByText('Extraction Performance')).toBeInTheDocument();
expect(screen.getByText('Model Validation')).toBeInTheDocument();
// Click the Model Validation tab button
await userEvent.click(screen.getByText('Model Validation'));
// Summary cards should render key metric labels unique to the validation summary
await waitFor(() => {
expect(screen.getByText('Brier Score')).toBeInTheDocument();
expect(screen.getByText('ECE')).toBeInTheDocument();
expect(screen.getByText('Directional Accuracy')).toBeInTheDocument();
expect(screen.getByText('Excess vs SPY')).toBeInTheDocument();
});
}, 10000);
it('renders calibration table with miscalibration warning', async () => {
renderRoute('/ops/model');
await waitFor(() => expect(screen.getByText('Model Performance')).toBeInTheDocument());
await userEvent.click(screen.getByText('Model Validation'));
await waitFor(() => {
expect(screen.getByText('Calibration by Confidence Bucket')).toBeInTheDocument();
});
// Miscalibrated buckets should show warning text
const miscalWarnings = screen.getAllByText('Miscalibrated');
expect(miscalWarnings.length).toBeGreaterThanOrEqual(1);
}, 10000);
it('renders gate status pass/fail indicator', async () => {
renderRoute('/ops/model');
await waitFor(() => expect(screen.getByText('Model Performance')).toBeInTheDocument());
await userEvent.click(screen.getByText('Model Validation'));
// The gate-status endpoint returns passed: false
await waitFor(() => {
expect(screen.getByText(/Live Trading Gate: FAIL/)).toBeInTheDocument();
});
}, 10000);
});
describe('Agents page', () => {
it('renders agent list in sidebar', async () => {
renderRoute('/agents');
await waitFor(() => {
expect(screen.getByText('Document Extractor')).toBeInTheDocument();
expect(screen.getByText('Event Classifier')).toBeInTheDocument();
});
});
it('renders variant list when an agent is selected', async () => {
renderRoute('/agents');
await waitFor(() => expect(screen.getByText('Document Extractor')).toBeInTheDocument());
await userEvent.click(screen.getByText('Document Extractor'));
await waitFor(() => {
expect(screen.getByText('GPT-4o Variant')).toBeInTheDocument();
expect(screen.getByText('Mistral Variant')).toBeInTheDocument();
});
});
it('shows comparison view when multiple variants are checked', async () => {
renderRoute('/agents');
await waitFor(() => expect(screen.getByText('Document Extractor')).toBeInTheDocument());
await userEvent.click(screen.getByText('Document Extractor'));
await waitFor(() => expect(screen.getByText('GPT-4o Variant')).toBeInTheDocument());
// Select both variant checkboxes
const checkboxes = screen.getAllByRole('checkbox');
await userEvent.click(checkboxes[0]);
await userEvent.click(checkboxes[1]);
await waitFor(() => {
expect(screen.getByText(/Variant Comparison/)).toBeInTheDocument();
});
});
});