fix(research): verify single-run finding acknowledgements (RP24)

This commit is contained in:
Boki 2026-10-27 22:14:27 -04:00
parent 2da899daf2
commit f80ae2f3f3
4 changed files with 233 additions and 27 deletions

View file

@ -285,6 +285,7 @@ export async function fixture(browser: Browser, native = false) {
'30-paper-deployments.sql',
'31-research-agent-project-links.sql',
'32-candidate-parameter-defaults.sql',
'33-candidate-decimal-normalization.sql',
]) {
await pool.query(
readFileSync(new URL(`../../database/postgres/init/${name}`, import.meta.url), 'utf8')

View file

@ -2136,6 +2136,102 @@ test('canonical_native_smoke', async () => {
}
});
test('single_run_finding_acknowledgement_blocks_duplicates_and_reopens_committed_evidence_browser', async () => {
const f = await fixture(true);
try {
await f.login();
const { id } = await createCanonicalInBrowser(f, 'Finding acknowledgement oracle', true);
const runId = f.page.url().split('/').at(-1)!;
f.dispatcher.start();
await visible(f.page, 'Canonical research result');
const native = (await f.request(`/api/v2/runs/${runId}/results`)) as CanonicalRunResult;
const { project } = await f.request('/api/v2/research-projects', 'POST', {
title: 'Finding acknowledgement recovery',
});
const counts = async () =>
(
await f.pool.query(`SELECT
(SELECT count(*)::int FROM runs) AS runs,
(SELECT count(*)::int FROM backtest_dispatch) AS dispatch,
(SELECT count(*)::int FROM analysis_artifacts) AS artifacts`)
).rows[0];
expect(await counts()).toEqual({ runs: 1, dispatch: 1, artifacts: 0 });
await f.page.getByRole('button', { name: 'Save finding', exact: true }).click();
const dialog = f.page.getByRole('dialog', { name: 'Save finding', exact: true });
await dialog.getByLabel('Finding project', { exact: true }).selectOption(project.id);
await dialog.getByLabel('Finding title', { exact: true }).fill('Keep exact native evidence');
await dialog
.getByLabel('Finding body', { exact: true })
.fill('Retain this draft on uncertainty.');
const endpoint = `**/api/v2/research-projects/${project.id}/analysis-artifacts`;
let posts = 0;
let committed: ResearchArtifact | undefined;
await f.page.route(endpoint, async route => {
posts++;
// The real write commits. Only its browser acknowledgement loses the evidence.
const response = await route.fetch();
expect(response.status()).toBe(201);
const payload = (await response.json()) as { artifact: ResearchArtifact };
committed = structuredClone(payload.artifact);
payload.artifact.latestRevision.evidence = [];
await route.fulfill({ response, json: payload });
});
await dialog.getByRole('button', { name: 'Save finding', exact: true }).click();
await visible(f.page, 'The saved finding response could not be verified.');
await visible(f.page, /Check saved records before creating another/);
expect(await dialog.getByLabel('Finding title', { exact: true }).inputValue()).toBe(
'Keep exact native evidence'
);
expect(await dialog.getByLabel('Finding body', { exact: true }).inputValue()).toBe(
'Retain this draft on uncertainty.'
);
expect(await dialog.getByLabel('Finding title', { exact: true }).isDisabled()).toBe(true);
expect(
await dialog.getByRole('button', { name: 'Save finding', exact: true }).isDisabled()
).toBe(true);
expect(
await dialog.getByRole('link', { name: 'Open saved finding', exact: true }).count()
).toBe(0);
expect(posts).toBe(1);
expect(await counts()).toEqual({ runs: 1, dispatch: 1, artifacts: 1 });
if (!committed) {
throw new Error('Expected the original committed finding');
}
expect(committed.latestRevision.evidence).toHaveLength(1);
expect(committed.latestRevision.evidence[0]).toMatchObject({
runId,
strategyVersionId: native.request.strategy.versionId,
metricPath: 'analytics.metrics.totalReturn',
value: native.analytics.metrics.totalReturn,
});
await f.page.unroute(endpoint);
f.page.on('dialog', event => void event.accept());
await f.page.goto(`${f.origin}/research/${project.id}?artifact=${committed.id}`);
await visible(f.page, 'Keep exact native evidence');
const measurements = f.page.getByRole('region', {
name: 'Referenced measurements',
exact: true,
});
await measurements.waitFor();
expect(await measurements.textContent()).toContain(
`Raw value: ${native.analytics.metrics.totalReturn}`
);
expect(
await measurements
.getByRole('link', { name: 'Open cited run', exact: true })
.getAttribute('href')
).toBe(`/backtests/${id}/run/${runId}`);
await f.page.reload();
await measurements.waitFor();
expect(await counts()).toEqual({ runs: 1, dispatch: 1, artifacts: 1 });
expect(await f.request(`/api/v2/runs/${runId}/results`)).toEqual(native);
expect(posts).toBe(1);
expect(f.unexpectedNetwork).toEqual([]);
} finally {
await f.close();
}
});
test('browser_legacy_frozen_history_reopens_without_reactivating_retired_execution', async () => {
const f = await fixture();
try {