fix(research): preserve verified hypothesis links after partial lookup failure (RP11)
This commit is contained in:
parent
f4cee5affa
commit
32f40ee753
3 changed files with 136 additions and 17 deletions
|
|
@ -3456,12 +3456,35 @@ 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.');
|
||||
// Move the cited hypothesis forward so the exact link requires history resolution.
|
||||
await f.request(`/api/v2/hypotheses/${hypothesis.id}/revisions`, 'POST', {
|
||||
expectedRevision: 1,
|
||||
title: 'Revised AI trend hypothesis',
|
||||
proposition: 'A revised hypothesis, still not validated alpha.',
|
||||
validationCriteria: 'Out-of-sample evidence required.',
|
||||
contentOrigin: 'ai',
|
||||
});
|
||||
const { hypothesis: unrelatedHypothesis } = await f.request(
|
||||
`/api/v2/research-projects/${project.id}/hypotheses`,
|
||||
'POST',
|
||||
{ title: 'Unrelated hypothesis', proposition: 'Separate future investigation.' }
|
||||
);
|
||||
const unrelatedHistoryPath = `**/api/v2/hypotheses/${unrelatedHypothesis.id}/revisions`;
|
||||
await f.page.route(unrelatedHistoryPath, route =>
|
||||
route.fulfill({ status: 503, json: { error: 'Unrelated history unavailable' } })
|
||||
);
|
||||
const unrelatedHistoryFailure = f.page.waitForResponse(response =>
|
||||
response.url().endsWith(`/hypotheses/${unrelatedHypothesis.id}/revisions`)
|
||||
);
|
||||
await f.page.reload();
|
||||
expect((await unrelatedHistoryFailure).status()).toBe(503);
|
||||
await visible(f.page, 'Costs and losses require further validation.');
|
||||
await f.page.getByRole('link', { name: 'Open exact hypothesis revision', exact: true }).click();
|
||||
await f.page.waitForURL(
|
||||
`${f.origin}/research/${project.id}?hypothesis=${hypothesis.id}&revision=${hypothesis.latestRevision.id}`
|
||||
);
|
||||
await f.page.unroute(unrelatedHistoryPath);
|
||||
await visible(f.page, 'A hypothesis, not validated alpha.');
|
||||
await visible(f.page, /AI-authored \(declared\).*Unvalidated narrative/);
|
||||
await f.page.getByRole('button', { name: 'Archive project', exact: true }).click();
|
||||
await visible(f.page, 'Archived project: research entries are read-only.');
|
||||
|
|
|
|||
|
|
@ -627,6 +627,105 @@ describe('research workspace', () => {
|
|||
[...host.querySelectorAll('button')].some(item => item.textContent === 'Edit latest revision')
|
||||
).toBe(false);
|
||||
});
|
||||
for (const failureFirst of [false, true]) {
|
||||
test(`exact hypothesis link survives unrelated history failure (${failureFirst ? 'failure first' : 'match first'})`, async () => {
|
||||
const original = hypothesis().latestRevision;
|
||||
const linked = hypothesis('h1', {
|
||||
latestRevision: { ...original, id: 'h1-r2', ordinal: 2 },
|
||||
});
|
||||
const finding = artifact('a1', { kind: 'finding', hypothesisRevisionId: original.id });
|
||||
await mount('/research/p1?artifact=a1');
|
||||
await flush(() => replyProject(project(), [linked, hypothesis('h2')], [finding]));
|
||||
await flush(() => replyArtifact(finding));
|
||||
const match = () =>
|
||||
reply(request('hypotheses/h1/revisions'), {
|
||||
revisions: [original, linked.latestRevision],
|
||||
});
|
||||
const failure = () =>
|
||||
reply(request('hypotheses/h2/revisions'), { error: 'Temporary history failure' }, 503);
|
||||
await flush(failureFirst ? failure : match);
|
||||
await flush(failureFirst ? match : failure);
|
||||
expect(
|
||||
host.querySelector('a[href="/research/p1?hypothesis=h1&revision=h1-r1"]')
|
||||
).not.toBeNull();
|
||||
expect(host.textContent).not.toContain('Could not resolve the linked hypothesis history');
|
||||
expect(host.textContent).not.toContain('unavailable in the loaded project history');
|
||||
});
|
||||
}
|
||||
test('incomplete hypothesis lookup remains retryable through project refresh', async () => {
|
||||
const original = hypothesis().latestRevision;
|
||||
const linked = hypothesis('h1', {
|
||||
latestRevision: { ...original, id: 'h1-r2', ordinal: 2 },
|
||||
});
|
||||
const unrelated = hypothesis('h2');
|
||||
const finding = artifact('a1', { kind: 'finding', hypothesisRevisionId: original.id });
|
||||
await mount('/research/p1?artifact=a1');
|
||||
await flush(() => replyProject(project(), [linked, unrelated], [finding]));
|
||||
await flush(() => replyArtifact(finding));
|
||||
await flush(() => {
|
||||
reply(request('hypotheses/h1/revisions'), { error: 'Temporary history failure' }, 503);
|
||||
reply(request('hypotheses/h2/revisions'), { revisions: [unrelated.latestRevision] });
|
||||
});
|
||||
expect(host.textContent).toContain('Could not resolve the linked hypothesis history');
|
||||
expect(host.textContent).not.toContain('unavailable in the loaded project history');
|
||||
expect(host.querySelector('a[href*="?hypothesis=h1&revision=h1-r1"]')).toBeNull();
|
||||
await flush(() => click('Refresh project'));
|
||||
await flush(() => replyProject(project(), [linked, unrelated], [finding]));
|
||||
await flush(() => {
|
||||
reply(request('hypotheses/h1/revisions'), { revisions: [original, linked.latestRevision] });
|
||||
reply(request('hypotheses/h2/revisions'), { revisions: [unrelated.latestRevision] });
|
||||
});
|
||||
expect(host.textContent).not.toContain('Could not resolve the linked hypothesis history');
|
||||
expect(
|
||||
host.querySelector('a[href="/research/p1?hypothesis=h1&revision=h1-r1"]')
|
||||
).not.toBeNull();
|
||||
});
|
||||
test('fully read hypothesis history distinguishes absence and rejects a foreign revision owner', async () => {
|
||||
const finding = artifact('a1', { kind: 'finding', hypothesisRevisionId: 'missing-r1' });
|
||||
await mount('/research/p1?artifact=a1');
|
||||
await flush(() => replyProject(project(), [hypothesis()], [finding]));
|
||||
await flush(() => replyArtifact(finding));
|
||||
await flush(() =>
|
||||
reply(request('hypotheses/h1/revisions'), {
|
||||
revisions: [
|
||||
hypothesis().latestRevision,
|
||||
{ ...hypothesis('h2').latestRevision, id: 'missing-r1' },
|
||||
],
|
||||
})
|
||||
);
|
||||
expect(host.textContent).toContain('unavailable in the loaded project history');
|
||||
expect(host.textContent).not.toContain('Could not resolve the linked hypothesis history');
|
||||
expect(host.querySelector('a[href*="?hypothesis="]')).toBeNull();
|
||||
});
|
||||
for (const destination of ['finding', 'project'] as const) {
|
||||
test(`late hypothesis resolution cannot attach to a different ${destination}`, async () => {
|
||||
const original = hypothesis().latestRevision;
|
||||
const linked = hypothesis('h1', {
|
||||
latestRevision: { ...original, id: 'h1-r2', ordinal: 2 },
|
||||
});
|
||||
const finding = artifact('a1', { kind: 'finding', hypothesisRevisionId: original.id });
|
||||
await mount('/research/p1?artifact=a1');
|
||||
await flush(() => replyProject(project(), [linked, hypothesis('h2')], [finding]));
|
||||
await flush(() => replyArtifact(finding));
|
||||
const previousMatch = request('hypotheses/h1/revisions');
|
||||
const previousFailure = request('hypotheses/h2/revisions');
|
||||
const nextProjectId = destination === 'project' ? 'p2' : 'p1';
|
||||
const next = artifact('a2', { projectId: nextProjectId, kind: 'finding' });
|
||||
await flush(() => navigate(`/research/${nextProjectId}?artifact=a2`));
|
||||
if (destination === 'project') {
|
||||
await flush(() => replyProject(project('p2'), [], [next]));
|
||||
}
|
||||
await flush(() => replyArtifact(next));
|
||||
await flush(() => {
|
||||
reply(previousMatch, { revisions: [original, linked.latestRevision] });
|
||||
reply(previousFailure, { error: 'Temporary history failure' }, 503);
|
||||
});
|
||||
expect(location).toBe(`/research/${nextProjectId}?artifact=a2`);
|
||||
expect(host.querySelector('a[href*="?hypothesis="]')).toBeNull();
|
||||
expect(host.textContent).not.toContain('Linked hypothesis revision:');
|
||||
expect(host.textContent).not.toContain('Could not resolve the linked hypothesis history');
|
||||
});
|
||||
}
|
||||
test('late entry read and late revision success cannot overwrite a newly selected entry', async () => {
|
||||
await mount('/research/p1?hypothesis=h1');
|
||||
await flush(() => replyProject());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue