mirror of
https://github.com/morluto/rea.git
synced 2026-11-11 01:13:39 +00:00
refactor(evidence): unify retained inputs across domains (#8299)
Declare logical Evidence sources once and resolve exact retained inputs through shared application workflows across 20 composition tools. Preserve domain-owned authentication, source closure, caller choices, coverage and resource admission. Validation includes public CLI/MCP regressions, local Codex terra/high trials and fresh-import real-artifact workflows. Measurements, failed attempts and coverage limits are recorded in docs/verification/evidence-input-composition-2026-10-31.md. Fixes #8293. Fixes #8281. Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
This commit is contained in:
1 parent
23de10bb28
commit
a989c0e458
114 files changed
+8532
-1383
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { emptyArraySchema } from "../emptyArraySchema.js";
|
||||
import { evidenceSchema } from "../evidence.js";
|
||||
import {
|
||||
isValidatedImmutableJavaScriptApplicationGraph,
|
||||
javascriptApplicationGraphSchema,
|
||||
@@ -60,16 +59,6 @@ export const applicationVersionIdentitiesSchema = z
|
||||
})
|
||||
.superRefine(validateApplicationVersionIdentities);
|
||||
|
||||
/** Two authenticated application versions and their native observations. */
|
||||
export const compareApplicationVersionsInputSchema = z
|
||||
.strictObject({
|
||||
left: evidenceSchema,
|
||||
right: evidenceSchema,
|
||||
left_native_observations: z.array(evidenceSchema).default([]),
|
||||
right_native_observations: z.array(evidenceSchema).default([]),
|
||||
})
|
||||
.superRefine(validateApplicationVersionIdentities);
|
||||
|
||||
const candidateNodesSchema = z
|
||||
.tuple([nodeIdSchema], nodeIdSchema)
|
||||
.check(z.minLength(1));
|
||||
|
||||
@@ -2,21 +2,23 @@ import { classifyStaticLoadStates } from "./javascriptRuntimeLoadState.js";
|
||||
import { buildReconciledApplicationGraph } from "./javascriptRuntimeReconciliationGraph.js";
|
||||
import { reconcileRuntimeEntities } from "./javascriptRuntimeReconciliationMatching.js";
|
||||
import {
|
||||
parseStaticLayers,
|
||||
parseStaticLayer,
|
||||
type ParsedStaticLayer,
|
||||
} from "./javascriptRuntimeReconciliationParsing.js";
|
||||
import {
|
||||
parseRuntimeCaptures,
|
||||
parseRuntimeCapture,
|
||||
type ParsedRuntimeCapture,
|
||||
} from "./javascriptRuntimeReconciliationCaptureParsing.js";
|
||||
import { createJavaScriptRuntimeReconciliationResult } from "./javascriptRuntimeReconciliationResult.js";
|
||||
import type {
|
||||
JavaScriptRuntimeReconciliationResult,
|
||||
ReconcileJavaScriptRuntimeFrame,
|
||||
ReconcileJavaScriptRuntimeInput,
|
||||
} from "./javascriptRuntimeReconciliationSchemas.js";
|
||||
import { projectRuntimeCaptures } from "./javascriptRuntimeReconciliationRuntime.js";
|
||||
import { collectStaticRuntimeCandidates } from "./javascriptRuntimeStaticCandidates.js";
|
||||
import { AnalysisInputError } from "../analysisErrorCore.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { err, ok, type Result } from "../result.js";
|
||||
|
||||
/** Verified caller input and the static and runtime facts parsed from it. */
|
||||
@@ -28,15 +30,48 @@ export interface ParsedRuntimeReconciliationInput {
|
||||
|
||||
/** Parse caller Evidence once into the owner consumed by reconciliation. */
|
||||
export const readRuntimeReconciliationInput = (
|
||||
input: ReconcileJavaScriptRuntimeInput,
|
||||
input: ReconcileJavaScriptRuntimeFrame,
|
||||
): Result<ParsedRuntimeReconciliationInput, AnalysisInputError> => {
|
||||
try {
|
||||
const layers: ParsedStaticLayer[] = [];
|
||||
const captures: ParsedRuntimeCapture[] = [];
|
||||
// Preserve caller source order in Evidence parameters while the algorithm
|
||||
// consumes deterministically sorted facts. Only authenticated records enter
|
||||
// the canonical input returned to the Evidence constructor.
|
||||
const staticLayers = input.static_layers.map((layer, index) => {
|
||||
const parsed = parseStaticLayer(layer, [
|
||||
"static_layers",
|
||||
index,
|
||||
"analysis",
|
||||
]);
|
||||
layers.push(parsed);
|
||||
return { ...layer, analysis: parsed.evidence };
|
||||
});
|
||||
const runtimeObservations = input.runtime_observations.map(
|
||||
(observation, index) => {
|
||||
const parsed = parseRuntimeCapture(observation, [
|
||||
"runtime_observations",
|
||||
index,
|
||||
]);
|
||||
captures.push(parsed);
|
||||
return parsed.evidence;
|
||||
},
|
||||
);
|
||||
return ok({
|
||||
input,
|
||||
layers: parseStaticLayers(input.static_layers, ["static_layers"]),
|
||||
captures: parseRuntimeCaptures(input.runtime_observations, [
|
||||
"runtime_observations",
|
||||
]),
|
||||
input: {
|
||||
...input,
|
||||
static_layers: staticLayers,
|
||||
runtime_observations: runtimeObservations,
|
||||
},
|
||||
layers: layers.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.layerId, right.layerId),
|
||||
),
|
||||
captures: captures.sort((left, right) =>
|
||||
compareUnicodeCodePoints(
|
||||
left.evidence.evidence_id,
|
||||
right.evidence.evidence_id,
|
||||
),
|
||||
),
|
||||
});
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof AnalysisInputError) return err(cause);
|
||||
|
||||
@@ -126,7 +126,7 @@ export type ParsedRuntimeCapture =
|
||||
|
||||
/** Parse only supported passive web/Electron inspection Evidence. */
|
||||
export const parseRuntimeCaptures = (
|
||||
observations: readonly Evidence[],
|
||||
observations: readonly unknown[],
|
||||
path: readonly (string | number)[] = ["runtime_observations"],
|
||||
): ParsedRuntimeCapture[] =>
|
||||
observations
|
||||
@@ -140,8 +140,9 @@ export const parseRuntimeCaptures = (
|
||||
),
|
||||
);
|
||||
|
||||
const parseRuntimeCapture = (
|
||||
input: Evidence,
|
||||
/** Authenticate one source before interpreting its runtime capture. */
|
||||
export const parseRuntimeCapture = (
|
||||
input: unknown,
|
||||
evidencePath: readonly (string | number)[],
|
||||
): ParsedRuntimeCapture => {
|
||||
const evidence = authenticateRuntimeEvidence(input, evidencePath);
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { Evidence } from "../evidence.js";
|
||||
import {
|
||||
javascriptApplicationAnalysisResultSchema,
|
||||
type JavaScriptApplicationAnalysisResult,
|
||||
} from "./javascriptApplicationAnalysis.js";
|
||||
import type { JavaScriptApplicationGraph } from "./javascriptApplicationGraph.js";
|
||||
import type { ReconcileJavaScriptRuntimeInput } from "./javascriptRuntimeReconciliationSchemas.js";
|
||||
import type { ReconcileJavaScriptRuntimeFrame } from "./javascriptRuntimeReconciliationSchemas.js";
|
||||
import {
|
||||
assertEvidenceIdentity,
|
||||
authenticateRuntimeEvidence,
|
||||
@@ -15,7 +14,7 @@ import {
|
||||
} from "./javascriptRuntimeReconciliationInputValidation.js";
|
||||
|
||||
type StaticLayerInput =
|
||||
ReconcileJavaScriptRuntimeInput["static_layers"][number];
|
||||
ReconcileJavaScriptRuntimeFrame["static_layers"][number];
|
||||
type RuntimeMapping = StaticLayerInput["runtime_mappings"][number];
|
||||
|
||||
export interface ParsedStaticLayer {
|
||||
@@ -27,20 +26,8 @@ export interface ParsedStaticLayer {
|
||||
readonly runtimeMappings: readonly RuntimeMapping[];
|
||||
}
|
||||
|
||||
/** Parse and semantically bind every static analysis Evidence layer. */
|
||||
export const parseStaticLayers = (
|
||||
layers: readonly StaticLayerInput[],
|
||||
path: readonly (string | number)[] = ["static_layers"],
|
||||
): ParsedStaticLayer[] =>
|
||||
layers
|
||||
.map((layer, index) =>
|
||||
parseStaticLayer(layer, [...path, index, "analysis"]),
|
||||
)
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.layerId, right.layerId),
|
||||
);
|
||||
|
||||
const parseStaticLayer = (
|
||||
/** Authenticate and semantically bind one admitted static analysis layer. */
|
||||
export const parseStaticLayer = (
|
||||
layer: StaticLayerInput,
|
||||
evidencePath: readonly (string | number)[],
|
||||
): ParsedStaticLayer => {
|
||||
|
||||
@@ -3,10 +3,10 @@ import { z } from "zod";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { logicalPathEscapesRoot } from "../artifactIdentity.js";
|
||||
import { evidenceSchema } from "../evidence.js";
|
||||
import type { EvidenceRequestFrameInput } from "../evidenceInputContract.js";
|
||||
import { javascriptRuntimeUnresolvedLocationSchema } from "./javascriptRuntimeObservation.js";
|
||||
import { javascriptApplicationGraphSchema } from "./javascriptApplicationGraph.js";
|
||||
import { digestSchema } from "../digests.js";
|
||||
import { prefixedDigestSchema } from "../digests.js";
|
||||
import { digestSchema, prefixedDigestSchema } from "../digests.js";
|
||||
import { urlDeclaresQueryOrFragment } from "../urlComponents.js";
|
||||
|
||||
const evidenceIdSchema = prefixedDigestSchema("ev");
|
||||
@@ -95,41 +95,65 @@ function runtimeMappingKey(mapping: RuntimeLocationMapping): string {
|
||||
: `url-prefix\0${mapping.prefix}\0${mapping.artifact_prefix}`;
|
||||
}
|
||||
|
||||
const validateReconciliationIdentities = (
|
||||
input: {
|
||||
readonly static_layers: readonly {
|
||||
readonly role: "application" | "cache" | "assets";
|
||||
readonly analysis: { readonly evidence_id: string };
|
||||
}[];
|
||||
readonly runtime_observations: readonly { readonly evidence_id: string }[];
|
||||
},
|
||||
context: z.RefinementCtx,
|
||||
): void => {
|
||||
if (
|
||||
input.static_layers.filter(({ role }) => role === "application").length !==
|
||||
1
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["static_layers"],
|
||||
message: "Exactly one application static layer is required",
|
||||
});
|
||||
const staticIds = input.static_layers.map(
|
||||
({ analysis }) => analysis.evidence_id,
|
||||
);
|
||||
if (new Set(staticIds).size !== staticIds.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["static_layers"],
|
||||
message: "Static layer Evidence must be unique",
|
||||
});
|
||||
const runtimeIds = input.runtime_observations.map(
|
||||
({ evidence_id: id }) => id,
|
||||
);
|
||||
if (new Set(runtimeIds).size !== runtimeIds.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["runtime_observations"],
|
||||
message: "Runtime observation Evidence must be unique",
|
||||
});
|
||||
};
|
||||
|
||||
/** Verify layer roles and source uniqueness without copying retained payloads. */
|
||||
export const runtimeReconciliationIdentitiesSchema = z
|
||||
.object({
|
||||
static_layers: z.array(
|
||||
z.object({
|
||||
role: z.enum(["application", "cache", "assets"]),
|
||||
analysis: z.object({ evidence_id: evidenceIdSchema }),
|
||||
}),
|
||||
),
|
||||
runtime_observations: z.array(z.object({ evidence_id: evidenceIdSchema })),
|
||||
})
|
||||
.superRefine(validateReconciliationIdentities);
|
||||
|
||||
/** Evidence-backed static layers and passive captures to reconcile. */
|
||||
export const reconcileJavaScriptRuntimeInputSchema = z
|
||||
.strictObject({
|
||||
static_layers: z.array(staticLayerSchema).min(1),
|
||||
runtime_observations: z.array(evidenceSchema).min(1),
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
if (
|
||||
input.static_layers.filter(({ role }) => role === "application")
|
||||
.length !== 1
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["static_layers"],
|
||||
message: "Exactly one application static layer is required",
|
||||
});
|
||||
const staticIds = input.static_layers.map(
|
||||
({ analysis }) => analysis.evidence_id,
|
||||
);
|
||||
if (new Set(staticIds).size !== staticIds.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["static_layers"],
|
||||
message: "Static layer Evidence must be unique",
|
||||
});
|
||||
const runtimeIds = input.runtime_observations.map(
|
||||
({ evidence_id: id }) => id,
|
||||
);
|
||||
if (new Set(runtimeIds).size !== runtimeIds.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["runtime_observations"],
|
||||
message: "Runtime observation Evidence must be unique",
|
||||
});
|
||||
});
|
||||
.superRefine(validateReconciliationIdentities);
|
||||
|
||||
const layerSummarySchema = z.strictObject({
|
||||
layer_id: prefixedDigestSchema("jrl"),
|
||||
@@ -275,6 +299,9 @@ export const javascriptRuntimeReconciliationResultSchema = z.strictObject({
|
||||
export type ReconcileJavaScriptRuntimeInput = z.infer<
|
||||
typeof reconcileJavaScriptRuntimeInputSchema
|
||||
>;
|
||||
/** Admitted ordinary request facts; each source still needs owner authentication. */
|
||||
export type ReconcileJavaScriptRuntimeFrame =
|
||||
EvidenceRequestFrameInput<ReconcileJavaScriptRuntimeInput>;
|
||||
export type JavaScriptRuntimeReconciliationResult = z.infer<
|
||||
typeof javascriptRuntimeReconciliationResultSchema
|
||||
>;
|
||||
|
||||
Reference in new issue
Block a user