feat(research): reopen original hypothesis revisions (RP29)

This commit is contained in:
Boki 2026-10-28 00:38:38 -04:00
parent bbcec1c439
commit fa78b6a791
4 changed files with 391 additions and 0 deletions

View file

@ -260,6 +260,81 @@ async function fixture() {
}
describe.skipIf(!url)('AI research workflow through authenticated APIs and Rust', () => {
test('hypothesis reads retain original questions, human revisions and archival without writes', async () => {
const f = await fixture();
const created = await f.client.createHypothesis(f.project.id, f.suggestions().hypothesis);
const original = (await f.research.getHypothesis(created.id)).latestRevision;
const revised = await f.research.reviseHypothesis(
created.id,
{
expectedRevision: original.ordinal,
title: 'Human follow-up question',
proposition: 'A changed proposition is not the original research question.',
validationCriteria: 'Additional validation remains necessary.',
contentOrigin: 'human',
},
'operator'
);
const archived = await f.research.archiveHypothesis(created.id, { archived: true }, 'operator');
const serviceQuestion = await f.research.createHypothesis(
f.project.id,
{ title: 'Service diagnostic', proposition: 'No measured claim.', contentOrigin: 'unknown' },
'service'
);
const totals = async () =>
(
await f.pool.query(`SELECT
(SELECT count(*)::int FROM runs) AS runs,
(SELECT count(*)::int FROM research_experiments) AS experiments,
(SELECT count(*)::int FROM research_hypotheses) AS hypotheses,
(SELECT count(*)::int FROM research_hypothesis_revisions) AS revisions,
(SELECT count(*)::int FROM analysis_artifacts) AS artifacts`)
).rows[0];
const before = await totals();
const requestStart = f.requests.length;
expect(await f.client.hypothesis(created.id)).toEqual(archived);
const history = await f.client.hypothesisRevisions(created.id);
expect(history).toEqual([original, revised.latestRevision]);
expect(history.find(item => item.id === created.latestRevision.id)).toEqual(original);
expect<string>(history[0]!.submittedBy).toBe(f.provisioned.agent.id);
expect(history[0]!.contentOrigin).toBe('ai');
expect(history[1]!.submittedBy).toBe('operator');
expect(history[1]!.contentOrigin).toBe('human');
expect(history.every(item => item.validationState === 'unvalidated')).toBeTrue();
expect(await f.client.hypothesis(serviceQuestion.id)).toEqual(serviceQuestion);
expect(await f.client.hypothesisRevisions(serviceQuestion.id)).toEqual([
serviceQuestion.latestRevision,
]);
const missing = randomUUID();
await expect(f.client.hypothesis(missing)).rejects.toMatchObject({
status: 404,
uncertain: false,
});
await expect(f.client.hypothesisRevisions(missing)).rejects.toMatchObject({
status: 404,
uncertain: false,
});
expect(
f.requests
.slice(requestStart)
.every(
request => request.method === 'GET' && request.key === null && request.body === undefined
)
).toBeTrue();
expect(await totals()).toEqual(before);
await f.agents.update(f.provisioned.agent.id, { expectedRevision: 1, enabled: false });
await expect(f.client.hypothesis(created.id)).rejects.toMatchObject({
status: 401,
uncertain: false,
});
await expect(f.client.hypothesisRevisions(created.id)).rejects.toMatchObject({
status: 401,
uncertain: false,
});
expect(await totals()).toEqual(before);
expect(f.executionErrors).toEqual([]);
});
test('research credentials export known immutable snapshots with exact read-only scope', async () => {
const f = await fixture();
const hash = f.dataset.manifest.hash;
@ -558,6 +633,27 @@ describe.skipIf(!url)('AI research workflow through authenticated APIs and Rust'
// A comparison across candidates has no single aggregate report attachment.
// Each reference must still resolve to its exact retained native result.
const originalQuestion = await f.client.hypothesis(result.hypothesis.id);
expect(originalQuestion.latestRevision).toMatchObject(result.hypothesis.latestRevision);
const revisedQuestion = await f.research.reviseHypothesis(
result.hypothesis.id,
{
expectedRevision: originalQuestion.latestRevision.ordinal,
title: 'Later human interpretation',
proposition: 'This revision must not replace the candidate study question.',
validationCriteria: 'Further validation is required.',
contentOrigin: 'human',
},
'operator'
);
expect((await f.client.hypothesis(result.hypothesis.id)).latestRevision).toEqual(
revisedQuestion.latestRevision
);
const questionHistory = await f.client.hypothesisRevisions(result.hypothesis.id);
expect(questionHistory).toEqual([
originalQuestion.latestRevision,
revisedQuestion.latestRevision,
]);
const comparisonInput = {
kind: 'finding' as const,
title: 'Cross-candidate observations',
@ -594,6 +690,10 @@ describe.skipIf(!url)('AI research workflow through authenticated APIs and Rust'
expect(reference.value).toBe(native.analytics.metrics.totalReturn);
}
const retained = await f.client.artifact(finding.id);
expect(retained.hypothesisRevisionId).toBe(originalQuestion.latestRevision.id);
expect(questionHistory.find(item => item.id === retained.hypothesisRevisionId)).toEqual(
originalQuestion.latestRevision
);
expect(retained.latestRevision.id).toBe(finding.latestRevision.id);
expect(retained.latestRevision.source).toBeNull();
expect(retained.latestRevision.evidence).toMatchObject(finding.latestRevision.evidence);