fix(research): verify project updates and archive outcomes (RP32)
This commit is contained in:
parent
233178d4ad
commit
f84fa82bba
5 changed files with 670 additions and 46 deletions
|
|
@ -2189,6 +2189,219 @@ test('canonical_native_smoke', async () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('project_and_archive_acknowledgements_preserve_drafts_until_committed_state_is_reloaded_browser', async () => {
|
||||
const f = await fixture(true);
|
||||
try {
|
||||
await f.login();
|
||||
await createCanonicalInBrowser(f, 'Project archive 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: 'Project archive custody',
|
||||
})) as { project: ResearchProject };
|
||||
const { artifact } = (await f.request(
|
||||
`/api/v2/research-projects/${project.id}/analysis-artifacts`,
|
||||
'POST',
|
||||
{
|
||||
kind: 'finding',
|
||||
title: 'Retained finding',
|
||||
body: 'Original interpretation.',
|
||||
contentOrigin: 'human',
|
||||
evidence: [
|
||||
{
|
||||
runId,
|
||||
strategyVersionId: native.request.strategy.versionId,
|
||||
metricsVersion: 'canonical-analytics/v1',
|
||||
metricPath: 'analytics.metrics.totalReturn',
|
||||
},
|
||||
],
|
||||
}
|
||||
)) as { artifact: ResearchArtifact };
|
||||
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,
|
||||
(SELECT count(*)::int FROM analysis_artifact_revisions) AS revisions`)
|
||||
).rows[0];
|
||||
const expectedCounts = { runs: 1, dispatch: 1, artifacts: 1, revisions: 1 };
|
||||
expect(await counts()).toEqual(expectedCounts);
|
||||
f.page.on('dialog', event => void event.accept());
|
||||
await f.page.goto(`${f.origin}/research/${project.id}`);
|
||||
await f.page.getByRole('button', { name: 'Edit project', exact: true }).click();
|
||||
const title = ' Revised project custody ',
|
||||
description = ' Retain the project metadata draft.\n';
|
||||
await f.page.getByLabel('Project title', { exact: true }).fill(title);
|
||||
await f.page.getByLabel('Project description', { exact: true }).fill(description);
|
||||
const projectEndpoint = `**/api/v2/research-projects/${project.id}`;
|
||||
let metadataPatches = 0;
|
||||
let committedMetadata: ResearchProject | undefined;
|
||||
await f.page.route(projectEndpoint, async route => {
|
||||
if (route.request().method() !== 'PATCH') {
|
||||
await route.continue();
|
||||
return;
|
||||
}
|
||||
metadataPatches++;
|
||||
const response = await route.fetch();
|
||||
expect(response.status()).toBe(200);
|
||||
const payload = (await response.json()) as { project: ResearchProject };
|
||||
committedMetadata = structuredClone(payload.project);
|
||||
payload.project.revision = 1;
|
||||
await route.fulfill({ response, json: payload });
|
||||
});
|
||||
await f.page.getByRole('button', { name: 'Save project', exact: true }).click();
|
||||
await visible(f.page, 'The saved project update could not be verified.');
|
||||
expect(await f.page.getByLabel('Project title', { exact: true }).inputValue()).toBe(title);
|
||||
expect(await f.page.getByLabel('Project description', { exact: true }).inputValue()).toBe(
|
||||
description
|
||||
);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Save project', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Archive project', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
await f.page.getByRole('button', { name: 'Refresh project', exact: true }).click();
|
||||
await visible(f.page, /Project revision 2/);
|
||||
expect(await f.page.getByLabel('Project title', { exact: true }).inputValue()).toBe(title);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Archive project', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
expect(metadataPatches).toBe(1);
|
||||
if (!committedMetadata) {
|
||||
throw new Error('Expected the ordinary metadata update to commit');
|
||||
}
|
||||
expect(committedMetadata.title).toBe(title.trim());
|
||||
await f.page.unroute(projectEndpoint);
|
||||
await f.page
|
||||
.getByRole('button', { name: 'Discard edits and reload project', exact: true })
|
||||
.click();
|
||||
await f.page.getByRole('button', { name: 'Edit project', exact: true }).waitFor();
|
||||
expect((await f.request(`/api/v2/research-projects/${project.id}`)).project).toEqual(
|
||||
committedMetadata
|
||||
);
|
||||
|
||||
await f.page.goto(`${f.origin}/research/${project.id}?artifact=${artifact.id}`);
|
||||
await f.page.getByRole('button', { name: 'Edit latest revision', exact: true }).click();
|
||||
const revisionBody = 'Preserve this unsubmitted interpretation.';
|
||||
await f.page.getByLabel('Revision body', { exact: true }).fill(revisionBody);
|
||||
const entryEndpoint = `**/api/v2/analysis-artifacts/${artifact.id}`;
|
||||
let entryPatches = 0;
|
||||
let committedArchive: ResearchArtifact | undefined;
|
||||
await f.page.route(entryEndpoint, async route => {
|
||||
if (route.request().method() !== 'PATCH') {
|
||||
await route.continue();
|
||||
return;
|
||||
}
|
||||
entryPatches++;
|
||||
const response = await route.fetch();
|
||||
expect(response.status()).toBe(200);
|
||||
const payload = (await response.json()) as { artifact: ResearchArtifact };
|
||||
committedArchive = structuredClone(payload.artifact);
|
||||
payload.artifact.archived = false;
|
||||
await route.fulfill({ response, json: payload });
|
||||
});
|
||||
await f.page.getByRole('button', { name: 'Archive entry', exact: true }).click();
|
||||
await visible(f.page, 'The archive response could not be verified.');
|
||||
expect(await f.page.getByLabel('Revision body', { exact: true }).inputValue()).toBe(
|
||||
revisionBody
|
||||
);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Save new revision', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Archive entry', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
expect(entryPatches).toBe(1);
|
||||
if (!committedArchive) {
|
||||
throw new Error('Expected the ordinary archive write to commit');
|
||||
}
|
||||
expect(committedArchive.archived).toBe(true);
|
||||
expect(committedArchive.latestRevision).toEqual(artifact.latestRevision);
|
||||
await f.page.unroute(entryEndpoint);
|
||||
await f.page
|
||||
.getByRole('button', { name: 'Discard draft and reload archive state', exact: true })
|
||||
.click();
|
||||
await f.page.getByRole('button', { name: 'Restore entry', exact: true }).waitFor();
|
||||
expect((await f.request(`/api/v2/analysis-artifacts/${artifact.id}`)).artifact).toEqual(
|
||||
committedArchive
|
||||
);
|
||||
expect(
|
||||
(await f.request(`/api/v2/analysis-artifacts/${artifact.id}/revisions`)).revisions
|
||||
).toEqual([artifact.latestRevision]);
|
||||
await f.page.getByRole('button', { name: 'Restore entry', exact: true }).click();
|
||||
await f.page.getByRole('button', { name: 'Archive entry', exact: true }).waitFor();
|
||||
expect((await f.request(`/api/v2/analysis-artifacts/${artifact.id}`)).artifact.archived).toBe(
|
||||
false
|
||||
);
|
||||
|
||||
await f.page.getByRole('button', { name: 'New note', exact: true }).click();
|
||||
const noteBody = 'Preserve the pending child proposal.';
|
||||
await f.page.getByLabel('Note title', { exact: true }).fill('Pending child draft');
|
||||
await f.page.getByLabel('Note body', { exact: true }).fill(noteBody);
|
||||
let projectArchivePatches = 0;
|
||||
let committedProjectArchive: ResearchProject | undefined;
|
||||
await f.page.route(projectEndpoint, async route => {
|
||||
if (route.request().method() !== 'PATCH') {
|
||||
await route.continue();
|
||||
return;
|
||||
}
|
||||
projectArchivePatches++;
|
||||
const response = await route.fetch();
|
||||
expect(response.status()).toBe(200);
|
||||
const payload = (await response.json()) as { project: ResearchProject };
|
||||
committedProjectArchive = structuredClone(payload.project);
|
||||
payload.project.description = 'Substituted acknowledgement only.';
|
||||
await route.fulfill({ response, json: payload });
|
||||
});
|
||||
await f.page.getByRole('button', { name: 'Archive project', exact: true }).click();
|
||||
await visible(f.page, 'The saved project update could not be verified.');
|
||||
expect(await f.page.getByLabel('Note body', { exact: true }).inputValue()).toBe(noteBody);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Create note', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Archive project', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
await f.page.getByRole('button', { name: 'Refresh project', exact: true }).click();
|
||||
await visible(f.page, /Project revision 3/);
|
||||
expect(await f.page.getByLabel('Note body', { exact: true }).inputValue()).toBe(noteBody);
|
||||
expect(
|
||||
await f.page.getByRole('button', { name: 'Create note', exact: true }).isDisabled()
|
||||
).toBe(true);
|
||||
expect(projectArchivePatches).toBe(1);
|
||||
if (!committedProjectArchive) {
|
||||
throw new Error('Expected the ordinary project archive to commit');
|
||||
}
|
||||
expect(committedProjectArchive.archived).toBe(true);
|
||||
await f.page.unroute(projectEndpoint);
|
||||
await f.page
|
||||
.getByRole('button', { name: 'Discard edits and reload project', exact: true })
|
||||
.click();
|
||||
await f.page.getByRole('button', { name: 'Restore project', exact: true }).waitFor();
|
||||
expect(await f.page.getByLabel('Note body', { exact: true }).count()).toBe(0);
|
||||
expect((await f.request(`/api/v2/research-projects/${project.id}`)).project).toEqual(
|
||||
committedProjectArchive
|
||||
);
|
||||
await f.page.getByRole('button', { name: 'Restore project', exact: true }).click();
|
||||
await visible(f.page, /Project revision 4/);
|
||||
await f.page.getByRole('button', { name: 'New note', exact: true }).waitFor();
|
||||
await f.page.reload();
|
||||
await visible(f.page, /Project revision 4/);
|
||||
expect(await counts()).toEqual(expectedCounts);
|
||||
expect(
|
||||
(await f.request(`/api/v2/analysis-artifacts/${artifact.id}/revisions`)).revisions
|
||||
).toEqual([artifact.latestRevision]);
|
||||
expect(await f.request(`/api/v2/runs/${runId}/results`)).toEqual(native);
|
||||
expect(f.unexpectedNetwork).toEqual([]);
|
||||
} finally {
|
||||
await f.close();
|
||||
}
|
||||
});
|
||||
|
||||
test('creation_acknowledgements_preserve_proposals_and_reopen_committed_records_browser', async () => {
|
||||
const f = await fixture(true);
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue