fix(research): reuse older and known-hash datasets (RP05)

This commit is contained in:
Boki 2026-10-27 09:31:30 -04:00
parent 5319bd1bb2
commit 6d549542a9
5 changed files with 680 additions and 51 deletions

View file

@ -2351,6 +2351,128 @@ test('browser_catalog_version_parameters_clone_and_saved_draft', async () => {
}
});
test('canonical_dataset_browser_reuses_older_pages_and_known_hash_without_new_runs', async () => {
const f = await fixture();
try {
await f.login();
const { id, dataset } = await createCanonicalInBrowser(f, 'Retained dataset reuse');
const { calendars, series, executionSeries, bounds, universe, corporateActions } =
dataset.manifest;
const snapshots = [];
for (let index = 0; index < 52; index++) {
const snapshot = createDatasetV2({
metadata: {
calendars,
series: series.map(value => ({
...value,
source: { ...value.source, revision: `catalog-browser-fixture-${index}` },
})),
executionSeries,
bounds,
universe,
corporateActions,
},
bars: dataset.bars.map(bar => ({
seriesId: bar.seriesId,
timestamp: bar.intervalStart,
availableAt: bar.availableAt,
sourceSequence: bar.sourceSequence,
open: bar.open,
high: bar.high,
low: bar.low,
close: bar.close,
volume: bar.volume,
})),
});
// Set fixture ordering on initial insertion; retained evidence is immutable.
await f.pool.query(
'INSERT INTO backtest_datasets(hash,payload,created_at) VALUES($1,$2::jsonb,$3)',
[
snapshot.manifest.hash,
JSON.stringify(snapshot),
new Date(Date.parse('2020-01-01T00:00:00Z') + index * 60_000),
]
);
await retainResearchDataset(f.pool, snapshot);
snapshots.push(snapshot);
}
const older = snapshots[0]!,
known = snapshots[1]!;
const before = await f.request(`/api/v2/backtests/${id}`);
const listResponses: string[] = [];
f.page.on('request', request => {
const url = new URL(request.url());
if (url.pathname === '/api/v2/datasets/canonical') {
listResponses.push(url.search);
}
});
await f.page.getByRole('button', { name: 'Settings', exact: true }).click();
const choice = f.page.getByLabel('Canonical dataset', { exact: true });
await f.page
.getByRole('button', { name: 'Load more canonical datasets', exact: true })
.waitFor();
expect(await choice.locator(`option[value="${older.manifest.hash}"]`).count()).toBe(0);
expect(await choice.locator(`option[value="${known.manifest.hash}"]`).count()).toBe(0);
await f.page.getByLabel('Retained dataset hash', { exact: true }).fill(known.manifest.hash);
const lookup = f.page.waitForResponse(response =>
response.url().endsWith(`/api/v2/datasets/canonical/${known.manifest.hash}`)
);
await f.page.getByRole('button', { name: 'Use dataset hash', exact: true }).click();
expect((await lookup).status()).toBe(200);
await until(
() => choice.inputValue().then(value => value === known.manifest.hash),
'known hash selection'
);
expect(await f.request(`/api/v2/backtests/${id}`)).toEqual(before);
await f.page.getByRole('button', { name: 'Load more canonical datasets', exact: true }).click();
await choice.locator(`option[value="${older.manifest.hash}"]`).waitFor({ state: 'attached' });
expect(listResponses).toContain('?limit=50&offset=50');
expect(await choice.inputValue()).toBe(known.manifest.hash);
const values = await choice
.locator('option')
.evaluateAll(options => options.map(option => (option as HTMLOptionElement).value));
expect(new Set(values).size).toBe(values.length);
await choice.selectOption(older.manifest.hash);
await f.page.getByRole('button', { name: 'Validate parameters', exact: true }).click();
await visible(f.page, /Parameters validated/);
await until(
() => f.page.getByRole('button', { name: 'Save canonical setup', exact: true }).isEnabled(),
'older dataset verified and ready to save'
);
const saving = f.page.waitForResponse(
response =>
response.request().method() === 'PUT' && response.url().endsWith(`/api/v2/backtests/${id}`)
);
await f.page.getByRole('button', { name: 'Save canonical setup', exact: true }).click();
const saved = await saving;
expect(saved.status()).toBe(200);
expect(saved.request().postDataJSON()).toMatchObject({
config: { datasetHash: older.manifest.hash },
startDate: new Date(bounds.tradeStart).toISOString(),
endDate: new Date(bounds.tradeEnd).toISOString(),
});
await f.page.reload();
await f.page.getByRole('button', { name: 'Settings', exact: true }).click();
await until(
() => choice.inputValue().then(value => value === older.manifest.hash),
'saved older hash reopens outside first catalog page'
);
await f.page.getByRole('button', { name: 'Validate parameters', exact: true }).click();
await visible(f.page, /Parameters validated/);
await until(
() => f.page.getByRole('button', { name: 'Save canonical setup', exact: true }).isEnabled(),
'reopened retained metadata verified'
);
expect((await f.pool.query('SELECT count(*)::int AS n FROM runs')).rows[0].n).toBe(0);
expect((await f.pool.query('SELECT count(*)::int AS n FROM backtest_dispatch')).rows[0].n).toBe(
0
);
expect(f.unexpectedNetwork).toEqual([]);
} finally {
await f.close();
}
});
test('declared_session_source_browser_captures_two_windows_and_retains_without_requery', async () => {
const f = await fixture();
try {