fix(research): verify single-run finding acknowledgements (RP24)
This commit is contained in:
parent
2da899daf2
commit
f80ae2f3f3
4 changed files with 233 additions and 27 deletions
|
|
@ -9,6 +9,7 @@ import type {
|
|||
import type {
|
||||
BacktestRunResult,
|
||||
ResearchArtifact,
|
||||
ResearchEvidenceReference,
|
||||
ResearchHypothesis,
|
||||
ResearchProject,
|
||||
} from '@stock-bot/types';
|
||||
|
|
@ -161,6 +162,24 @@ const artifact = (hypothesisRevisionId: string | null = null): ResearchArtifact
|
|||
createdAt: '2026-10-23',
|
||||
},
|
||||
});
|
||||
function acceptedFinding(hypothesisRevisionId: string | null = null): ResearchArtifact {
|
||||
const saved = artifact(hypothesisRevisionId);
|
||||
const input = post().body as { evidence: ResearchEvidenceReference[] };
|
||||
saved.latestRevision.source = null;
|
||||
saved.latestRevision.evidence = input.evidence.map(reference => ({
|
||||
...reference,
|
||||
backtestId: 'definition',
|
||||
value: reference.metricPath.endsWith('sharpeRatio') ? null : 0.23,
|
||||
unit: 'fraction',
|
||||
availability: reference.metricPath.endsWith('sharpeRatio') ? 'unavailable' : 'available',
|
||||
unavailableReason: reference.metricPath.endsWith('sharpeRatio') ? 'insufficient-data' : null,
|
||||
resultKind: reference.metricsVersion === 'canonical-analytics/v1' ? 'canonical' : 'legacy',
|
||||
financialEngine: reference.metricsVersion === 'canonical-analytics/v1' ? 'rust' : 'typescript',
|
||||
datasetHash: 'a'.repeat(64),
|
||||
limitations: [],
|
||||
}));
|
||||
return saved;
|
||||
}
|
||||
function legacy(runId = 'run'): BacktestRunResult {
|
||||
return {
|
||||
runId,
|
||||
|
|
@ -385,29 +404,117 @@ describe('saved-result finding', () => {
|
|||
},
|
||||
],
|
||||
});
|
||||
await flush(() => reply(post(), { artifact: artifact('h1-revision') }, 201));
|
||||
await flush(() => reply(post(), { artifact: acceptedFinding('h1-revision') }, 201));
|
||||
expect(host.querySelector('a')?.getAttribute('href')).toBe(
|
||||
'/research/p1?artifact=saved-finding'
|
||||
);
|
||||
expect(host.textContent).toContain('narrative remains unvalidated');
|
||||
expect(closed).toBe(0);
|
||||
});
|
||||
test('legacy citations retain qualification and do not infer a strategy version', async () => {
|
||||
await mountDialog(legacy());
|
||||
test.each([
|
||||
'empty',
|
||||
'missing',
|
||||
'extra',
|
||||
'foreign-run',
|
||||
'foreign-version',
|
||||
'missing-version',
|
||||
'foreign-metric',
|
||||
'legacy-metric',
|
||||
'foreign-source',
|
||||
] as const)('%s evidence acknowledgement freezes the single-run finding draft', async failure => {
|
||||
await mountDialog();
|
||||
await draft();
|
||||
await preflight();
|
||||
expect(host.textContent).toContain('Legacy · Unverified economics');
|
||||
expect(post().body).toEqual({
|
||||
kind: 'finding',
|
||||
title: 'Exact finding',
|
||||
body: 'Keep this narrative',
|
||||
contentOrigin: 'human',
|
||||
hypothesisRevisionId: null,
|
||||
evidence: [
|
||||
{ runId: 'run', metricsVersion: 'legacy-display/v1', metricPath: 'metrics.totalReturn' },
|
||||
],
|
||||
});
|
||||
const saved = acceptedFinding();
|
||||
const reference = saved.latestRevision.evidence[0]!;
|
||||
switch (failure) {
|
||||
case 'empty':
|
||||
saved.latestRevision.evidence = [];
|
||||
break;
|
||||
case 'missing':
|
||||
delete (saved.latestRevision as Partial<ResearchArtifact['latestRevision']>).evidence;
|
||||
break;
|
||||
case 'extra':
|
||||
saved.latestRevision.evidence.push({ ...reference, metricPath: 'analytics.fillCount' });
|
||||
break;
|
||||
case 'foreign-run':
|
||||
reference.runId = 'another-run';
|
||||
break;
|
||||
case 'foreign-version':
|
||||
reference.strategyVersionId = 'another-version';
|
||||
break;
|
||||
case 'missing-version':
|
||||
reference.strategyVersionId = null;
|
||||
break;
|
||||
case 'foreign-metric':
|
||||
reference.metricPath = 'analytics.metrics.maxDrawdown';
|
||||
break;
|
||||
case 'legacy-metric':
|
||||
reference.metricsVersion = 'legacy-display/v1';
|
||||
reference.metricPath = 'metrics.totalReturn';
|
||||
break;
|
||||
case 'foreign-source':
|
||||
saved.latestRevision.source = {
|
||||
kind: 'experiment/v1',
|
||||
experimentId: '22222222-2222-4222-8222-222222222222',
|
||||
previewHash: 'a'.repeat(64),
|
||||
};
|
||||
break;
|
||||
}
|
||||
await flush(() => reply(post(), { artifact: saved }, 201));
|
||||
expect(host.textContent).toContain('saved finding response could not be verified');
|
||||
expect(host.textContent).toContain('Check saved records before creating another');
|
||||
expect(host.textContent).not.toContain('Finding saved.');
|
||||
expect(host.textContent).not.toContain('Open saved finding');
|
||||
expect(field('Finding title').value).toBe('Exact finding');
|
||||
expect(field('Finding body').value).toBe('Keep this narrative');
|
||||
expect(field('Finding title').disabled).toBe(true);
|
||||
expect(button('Save finding').disabled).toBe(true);
|
||||
await flush(() => button('Save finding').click());
|
||||
expect(requests.filter(item => item.method === 'POST')).toHaveLength(1);
|
||||
});
|
||||
test.each(['omitted', 'null'] as const)(
|
||||
'matching canonical evidence accepts %s aggregate source',
|
||||
async source => {
|
||||
await mountDialog();
|
||||
await draft();
|
||||
await preflight();
|
||||
const saved = acceptedFinding();
|
||||
if (source === 'omitted') {
|
||||
delete saved.latestRevision.source;
|
||||
}
|
||||
await flush(() => reply(post(), { artifact: saved }, 201));
|
||||
expect(host.textContent).toContain('Finding saved.');
|
||||
expect(host.querySelector('a')?.getAttribute('href')).toContain('artifact=saved-finding');
|
||||
}
|
||||
);
|
||||
test.each(['omitted', 'null'] as const)(
|
||||
'legacy citations accept %s version without inferring one',
|
||||
async version => {
|
||||
await mountDialog(legacy());
|
||||
await draft();
|
||||
await preflight();
|
||||
expect(host.textContent).toContain('Legacy · Unverified economics');
|
||||
expect(post().body).toEqual({
|
||||
kind: 'finding',
|
||||
title: 'Exact finding',
|
||||
body: 'Keep this narrative',
|
||||
contentOrigin: 'human',
|
||||
hypothesisRevisionId: null,
|
||||
evidence: [
|
||||
{ runId: 'run', metricsVersion: 'legacy-display/v1', metricPath: 'metrics.totalReturn' },
|
||||
],
|
||||
});
|
||||
const saved = acceptedFinding();
|
||||
if (version === 'null') {
|
||||
saved.latestRevision.evidence[0]!.strategyVersionId = null;
|
||||
}
|
||||
await flush(() => reply(post(), { artifact: saved }, 201));
|
||||
expect(host.textContent).toContain('Finding saved.');
|
||||
expect(host.textContent).toContain('Legacy · Unverified economics');
|
||||
expect(host.querySelector('a[href*="/strategies/versions/"]')).toBeNull();
|
||||
}
|
||||
);
|
||||
test('late project and hypothesis responses cannot overwrite the current destination', async () => {
|
||||
await mountDialog();
|
||||
await flush(() => edit('Finding project', 'p1'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue