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
|
|
@ -5,6 +5,7 @@ import { canonicalStrategyJson } from '@stock-bot/stock-config/strategy';
|
|||
import type {
|
||||
ResearchArtifact,
|
||||
ResearchContentOrigin,
|
||||
ResearchEvidenceReference,
|
||||
ResearchHypothesis,
|
||||
ResearchProject,
|
||||
} from '@stock-bot/types';
|
||||
|
|
@ -24,6 +25,15 @@ import {
|
|||
} from './findingSources';
|
||||
import { ResearchEvidenceList, researchMetricLabel } from './ResearchEvidence';
|
||||
|
||||
function referenceIdentities(references: ResearchEvidenceReference[]) {
|
||||
return references.map(({ runId, metricsVersion, metricPath, strategyVersionId }) => ({
|
||||
runId,
|
||||
metricsVersion,
|
||||
metricPath,
|
||||
strategyVersionId: strategyVersionId ?? null,
|
||||
}));
|
||||
}
|
||||
|
||||
/** Preserve the original single-run API and initial total-return selection. */
|
||||
export function SaveFindingDialog({
|
||||
result,
|
||||
|
|
@ -252,19 +262,11 @@ function FindingDraft({
|
|||
artifact.projectId !== projectId ||
|
||||
artifact.hypothesisRevisionId !== input.hypothesisRevisionId ||
|
||||
artifact.kind !== 'finding' ||
|
||||
(source.context !== null &&
|
||||
(canonicalStrategyJson(artifact.latestRevision.source ?? null) !==
|
||||
canonicalStrategyJson(source.context) ||
|
||||
canonicalStrategyJson(
|
||||
artifact.latestRevision.evidence.map(
|
||||
({ runId, metricsVersion, metricPath, strategyVersionId }) => ({
|
||||
runId,
|
||||
metricsVersion,
|
||||
metricPath,
|
||||
strategyVersionId,
|
||||
})
|
||||
)
|
||||
) !== canonicalStrategyJson(input.evidence)))
|
||||
canonicalStrategyJson(artifact.latestRevision.source ?? null) !==
|
||||
canonicalStrategyJson(source.context) ||
|
||||
!Array.isArray(artifact.latestRevision.evidence) ||
|
||||
canonicalStrategyJson(referenceIdentities(artifact.latestRevision.evidence)) !==
|
||||
canonicalStrategyJson(referenceIdentities(input.evidence ?? []))
|
||||
) {
|
||||
throw new ResearchApiError('The saved finding response could not be verified.', null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue