feat(research): download exact saved revisions (RP26)
This commit is contained in:
parent
6ce3b68b3d
commit
5434950263
7 changed files with 320 additions and 3 deletions
|
|
@ -36,7 +36,9 @@ import type {
|
|||
HistoricalDatasetInputV2,
|
||||
HistoricalDatasetV2,
|
||||
ResearchArtifact,
|
||||
ResearchArtifactRevision,
|
||||
ResearchFindingSource,
|
||||
ResearchHypothesisRevision,
|
||||
} from '@stock-bot/types';
|
||||
import {
|
||||
createDatasetV2,
|
||||
|
|
@ -94,6 +96,55 @@ async function downloadDatasetInBrowser(
|
|||
expect(validateDatasetV2(JSON.parse(readFileSync(path, 'utf8')))).toEqual(expected);
|
||||
}
|
||||
|
||||
async function downloadResearchRevisionInBrowser(
|
||||
f: Awaited<ReturnType<typeof fixture>>,
|
||||
projectId: string,
|
||||
entry: {
|
||||
id: string;
|
||||
kind: 'hypothesis' | 'note' | 'finding';
|
||||
hypothesisRevisionId?: string | null;
|
||||
},
|
||||
revision: ResearchArtifactRevision | ResearchHypothesisRevision
|
||||
) {
|
||||
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_artifact_revisions) AS artifacts,
|
||||
(SELECT count(*)::int FROM research_hypothesis_revisions) AS hypotheses`)
|
||||
).rows[0];
|
||||
const before = await counts();
|
||||
const requests: string[] = [];
|
||||
const record = (request: Request) => {
|
||||
if (new URL(request.url()).pathname.startsWith('/api/')) {
|
||||
requests.push(request.url());
|
||||
}
|
||||
};
|
||||
f.page.on('request', record);
|
||||
try {
|
||||
const downloading = f.page.waitForEvent('download');
|
||||
await f.page.getByRole('button', { name: 'Download saved revision', exact: true }).click();
|
||||
const download = await downloading;
|
||||
expect(download.suggestedFilename()).toBe(`research-${entry.id}-${revision.id}.json`);
|
||||
expect(await download.failure()).toBeNull();
|
||||
const path = await download.path();
|
||||
if (!path) {
|
||||
throw new Error('Expected a downloaded research revision file');
|
||||
}
|
||||
expect(JSON.parse(readFileSync(path, 'utf8'))).toEqual({
|
||||
kind: 'research-revision-export/v1',
|
||||
projectId,
|
||||
entry,
|
||||
revision,
|
||||
});
|
||||
expect(requests).toEqual([]);
|
||||
expect(await counts()).toEqual(before);
|
||||
} finally {
|
||||
f.page.off('request', record);
|
||||
}
|
||||
}
|
||||
|
||||
test('operator_provisions_bounded_agent_views_usage_and_revokes_without_corrupting_accepted_work_browser', async () => {
|
||||
const f = await fixture(true);
|
||||
try {
|
||||
|
|
@ -3725,6 +3776,14 @@ test('research_project_to_finding_browser_with_canonical_strategy_setup_run_and_
|
|||
await f.page.getByRole('button', { name: 'View revision 1', exact: true }).click();
|
||||
await visible(f.page, 'Costs and losses require further validation.');
|
||||
await visible(f.page, 'Immutable history: this revision is read-only.');
|
||||
await downloadResearchRevisionInBrowser(
|
||||
f,
|
||||
project.id,
|
||||
{ id: artifact.id, kind: 'finding', hypothesisRevisionId: hypothesis.latestRevision.id },
|
||||
history.revisions.find(
|
||||
(item: ResearchArtifactRevision) => item.id === artifact.latestRevision.id
|
||||
)!
|
||||
);
|
||||
// Move the cited hypothesis forward so the exact link requires history resolution.
|
||||
await f.request(`/api/v2/hypotheses/${hypothesis.id}/revisions`, 'POST', {
|
||||
expectedRevision: 1,
|
||||
|
|
@ -3755,6 +3814,12 @@ test('research_project_to_finding_browser_with_canonical_strategy_setup_run_and_
|
|||
await f.page.unroute(unrelatedHistoryPath);
|
||||
await visible(f.page, 'A hypothesis, not validated alpha.');
|
||||
await visible(f.page, /AI-authored \(declared\).*Unvalidated narrative/);
|
||||
await downloadResearchRevisionInBrowser(
|
||||
f,
|
||||
project.id,
|
||||
{ id: hypothesis.id, kind: 'hypothesis' },
|
||||
hypothesis.latestRevision
|
||||
);
|
||||
await f.page.getByRole('button', { name: 'Archive project', exact: true }).click();
|
||||
await visible(f.page, 'Archived project: research entries are read-only.');
|
||||
expect(await f.page.getByRole('button', { name: 'New note', exact: true }).count()).toBe(0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue