fix(managed): share native verification input diagnostics (#2901)
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { evidenceSchema } from "../../domain/evidence.js";
|
import { evidenceSchema } from "../../domain/evidence.js";
|
||||||
|
import { managedNativeVerificationInputSchema } from "../../domain/managed/managedNativeVerificationSchemas.js";
|
||||||
|
|
||||||
import { managedReconstructionImportInputSchema } from "../../domain/managed/managedReconstruction.js";
|
import { managedReconstructionImportInputSchema } from "../../domain/managed/managedReconstruction.js";
|
||||||
import type { ToolContract } from "../toolContractTypes.js";
|
import type { ToolContract } from "../toolContractTypes.js";
|
||||||
@@ -34,35 +35,6 @@ export const managedReconstructionReferenceInputSchema =
|
|||||||
static_members: evidenceSchema,
|
static_members: evidenceSchema,
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Inline Evidence inputs for managed/native verification. */
|
|
||||||
export const managedNativeVerificationReferenceInputSchema = z
|
|
||||||
.strictObject({
|
|
||||||
managed_boundaries: evidenceSchema,
|
|
||||||
native_observations: z
|
|
||||||
.array(evidenceSchema)
|
|
||||||
.min(1)
|
|
||||||
.describe("Native function or export Evidence records"),
|
|
||||||
})
|
|
||||||
.superRefine((input, context) => {
|
|
||||||
const ids = new Set<string>([input.managed_boundaries.evidence_id]);
|
|
||||||
for (const [index, evidence] of input.native_observations.entries()) {
|
|
||||||
if (evidence.evidence_id === input.managed_boundaries.evidence_id)
|
|
||||||
context.addIssue({
|
|
||||||
code: "custom",
|
|
||||||
path: ["native_observations", index],
|
|
||||||
message:
|
|
||||||
"Native observation Evidence must be distinct from managed boundary Evidence",
|
|
||||||
});
|
|
||||||
if (ids.has(evidence.evidence_id))
|
|
||||||
context.addIssue({
|
|
||||||
code: "custom",
|
|
||||||
path: ["native_observations", index],
|
|
||||||
message: "Native observation Evidence IDs must be unique",
|
|
||||||
});
|
|
||||||
ids.add(evidence.evidence_id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const managedApplicationGraphReferenceFacts = {} as const;
|
const managedApplicationGraphReferenceFacts = {} as const;
|
||||||
|
|
||||||
const managedApplicationGraphReferenceShape = z.strictObject({
|
const managedApplicationGraphReferenceShape = z.strictObject({
|
||||||
@@ -146,7 +118,7 @@ export const MANAGED_WORKFLOW_TOOL_CONTRACTS = [
|
|||||||
description:
|
description:
|
||||||
"Verify managed P/Invoke/native-boundary declarations against authenticated native export or function Evidence without executing managed code or translating managed metadata tokens into native addresses. The workflow preserves declaration-only, verified, inferred, contradicted, and unresolved states.",
|
"Verify managed P/Invoke/native-boundary declarations against authenticated native export or function Evidence without executing managed code or translating managed metadata tokens into native addresses. The workflow preserves declaration-only, verified, inferred, contradicted, and unresolved states.",
|
||||||
kind: "application",
|
kind: "application",
|
||||||
inputSchema: managedNativeVerificationReferenceInputSchema,
|
inputSchema: managedNativeVerificationInputSchema,
|
||||||
outputSchema: nativeVerificationOutputSchema,
|
outputSchema: nativeVerificationOutputSchema,
|
||||||
examples: [
|
examples: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import { managedNativeVerificationInputSchema } from "../domain/managed/managedNativeVerificationSchemas.js";
|
||||||
|
import { toolContract } from "./toolContracts.js";
|
||||||
|
import { toolInputSchemaWithMetadata } from "./toolSchemaMetadata.js";
|
||||||
|
|
||||||
import { traceJavaScriptSemanticsRequestSchema } from "./javascript/applicationWorkflowInputContracts.js";
|
import { traceJavaScriptSemanticsRequestSchema } from "./javascript/applicationWorkflowInputContracts.js";
|
||||||
import { JAVASCRIPT_FEATURE_TRACE_EXAMPLE } from "./javascript/javascriptApplicationWorkflowExamples.js";
|
import { JAVASCRIPT_FEATURE_TRACE_EXAMPLE } from "./javascript/javascriptApplicationWorkflowExamples.js";
|
||||||
import {
|
import {
|
||||||
@@ -10,7 +14,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
compareManagedMembersReferenceInputSchema,
|
compareManagedMembersReferenceInputSchema,
|
||||||
managedApplicationGraphReferenceInputSchema,
|
managedApplicationGraphReferenceInputSchema,
|
||||||
managedNativeVerificationReferenceInputSchema,
|
|
||||||
} from "./managed/managedWorkflowToolContracts.js";
|
} from "./managed/managedWorkflowToolContracts.js";
|
||||||
|
|
||||||
describe("workflow input contracts", () => {
|
describe("workflow input contracts", () => {
|
||||||
@@ -41,17 +44,6 @@ describe("workflow input contracts", () => {
|
|||||||
}).success,
|
}).success,
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
|
|
||||||
expect(
|
|
||||||
managedNativeVerificationReferenceInputSchema.safeParse({
|
|
||||||
managed_boundaries:
|
|
||||||
MANAGED_NATIVE_VERIFICATION_EXAMPLE.managed_boundaries,
|
|
||||||
native_observations: [
|
|
||||||
MANAGED_NATIVE_VERIFICATION_EXAMPLE.native_observations[0],
|
|
||||||
MANAGED_NATIVE_VERIFICATION_EXAMPLE.native_observations[0],
|
|
||||||
],
|
|
||||||
}).success,
|
|
||||||
).toBe(false);
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
managedApplicationGraphReferenceInputSchema.safeParse({
|
managedApplicationGraphReferenceInputSchema.safeParse({
|
||||||
managed_artifact: MANAGED_APPLICATION_GRAPH_EXAMPLE.managed_members,
|
managed_artifact: MANAGED_APPLICATION_GRAPH_EXAMPLE.managed_members,
|
||||||
@@ -62,4 +54,80 @@ describe("workflow input contracts", () => {
|
|||||||
managedApplicationGraphReferenceInputSchema.safeParse({}).success,
|
managedApplicationGraphReferenceInputSchema.safeParse({}).success,
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
name: "one observation reusing the boundary",
|
||||||
|
observations: [MANAGED_NATIVE_VERIFICATION_EXAMPLE.managed_boundaries],
|
||||||
|
issues: [
|
||||||
|
{
|
||||||
|
path: ["native_observations", 0],
|
||||||
|
message:
|
||||||
|
"Native observation Evidence must be distinct from managed boundary Evidence",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "repeated native observations",
|
||||||
|
observations: [
|
||||||
|
MANAGED_NATIVE_VERIFICATION_EXAMPLE.native_observations[0],
|
||||||
|
MANAGED_NATIVE_VERIFICATION_EXAMPLE.native_observations[0],
|
||||||
|
],
|
||||||
|
issues: [
|
||||||
|
{
|
||||||
|
path: ["native_observations", 1],
|
||||||
|
message: "Native observation Evidence IDs must be unique",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "repeated observations reusing the boundary",
|
||||||
|
observations: [
|
||||||
|
MANAGED_NATIVE_VERIFICATION_EXAMPLE.managed_boundaries,
|
||||||
|
MANAGED_NATIVE_VERIFICATION_EXAMPLE.managed_boundaries,
|
||||||
|
],
|
||||||
|
issues: [
|
||||||
|
{
|
||||||
|
path: ["native_observations", 0],
|
||||||
|
message:
|
||||||
|
"Native observation Evidence must be distinct from managed boundary Evidence",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ["native_observations", 1],
|
||||||
|
message:
|
||||||
|
"Native observation Evidence must be distinct from managed boundary Evidence",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ["native_observations", 1],
|
||||||
|
message: "Native observation Evidence IDs must be unique",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "distinct native observations",
|
||||||
|
observations: MANAGED_NATIVE_VERIFICATION_EXAMPLE.native_observations,
|
||||||
|
issues: [],
|
||||||
|
},
|
||||||
|
])(
|
||||||
|
"preserves managed/native diagnostics for $name",
|
||||||
|
async ({ observations, issues }) => {
|
||||||
|
const input = {
|
||||||
|
managed_boundaries:
|
||||||
|
MANAGED_NATIVE_VERIFICATION_EXAMPLE.managed_boundaries,
|
||||||
|
native_observations: observations,
|
||||||
|
};
|
||||||
|
const contract = toolContract("verify_managed_native_boundaries");
|
||||||
|
for (const schema of [
|
||||||
|
managedNativeVerificationInputSchema,
|
||||||
|
contract.inputSchema,
|
||||||
|
toolInputSchemaWithMetadata(contract),
|
||||||
|
]) {
|
||||||
|
const result = await schema["~standard"].validate(input);
|
||||||
|
expect(
|
||||||
|
result.issues?.map(({ path, message }) => ({ path, message })) ?? [],
|
||||||
|
).toEqual(issues);
|
||||||
|
if (issues.length === 0) expect(result).toEqual({ value: input });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -92,7 +92,10 @@ export type PinvokeVerification = z.infer<typeof pinvokeVerificationSchema>;
|
|||||||
export const managedNativeVerificationInputSchema = z
|
export const managedNativeVerificationInputSchema = z
|
||||||
.strictObject({
|
.strictObject({
|
||||||
managed_boundaries: evidenceSchema,
|
managed_boundaries: evidenceSchema,
|
||||||
native_observations: z.array(evidenceSchema).min(1),
|
native_observations: z
|
||||||
|
.array(evidenceSchema)
|
||||||
|
.min(1)
|
||||||
|
.describe("Native function or export Evidence records"),
|
||||||
})
|
})
|
||||||
.superRefine((input, context) => {
|
.superRefine((input, context) => {
|
||||||
const ids = new Set<string>();
|
const ids = new Set<string>();
|
||||||
|
|||||||
Reference in New Issue
Block a user