refactor(snapshot): share persisted execution projection

This commit is contained in:
morluto committed 2026-10-22 09:03:51 +08:00
1 parent 421d527bfe
commit 09b29436f4
1 file changed
+36 -28
+36 -28
View File
@@ -344,6 +344,37 @@ interface SnapshotExecution {
readonly subject: EvidenceSubjectTarget | null;
}
type SnapshotExecutionProjection = Pick<
AnalysisSnapshotEntry["execution"],
| "result"
| "raw_result"
| "provider"
| "limitations"
| "relationship_coverage"
| "locations"
| "subject"
>;
/** Project one authenticated execution into the shared persisted snapshot shape. */
const snapshotExecutionProjection = (
execution: SnapshotExecution,
provider: AnalysisSnapshotEntry["execution"]["provider"],
): SnapshotExecutionProjection => ({
result: execution.result,
raw_result: execution.rawResult,
provider,
limitations: [...execution.limitations],
relationship_coverage: execution.relationshipCoverage ?? null,
locations: [...execution.locations],
subject:
execution.subject === null
? null
: subjectSchema.parse({
...execution.subject,
architecture: execution.subject.architecture ?? null,
}),
});
const canonicalJson = (value: unknown): string => {
const json = jsonValueSchema.parse(value);
const encoded = canonicalize(json);
@@ -489,20 +520,11 @@ export const createAnalysisSnapshotWorkflowEntry = (input: {
operation,
parameters: jsonObjectSchema.parse(parameters),
execution: {
result: execution.result,
raw_result: execution.rawResult,
provider: execution.analysisProfile.provider,
...snapshotExecutionProjection(
execution,
execution.analysisProfile.provider,
),
analysis_profile: execution.analysisProfile,
limitations: [...execution.limitations],
relationship_coverage: execution.relationshipCoverage ?? null,
locations: [...execution.locations],
subject:
execution.subject === null
? null
: subjectSchema.parse({
...execution.subject,
architecture: execution.subject.architecture ?? null,
}),
},
};
};
@@ -552,21 +574,7 @@ export const createAnalysisSnapshotEntry = (input: {
query_id: analysisQueryId(target, binding, operation, parameters),
operation,
parameters: jsonObjectSchema.parse(parameters),
execution: {
result: execution.result,
raw_result: execution.rawResult,
provider: binding.provider,
limitations: [...execution.limitations],
relationship_coverage: execution.relationshipCoverage ?? null,
locations: [...execution.locations],
subject:
execution.subject === null
? null
: subjectSchema.parse({
...execution.subject,
architecture: execution.subject.architecture ?? null,
}),
},
execution: snapshotExecutionProjection(execution, binding.provider),
};
};