fix(research): support typed cross-study findings (RP23)
This commit is contained in:
parent
27d2bc961c
commit
8dc8724c52
4 changed files with 296 additions and 2 deletions
|
|
@ -469,6 +469,85 @@ describe.skipIf(!url)('AI research workflow through authenticated APIs and Rust'
|
|||
);
|
||||
const reopened = await f.client.validation(result.outcomes[0]!.validation!.id);
|
||||
expect(reopened.report).toEqual(result.outcomes[0]!.validation!.report);
|
||||
|
||||
// A comparison across candidates has no single aggregate report attachment.
|
||||
// Each reference must still resolve to its exact retained native result.
|
||||
const comparisonInput = {
|
||||
kind: 'finding' as const,
|
||||
title: 'Cross-candidate observations',
|
||||
body: 'AI-generated comparison, unvalidated; no comparability or profitability claim.',
|
||||
hypothesisRevisionId: result.hypothesis.latestRevision.id,
|
||||
evidence: result.outcomes.slice(0, 2).map(outcome => ({
|
||||
runId: outcome.validation!.report!.test.runId,
|
||||
strategyVersionId: outcome.versionId,
|
||||
metricsVersion: 'canonical-analytics/v1' as const,
|
||||
metricPath: 'analytics.metrics.totalReturn' as const,
|
||||
})),
|
||||
};
|
||||
expect(new Set(comparisonInput.evidence.map(item => item.strategyVersionId)).size).toBe(2);
|
||||
for (const source of [null, undefined]) {
|
||||
const finding = await f.client.saveFinding(f.project.id, { ...comparisonInput, source });
|
||||
expect(finding.latestRevision).toMatchObject({
|
||||
source: null,
|
||||
contentOrigin: 'ai',
|
||||
submittedBy: f.provisioned.agent.id,
|
||||
validationState: 'unvalidated',
|
||||
evidenceState: 'referenced',
|
||||
});
|
||||
expect(finding.latestRevision.evidence).toHaveLength(2);
|
||||
const savedInput = f.requests.at(-1)!.body as Record<string, unknown>;
|
||||
expect(Object.hasOwn(savedInput, 'source')).toBe(source === null);
|
||||
expect(savedInput.evidence).toEqual(comparisonInput.evidence);
|
||||
for (const reference of finding.latestRevision.evidence) {
|
||||
const native = await f.api.getRunResults(reference.runId);
|
||||
if (!native || !('kind' in native) || native.kind !== 'canonical-result/v1') {
|
||||
throw new Error('Missing native comparison evidence');
|
||||
}
|
||||
expect(reference.strategyVersionId).toBe(native.request.strategy.versionId);
|
||||
expect(reference.datasetHash).toBe(native.request.datasetHash);
|
||||
expect(reference.value).toBe(native.analytics.metrics.totalReturn);
|
||||
}
|
||||
const response = await f.transport(
|
||||
`http://127.0.0.1:2003/api/v2/analysis-artifacts/${finding.id}`,
|
||||
{ headers: { Authorization: `Bearer ${f.provisioned.token}` } }
|
||||
);
|
||||
expect(response.status).toBe(200);
|
||||
const retained = (await response.json()).artifact;
|
||||
expect(retained.latestRevision.id).toBe(finding.latestRevision.id);
|
||||
expect(retained.latestRevision.source).toBeNull();
|
||||
expect(retained.latestRevision.evidence).toMatchObject(finding.latestRevision.evidence);
|
||||
expect(retained.latestRevision.validationState).toBe('unvalidated');
|
||||
}
|
||||
const artifactsBeforeRefusals = (
|
||||
await f.pool.query('SELECT count(*)::int AS count FROM analysis_artifacts')
|
||||
).rows[0].count;
|
||||
const reference = comparisonInput.evidence[0]!;
|
||||
for (const invalid of [
|
||||
{ ...reference, strategyVersionId: result.outcomes[1]!.versionId },
|
||||
{ ...reference, runId: randomUUID() },
|
||||
{
|
||||
...reference,
|
||||
runId: broken.screening!.trials[0]!.runId!,
|
||||
strategyVersionId: broken.versionId,
|
||||
},
|
||||
]) {
|
||||
await expect(
|
||||
f.client.saveFinding(f.project.id, {
|
||||
...comparisonInput,
|
||||
source: null,
|
||||
evidence: [invalid],
|
||||
})
|
||||
).rejects.toMatchObject({ status: 422, uncertain: false });
|
||||
}
|
||||
await expect(
|
||||
f.client.saveFinding(randomUUID(), { ...comparisonInput, source: null })
|
||||
).rejects.toMatchObject({ status: 403, uncertain: false });
|
||||
expect(
|
||||
(await f.pool.query('SELECT count(*)::int AS count FROM analysis_artifacts')).rows[0].count
|
||||
).toBe(artifactsBeforeRefusals);
|
||||
expect((await f.pool.query('SELECT count(*)::int AS count FROM runs')).rows[0].count).toBe(
|
||||
before
|
||||
);
|
||||
}, 180000);
|
||||
|
||||
test('real quota refusal and oversized search create no runs; nonmember evidence cannot become a finding', async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue