fix(research): accept eligible isolated candidate reproduction previews (RP13)

This commit is contained in:
Boki 2026-10-27 14:57:09 -04:00
parent 8807d9e504
commit 773314d29e
6 changed files with 251 additions and 6 deletions

View file

@ -3747,6 +3747,86 @@ test('isolated_candidate_publication_research_validation_and_reviewed_paper_hist
await f.page.reload();
await visible(f.page, result.request.datasetHash);
// Reproduction of an isolated candidate does not require inventing a human review.
const candidateReviewCount = async () =>
(
await f.pool.query(
'SELECT count(*)::int AS count FROM strategy_review_events WHERE version_id=$1',
[version.id]
)
).rows[0].count;
expect(await candidateReviewCount()).toBe(0);
const previewingReproduction = f.page.waitForResponse(response =>
response.url().endsWith(`/runs/${runId}/reproduction`)
);
await f.page.getByRole('button', { name: 'Reproduce original', exact: true }).click();
const reproductionPreview = await previewingReproduction;
expect(reproductionPreview.status()).toBe(200);
expect(await reproductionPreview.json()).toMatchObject({
originalRunId: runId,
available: true,
currentReviewId: null,
request: { strategy: { origin: 'candidate', reviewId: null } },
});
const reproductionDialog = f.page.getByRole('dialog', {
name: 'Reproduce original',
exact: true,
});
const originalInputs = reproductionDialog.getByRole('region', {
name: 'Original retained inputs',
exact: true,
});
await originalInputs.waitFor({ state: 'visible' });
expect(await originalInputs.textContent()).toContain(result.request.datasetHash);
expect(await originalInputs.textContent()).toContain(version.id);
const reproducing = f.page.waitForResponse(
response =>
response.request().method() === 'POST' &&
response.url().endsWith(`/runs/${runId}/reproduce`)
);
await reproductionDialog
.getByRole('button', { name: 'Confirm reproduction', exact: true })
.click();
const reproducedResponse = await reproducing;
expect(reproducedResponse.status()).toBe(202);
expect(reproducedResponse.request().postDataJSON()).toEqual({});
const receipt = reproducedResponse.request().headers()['idempotency-key']!;
expect(receipt).toBeTruthy();
const reproducedRun = await reproducedResponse.json();
expect(reproducedRun.originalRunId).toBe(runId);
expect(reproducedRun.id).not.toBe(runId);
await f.page.waitForURL(`${f.origin}/backtests/${draft.id}/run/${reproducedRun.id}`);
const duplicate = await f.request(
`/api/v2/runs/${runId}/reproduce`,
'POST',
{},
{
'Idempotency-Key': receipt,
}
);
expect(duplicate.id).toBe(reproducedRun.id);
await visible(f.page, 'Economic results match the original.');
const reproducedResult = (await f.request(
`/api/v2/runs/${reproducedRun.id}/results`
)) as CanonicalRunResult;
expect(reproducedResult.strategyExecution).toBe('typescript-isolated-candidate/v1');
expect(reproducedResult.request.strategy).toEqual(result.request.strategy);
expect(reproducedResult.request.build).toEqual(result.request.build);
expect(reproducedResult.request.datasetHash).toBe(result.request.datasetHash);
expect(reproducedResult.financial.projection.valuation).toEqual(
result.financial.projection.valuation
);
expect(reproducedResult.analytics).toEqual(result.analytics);
expect(await f.request(`/api/v2/runs/${runId}/results`)).toEqual(result);
expect(await candidateReviewCount()).toBe(0);
expect(
(await f.pool.query('SELECT id FROM runs WHERE original_run_id=$1', [runId])).rowCount
).toBe(1);
await f.page.reload();
await visible(f.page, 'Economic results match the original.');
await f.page.getByRole('link', { name: 'Open original run', exact: true }).click();
await f.page.waitForURL(`${f.origin}/backtests/${draft.id}/run/${runId}`);
// Real immutable validation and cost evidence prepare the human promotion screen.
const candidate = { versionId: version.id, parameters: { fastPeriod: 2, slowPeriod: 3 } };
const validationInput = {