fix(mcp): preserve JavaScript workflow identity validation (#1366)
Preserve canonical distinct-source and unique-native-observation refinements after resolving inline or retained JavaScript workflow inputs. The shared application entry points now return structured invalid_request errors before graph parsing and computation, avoiding another complete graph capture. Six focused tests, actual compiled CLI/SDK stdio workflows, JSON Schema dialect checks, static/document checks, and a real Notion ASAR analysis/recovery/trace/close workflow passed. All 20 final-head checks, including real JavaScript recovery, passed. Native-provider acceptance is not claimed for this provider-neutral validation change. Fixes #1364 Refs #1065
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisProtocolError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { AnalysisProtocolError } from "../../domain/analysisErrorCore.js";
|
||||
import { type AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import { analysisInputErrorFromIssues } from "../../domain/inputIssueProjection.js";
|
||||
import { compareJavaScriptApplicationVersions } from "../../domain/javascript/javascriptApplicationVersionComparison.js";
|
||||
import { compareApplicationVersionsInputSchema } from "../../domain/javascript/javascriptApplicationVersionComparisonSchemas.js";
|
||||
import {
|
||||
compareApplicationVersionsInputSchema,
|
||||
applicationVersionIdentitiesSchema,
|
||||
} from "../../domain/javascript/javascriptApplicationVersionComparisonSchemas.js";
|
||||
import { compareJavaScriptExportShapes } from "../../domain/javascript/javascriptExportShapeComparison.js";
|
||||
import { compareJavaScriptExportShapesInputSchema } from "../../domain/javascript/javascriptExportShapeComparisonSchemas.js";
|
||||
import {
|
||||
compareJavaScriptExportShapesInputSchema,
|
||||
javaScriptExportShapeIdentitiesSchema,
|
||||
} from "../../domain/javascript/javascriptExportShapeComparisonSchemas.js";
|
||||
import { traceApplicationFeature } from "../../domain/javascript/javascriptFeatureTrace.js";
|
||||
import { traceApplicationFeatureInputSchema } from "../../domain/javascript/javascriptFeatureTraceSchemas.js";
|
||||
import {
|
||||
traceApplicationFeatureInputSchema,
|
||||
applicationTraceIdentitiesSchema,
|
||||
} from "../../domain/javascript/javascriptFeatureTraceSchemas.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { compareSourceToBundle } from "../../domain/javascript/sourceToBundleComparison.js";
|
||||
import { compareSourceToBundleInputSchema } from "../../domain/javascript/sourceToBundleComparisonSchemas.js";
|
||||
@@ -46,6 +52,11 @@ export const traceApplicationFeatureEvidenceValidated = (
|
||||
input: z.output<typeof traceApplicationFeatureInputSchema>,
|
||||
): Result<Evidence, AnalysisError> => {
|
||||
const operation = "trace_application_feature";
|
||||
const identities = applicationTraceIdentitiesSchema.safeParse(input);
|
||||
if (!identities.success)
|
||||
return err(
|
||||
analysisInputErrorFromIssues(operation, identities.error.issues, input),
|
||||
);
|
||||
const sourceResult = parseApplicationGraphEvidence(input.application, [
|
||||
"application",
|
||||
]);
|
||||
@@ -105,6 +116,11 @@ export const compareApplicationVersionsEvidenceValidated = (
|
||||
input: z.output<typeof compareApplicationVersionsInputSchema>,
|
||||
): Result<Evidence, AnalysisError> => {
|
||||
const operation = "compare_application_versions";
|
||||
const identities = applicationVersionIdentitiesSchema.safeParse(input);
|
||||
if (!identities.success)
|
||||
return err(
|
||||
analysisInputErrorFromIssues(operation, identities.error.issues, input),
|
||||
);
|
||||
const leftResult = parseApplicationGraphEvidence(input.left, ["left"]);
|
||||
if (!leftResult.ok)
|
||||
return err(applicationGraphEvidenceInputError(operation, leftResult.error));
|
||||
@@ -223,6 +239,11 @@ export const compareJavaScriptExportShapesEvidenceValidated = (
|
||||
input: z.output<typeof compareJavaScriptExportShapesInputSchema>,
|
||||
): Result<Evidence, AnalysisError> => {
|
||||
const operation = "compare_javascript_export_shapes";
|
||||
const identities = javaScriptExportShapeIdentitiesSchema.safeParse(input);
|
||||
if (!identities.success)
|
||||
return err(
|
||||
analysisInputErrorFromIssues(operation, identities.error.issues, input),
|
||||
);
|
||||
const leftResult = parseApplicationGraphEvidence(input.left, ["left"]);
|
||||
if (!leftResult.ok)
|
||||
return err(applicationGraphEvidenceInputError(operation, leftResult.error));
|
||||
|
||||
@@ -10,6 +10,52 @@ const evidenceIdSchema = prefixedDigestSchema("ev");
|
||||
const nodeIdSchema = prefixedDigestSchema("jag_node");
|
||||
const textSchema = z.string().min(1);
|
||||
|
||||
/** Check paired version identities and per-side native identity uniqueness. */
|
||||
const validateApplicationVersionIdentities = (
|
||||
input: {
|
||||
readonly left: { readonly evidence_id: string };
|
||||
readonly right: { readonly evidence_id: string };
|
||||
readonly left_native_observations: readonly {
|
||||
readonly evidence_id: string;
|
||||
}[];
|
||||
readonly right_native_observations: readonly {
|
||||
readonly evidence_id: string;
|
||||
}[];
|
||||
},
|
||||
context: z.RefinementCtx,
|
||||
): void => {
|
||||
if (input.left.evidence_id === input.right.evidence_id)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["right"],
|
||||
message: "Application version Evidence must be distinct",
|
||||
});
|
||||
for (const side of [
|
||||
"left_native_observations",
|
||||
"right_native_observations",
|
||||
] as const) {
|
||||
const ids = input[side].map(({ evidence_id: id }) => id);
|
||||
if (new Set(ids).size !== ids.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: [side],
|
||||
message: "Native observations must be unique on each side",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const evidenceIdentitySchema = z.object({ evidence_id: evidenceIdSchema });
|
||||
|
||||
/** Validate paired version identities without capturing whole analysis graphs. */
|
||||
export const applicationVersionIdentitiesSchema = z
|
||||
.object({
|
||||
left: evidenceIdentitySchema,
|
||||
right: evidenceIdentitySchema,
|
||||
left_native_observations: z.array(evidenceIdentitySchema),
|
||||
right_native_observations: z.array(evidenceIdentitySchema),
|
||||
})
|
||||
.superRefine(validateApplicationVersionIdentities);
|
||||
|
||||
/** Two authenticated application versions and their native observations. */
|
||||
export const compareApplicationVersionsInputSchema = z
|
||||
.strictObject({
|
||||
@@ -18,26 +64,7 @@ export const compareApplicationVersionsInputSchema = z
|
||||
left_native_observations: z.array(evidenceSchema).default([]),
|
||||
right_native_observations: z.array(evidenceSchema).default([]),
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
if (input.left.evidence_id === input.right.evidence_id)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["right"],
|
||||
message: "Application version Evidence must be distinct",
|
||||
});
|
||||
for (const side of [
|
||||
"left_native_observations",
|
||||
"right_native_observations",
|
||||
] as const) {
|
||||
const ids = input[side].map(({ evidence_id: id }) => id);
|
||||
if (new Set(ids).size !== ids.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: [side],
|
||||
message: "Native observations must be unique on each side",
|
||||
});
|
||||
}
|
||||
});
|
||||
.superRefine(validateApplicationVersionIdentities);
|
||||
|
||||
const candidateNodesSchema = z.tuple([nodeIdSchema]).rest(nodeIdSchema);
|
||||
const exactMatchSchema = z.strictObject({
|
||||
|
||||
@@ -53,6 +53,32 @@ const sourceRangeSchema = z
|
||||
});
|
||||
});
|
||||
|
||||
/** Check that export-shape comparisons bind distinct source Evidence. */
|
||||
const validateJavaScriptExportShapeIdentities = (
|
||||
input: {
|
||||
readonly left: { readonly evidence_id: string };
|
||||
readonly right: { readonly evidence_id: string };
|
||||
},
|
||||
context: z.RefinementCtx,
|
||||
): void => {
|
||||
if (input.left.evidence_id === input.right.evidence_id)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["right"],
|
||||
message: "JavaScript export shape Evidence must be distinct",
|
||||
});
|
||||
};
|
||||
|
||||
const evidenceIdentitySchema = z.object({ evidence_id: evidenceIdSchema });
|
||||
|
||||
/** Validate export-shape identities without capturing complete source graphs. */
|
||||
export const javaScriptExportShapeIdentitiesSchema = z
|
||||
.object({
|
||||
left: evidenceIdentitySchema,
|
||||
right: evidenceIdentitySchema,
|
||||
})
|
||||
.superRefine(validateJavaScriptExportShapeIdentities);
|
||||
|
||||
/** Two authenticated application graphs and exact export selectors. */
|
||||
export const compareJavaScriptExportShapesInputSchema = z
|
||||
.strictObject({
|
||||
@@ -63,14 +89,7 @@ export const compareJavaScriptExportShapesInputSchema = z
|
||||
right_module_path: textSchema,
|
||||
right_export_name: textSchema,
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
if (input.left.evidence_id === input.right.evidence_id)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["right"],
|
||||
message: "JavaScript export shape Evidence must be distinct",
|
||||
});
|
||||
});
|
||||
.superRefine(validateJavaScriptExportShapeIdentities);
|
||||
|
||||
const projectedReturnFieldShape = {
|
||||
path: jsonPointerSchema,
|
||||
|
||||
@@ -46,6 +46,29 @@ const applicationFeatureSeedSchema = z.union([
|
||||
}),
|
||||
]);
|
||||
|
||||
/** Check unique native identities before projecting an application trace. */
|
||||
const validateApplicationTraceIdentities = (
|
||||
input: {
|
||||
readonly native_observations: readonly { readonly evidence_id: string }[];
|
||||
},
|
||||
context: z.RefinementCtx,
|
||||
): void => {
|
||||
const ids = input.native_observations.map(({ evidence_id: id }) => id);
|
||||
if (new Set(ids).size !== ids.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["native_observations"],
|
||||
message: "Native observations must be unique",
|
||||
});
|
||||
};
|
||||
|
||||
/** Validate native trace identities without capturing their complete Evidence. */
|
||||
export const applicationTraceIdentitiesSchema = z
|
||||
.object({
|
||||
native_observations: z.array(z.object({ evidence_id: evidenceIdSchema })),
|
||||
})
|
||||
.superRefine(validateApplicationTraceIdentities);
|
||||
|
||||
/** Evidence-backed application graph and feature seed. */
|
||||
export const traceApplicationFeatureInputSchema = z
|
||||
.strictObject({
|
||||
@@ -54,15 +77,7 @@ export const traceApplicationFeatureInputSchema = z
|
||||
seed: applicationFeatureSeedSchema,
|
||||
direction: z.enum(["outgoing", "incoming", "both"]).default("both"),
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
const ids = input.native_observations.map(({ evidence_id: id }) => id);
|
||||
if (new Set(ids).size !== ids.length)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["native_observations"],
|
||||
message: "Native observations must be unique",
|
||||
});
|
||||
});
|
||||
.superRefine(validateApplicationTraceIdentities);
|
||||
|
||||
const seedMatchSchema = z.strictObject({
|
||||
node_id: nodeIdSchema,
|
||||
|
||||
Reference in New Issue
Block a user