fix(backtest): keep run history available while metrics load (RP12)

This commit is contained in:
Boki 2026-10-27 14:14:30 -04:00
parent 32f40ee753
commit a050c71012
4 changed files with 312 additions and 53 deletions

View file

@ -456,7 +456,7 @@ export async function fixture(browser: Browser, native = false) {
const response = await routes.fetch(request);
const delay = responseDelay;
if (delay?.path === pathname) {
responseDelay = undefined; // Only the selected read, not run-list metric reads.
responseDelay = undefined; // Delay only the next matching read.
delay.captured.resolve();
await delay.release.promise;
delay.delivered.resolve();

View file

@ -1893,6 +1893,29 @@ test('browser_reopen_and_switch', async () => {
await visible(f.page, secondId);
expect(f.page.url()).toBe(secondUrl);
expect(await f.page.getByText(firstId, { exact: true }).count()).toBe(0);
// Optional history metrics must not hide saved runs while one result is delayed.
const beforeHistorySelection = (
await f.pool.query('SELECT id, status FROM runs WHERE backtest_id=$1 ORDER BY id', [
definitionId,
])
).rows;
delayed = f.delayResponse(`/api/v2/runs/${firstId}/results`);
await f.page.getByRole('button', { name: 'Runs', exact: true }).click();
await delayed.captured.wait('delayed history metrics');
await visible(f.page, /^#1$/);
await visible(f.page, /^#2\s*Canonical$/);
await f.page.getByText(/^#2\s*Canonical$/).click();
await visible(f.page, 'Completed');
expect(f.page.url()).toBe(secondUrl);
delayed.release.resolve();
await delayed.delivered.wait('history metrics released after selection');
expect(
(
await f.pool.query('SELECT id, status FROM runs WHERE backtest_id=$1 ORDER BY id', [
definitionId,
])
).rows
).toEqual(beforeHistorySelection);
// A real missing row, not an invented empty result.
await f.page.goto(`${f.origin}/backtests/${definitionId}/run/${randomUUID()}`);
await visible(f.page, 'Failed to get run: Not Found');