feat(research): inspect scoped stored market data (RP01)

This commit is contained in:
Boki 2026-10-27 00:25:19 -04:00
parent b4ac6460ef
commit 5bfaf37d08
12 changed files with 1592 additions and 3 deletions

View file

@ -2341,6 +2341,133 @@ test('browser_catalog_version_parameters_clone_and_saved_draft', async () => {
}
});
test('stored_source_inspection_browser_keeps_utc_scope_and_research_state_unchanged', async () => {
const f = await fixture();
try {
await f.login();
const { id, dataset } = await createCanonicalInBrowser(f, 'Stored source inspection');
const rows = dataset.bars.map((bar, index) => ({
eodSearchCode: 'X0.US',
symbol: 'X0',
exchange: 'US',
timestamp: bar.intervalStart / 1000,
open: bar.open,
high: bar.high,
low: bar.low,
close: bar.close,
volume: index === 0 ? -1 : bar.volume,
}));
f.setStoredEodBars('eodIntraday1M', rows);
const first = Math.min(...rows.map(row => row.timestamp)) * 1000;
const last = Math.max(...rows.map(row => row.timestamp)) * 1000;
const coverageRequests: URL[] = [];
// Mongo aggregation has separate real-server coverage. This response fixture
// drives the browser picker; the following inspection uses the real HTTP API.
await f.page.route(/\/api\/v2\/datasets\/stored-eod\/coverage(?:\?.*)?$/, route => {
coverageRequests.push(new URL(route.request().url()));
return route.fulfill({
json: {
version: 'stored-eod-coverage/v1',
observedAt: first,
query: { instrumentId: 'X0.US', interval: '1m' },
series: [
{
instrumentId: 'X0.US',
interval: '1m',
rowCount: rows.length,
firstTimestamp: first,
lastTimestamp: last,
invalidTimestampRows: 0,
},
],
},
});
});
const template = await f.request(`/api/v2/backtests/${id}`);
const templateWrites: string[] = [];
f.page.on('request', request => {
if (
request.method() === 'PUT' &&
new URL(request.url()).pathname === `/api/v2/backtests/${id}`
) {
templateWrites.push(request.url());
}
});
const counts = async () =>
(
await f.pool.query(`SELECT
(SELECT count(*)::int FROM backtest_datasets) AS datasets,
(SELECT count(*)::int FROM runs) AS runs,
(SELECT count(*)::int FROM backtest_dispatch) AS dispatch`)
).rows[0];
const before = await counts();
await f.page.getByRole('button', { name: 'Settings', exact: true }).click();
await f.page.getByText('Prepare dataset from source export', { exact: true }).click();
await f.page.getByLabel('Dataset input', { exact: true }).selectOption('stored-eod');
const inspector = f.page.getByRole('region', { name: 'Stored source inspection', exact: true });
await inspector.waitFor();
expect(coverageRequests).toHaveLength(0);
await inspector.getByLabel('Inspect instrument', { exact: true }).fill('X0.US');
await inspector.getByLabel('Inspect timeframe', { exact: true }).selectOption('1m');
await inspector.getByLabel('Inspect instrument', { exact: true }).press('Enter');
expect(coverageRequests).toHaveLength(0);
await inspector.getByRole('button', { name: 'Load selected coverage', exact: true }).click();
await inspector.getByRole('button', { name: 'Use coverage dates', exact: true }).waitFor();
expect(coverageRequests).toHaveLength(1);
expect(Object.fromEntries(coverageRequests[0]!.searchParams)).toEqual({
instrumentId: 'X0.US',
interval: '1m',
});
expect(await inspector.getByLabel('Inspect start UTC', { exact: true }).inputValue()).toBe('');
expect(await inspector.getByLabel('Inspect end UTC', { exact: true }).inputValue()).toBe('');
await inspector.getByRole('button', { name: 'Use coverage dates', exact: true }).click();
expect(await inspector.getByLabel('Inspect instrument', { exact: true }).inputValue()).toBe(
'X0.US'
);
expect(await inspector.getByLabel('Inspect timeframe', { exact: true }).inputValue()).toBe(
'1m'
);
const inspecting = f.page.waitForResponse(response =>
response.url().endsWith('/api/v2/datasets/stored-eod/inspect')
);
await inspector.getByRole('button', { name: 'Inspect source window', exact: true }).click();
const response = await inspecting;
expect(response.status()).toBe(200);
expect(response.request().postDataJSON()).toEqual({
instrumentId: 'X0.US',
interval: '1m',
start: first,
end: last + 60000,
});
const inspected = await response.json();
expect(inspected.invalidRows).toBe(1);
expect(inspected.rowCount).toBe(rows.length);
await inspector.getByText('Invalid volume: 1 rows', { exact: true }).waitFor();
await visible(f.page, /No rows were changed or excluded/);
expect(
await f.page.getByRole('button', { name: 'Retain dataset', exact: true }).isDisabled()
).toBe(true);
expect(await f.page.getByLabel('Canonical dataset', { exact: true }).inputValue()).toBe(
dataset.manifest.hash
);
expect(await counts()).toEqual(before);
expect(await f.request(`/api/v2/backtests/${id}`)).toEqual(template);
expect(templateWrites).toEqual([]);
expect(f.storedSourceReads).toEqual([
{
collection: 'eodIntraday1M',
filter: {
eodSearchCode: 'X0.US',
timestamp: { $gte: first / 1000, $lt: (last + 60000) / 1000 },
},
},
]);
expect(f.unexpectedNetwork).toEqual([]);
} finally {
await f.close();
}
});
test('research_project_to_finding_browser_with_canonical_strategy_setup_run_and_reopen', async () => {
const f = await fixture(true);
f.page.on('dialog', dialog => void dialog.accept());