feat(dotnet): verify managed native boundaries
Add the verify_managed_native_boundaries workflow for comparing authenticated inspect_managed_native_boundaries Evidence with supplied native export or function Evidence. The workflow verifies only P/Invoke declaration names against observed native symbols, keeps verified, inferred, contradicted, unresolved, and unsupported-native states explicit, and does not translate managed metadata tokens or RVAs into native addresses. Expose schema-identical MCP and CLI surfaces, update managed workflow contracts, product catalog facts, TypeDoc output, README/localized docs, ADR status, package verification, and the REA analysis skill metadata for the 90-tool/50-command inventory. Verification: npx vitest run tests/managedNativeVerification.test.ts --coverage=false; npm run typecheck; npm run docs:generate; npm run check (first run hit a load-sensitive sessionMcp timeout, isolated rerun passed); npx vitest run tests/sessionMcp.test.ts --coverage=false; npm run check; npm run knip; npm run jscpd; npm run scan:todos; npm run verify:managed; CXX=/usr/bin/g++-13 CC=/usr/bin/gcc-13 npm run verify:package.
This commit is contained in:
@@ -37,7 +37,7 @@ describe("browser MCP tools", () => {
|
||||
const connected = await connectBrowser(browser);
|
||||
|
||||
const tools = await connected.client.listTools();
|
||||
expect(tools.tools).toHaveLength(89);
|
||||
expect(tools.tools).toHaveLength(90);
|
||||
expect(tools.tools.map(({ name }) => name)).toEqual(
|
||||
expect.arrayContaining([
|
||||
"list_browser_targets",
|
||||
|
||||
@@ -66,7 +66,7 @@ describe("tool contract surface", () => {
|
||||
...ELECTRON_TOOL_CONTRACTS,
|
||||
...APPLICATION_TOOL_CONTRACTS,
|
||||
];
|
||||
expect(contracts).toHaveLength(71);
|
||||
expect(contracts).toHaveLength(72);
|
||||
for (const contract of contracts) {
|
||||
const inputSchema = contractJsonSchema(contract.inputSchema);
|
||||
const outputSchema = contractJsonSchema(contract.outputSchema);
|
||||
@@ -164,7 +164,7 @@ describe("tool contract surface", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("publishes no unconstrained output-schema holes across all 89 tools", () => {
|
||||
it("publishes no unconstrained output-schema holes across all 90 tools", () => {
|
||||
const contracts = [
|
||||
...OFFICIAL_TOOL_CONTRACTS,
|
||||
...ENHANCED_TOOL_CONTRACTS,
|
||||
@@ -177,7 +177,7 @@ describe("tool contract surface", () => {
|
||||
...APPLICATION_TOOL_CONTRACTS,
|
||||
...SESSION_TOOL_CONTRACTS,
|
||||
];
|
||||
expect(contracts).toHaveLength(89);
|
||||
expect(contracts).toHaveLength(90);
|
||||
for (const contract of contracts) {
|
||||
const schema = contractJsonSchema(contract.outputSchema);
|
||||
expect(emptySchemaPaths(schema), contract.name).toEqual([]);
|
||||
|
||||
@@ -131,7 +131,7 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the complete 89-tool inventory with a session", async () => {
|
||||
it("preserves the complete 90-tool inventory with a session", async () => {
|
||||
const session = new BinarySession(
|
||||
(_path) =>
|
||||
({
|
||||
@@ -154,7 +154,7 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
await client.connect(clientTransport);
|
||||
|
||||
const listed = await client.listTools();
|
||||
expect(listed.tools).toHaveLength(89);
|
||||
expect(listed.tools).toHaveLength(90);
|
||||
const names = listed.tools.map((t) => t.name);
|
||||
expect(names).toContain("open_binary");
|
||||
expect(names).toContain("close_binary");
|
||||
|
||||
@@ -11,6 +11,7 @@ import { AnalysisProviderRegistry } from "../src/application/AnalysisProviderReg
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { createPermissionAuthority } from "../src/application/PermissionAuthority.js";
|
||||
import { SessionProviderRouter } from "../src/application/SessionProviderRouter.js";
|
||||
import { MANAGED_NATIVE_VERIFICATION_EXAMPLE } from "../src/contracts/managedWorkflowExamples.js";
|
||||
import type { PermissionCeiling } from "../src/domain/permissionPolicy.js";
|
||||
import { ManagedStaticProvider } from "../src/dotnet/ManagedStaticProvider.js";
|
||||
import { createServer } from "../src/server/createServer.js";
|
||||
@@ -92,9 +93,28 @@ describe("managed artifact MCP tools", () => {
|
||||
expect(tools.tools.map(({ name }) => name)).toContain(
|
||||
"import_managed_reconstruction",
|
||||
);
|
||||
expect(tools.tools.map(({ name }) => name)).toContain(
|
||||
"verify_managed_native_boundaries",
|
||||
);
|
||||
expect(tools.tools.map(({ name }) => name)).toContain(
|
||||
"plan_managed_runtime_correlation",
|
||||
);
|
||||
const verifiedNative = structured(
|
||||
await client.callTool({
|
||||
name: "verify_managed_native_boundaries",
|
||||
arguments: MANAGED_NATIVE_VERIFICATION_EXAMPLE,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(verifiedNative).toMatchObject({
|
||||
operation: "verify_managed_native_boundaries",
|
||||
provider: { id: "rea-dotnet-workflows" },
|
||||
confidence: "inferred",
|
||||
normalized_result: {
|
||||
summary: { verified: 1 },
|
||||
algorithm: { token_to_address_mapping: "not-inferred" },
|
||||
},
|
||||
});
|
||||
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { verifyManagedNativeBoundariesEvidence } from "../src/application/ManagedNativeVerificationService.js";
|
||||
import { MANAGED_NATIVE_VERIFICATION_EXAMPLE } from "../src/contracts/managedWorkflowExamples.js";
|
||||
import { createEvidence } from "../src/domain/evidence.js";
|
||||
import {
|
||||
managedNativeVerificationInputSchema,
|
||||
verifyManagedNativeBoundaries,
|
||||
} from "../src/domain/managedNativeVerification.js";
|
||||
import { inspectMachoSchema } from "../src/domain/nativeInspection.js";
|
||||
|
||||
const exampleInput = () =>
|
||||
managedNativeVerificationInputSchema.parse(
|
||||
MANAGED_NATIVE_VERIFICATION_EXAMPLE,
|
||||
);
|
||||
|
||||
const nativeEvidenceWithExports = (names: readonly string[]) => {
|
||||
const input = exampleInput();
|
||||
const native = input.native_observations[0];
|
||||
if (native === undefined || native.subject === null)
|
||||
throw new Error("missing native example");
|
||||
const macho = inspectMachoSchema.parse(native.normalized_result);
|
||||
return createEvidence(
|
||||
{
|
||||
path: native.subject.local_path,
|
||||
sha256: native.subject.digest.sha256,
|
||||
format: native.subject.format,
|
||||
...(native.subject.architecture === null
|
||||
? {}
|
||||
: { architecture: native.subject.architecture }),
|
||||
},
|
||||
native.provider,
|
||||
{
|
||||
operation: native.operation,
|
||||
parameters: native.parameters,
|
||||
result: {
|
||||
...macho,
|
||||
exports: {
|
||||
...macho.exports,
|
||||
items: names.map((name, index) => ({
|
||||
name,
|
||||
address: `0x${(0x1000 + index).toString(16)}`,
|
||||
weak: false,
|
||||
reexport: false,
|
||||
source: "nm",
|
||||
})),
|
||||
total: names.length,
|
||||
},
|
||||
},
|
||||
rawResult: native.raw_result,
|
||||
confidence: native.confidence,
|
||||
authority: native.authority,
|
||||
environment: native.environment,
|
||||
limitations: native.limitations,
|
||||
locations: native.locations,
|
||||
evidenceLinks: native.evidence_links,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
describe("managed/native boundary verification", () => {
|
||||
it("verifies a P/Invoke declaration against native export Evidence", () => {
|
||||
const result = verifyManagedNativeBoundaries(exampleInput());
|
||||
|
||||
expect(result).toMatchObject({
|
||||
schema_version: 1,
|
||||
algorithm: {
|
||||
name: "rea-managed-native-verification",
|
||||
token_to_address_mapping: "not-inferred",
|
||||
},
|
||||
managed_boundary: {
|
||||
artifact_sha256: "6".repeat(64),
|
||||
mvid: "00112233-4455-4677-8899-aabbccddeeff",
|
||||
pinvoke_imports_total: 1,
|
||||
},
|
||||
native_observations: {
|
||||
total: 1,
|
||||
accepted: 1,
|
||||
unsupported: 0,
|
||||
symbols: 1,
|
||||
},
|
||||
summary: {
|
||||
verified: 1,
|
||||
inferred: 0,
|
||||
unresolved: 0,
|
||||
contradicted: 0,
|
||||
},
|
||||
pinvoke_imports: [
|
||||
{
|
||||
managed: {
|
||||
import_name: "open_native",
|
||||
import_scope_name: "nativehelper.dll",
|
||||
declaration_verification: "managed-declaration-only",
|
||||
},
|
||||
status: "verified",
|
||||
basis: "exact-export-name",
|
||||
confidence: "observed",
|
||||
matched_native: {
|
||||
name: "open_native",
|
||||
source: "macho-export",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(result.verification_id).toMatch(/^mnv_[a-f0-9]{64}$/u);
|
||||
expect(result.limitations.join(" ")).toContain(
|
||||
"does not prove CLR binding",
|
||||
);
|
||||
});
|
||||
|
||||
it("reports module mismatch as a contradiction within supplied Evidence", () => {
|
||||
const input = exampleInput();
|
||||
const native = input.native_observations[0];
|
||||
if (native === undefined || native.subject === null)
|
||||
throw new Error("missing native example");
|
||||
const mismatched = createEvidence(
|
||||
{
|
||||
path: "/examples/other.dll",
|
||||
sha256: native.subject.digest.sha256,
|
||||
format: "pe",
|
||||
...(native.subject.architecture === null
|
||||
? {}
|
||||
: { architecture: native.subject.architecture }),
|
||||
},
|
||||
native.provider,
|
||||
{
|
||||
operation: native.operation,
|
||||
parameters: native.parameters,
|
||||
result: native.normalized_result,
|
||||
rawResult: native.raw_result,
|
||||
confidence: native.confidence,
|
||||
authority: native.authority,
|
||||
environment: native.environment,
|
||||
limitations: native.limitations,
|
||||
locations: native.locations,
|
||||
evidenceLinks: native.evidence_links,
|
||||
},
|
||||
);
|
||||
|
||||
const result = verifyManagedNativeBoundaries({
|
||||
...input,
|
||||
native_observations: [mismatched],
|
||||
});
|
||||
|
||||
expect(result.summary).toMatchObject({
|
||||
verified: 0,
|
||||
contradicted: 1,
|
||||
});
|
||||
expect(result.pinvoke_imports[0]).toMatchObject({
|
||||
status: "contradicted",
|
||||
basis: "module-mismatch",
|
||||
});
|
||||
});
|
||||
|
||||
it("treats supported native Evidence with no symbols as unresolved", () => {
|
||||
const result = verifyManagedNativeBoundaries({
|
||||
...exampleInput(),
|
||||
native_observations: [nativeEvidenceWithExports([])],
|
||||
});
|
||||
|
||||
expect(result.native_observations).toMatchObject({
|
||||
accepted: 1,
|
||||
unsupported: 0,
|
||||
symbols: 0,
|
||||
});
|
||||
expect(result.summary).toMatchObject({
|
||||
verified: 0,
|
||||
unresolved: 1,
|
||||
});
|
||||
expect(result.pinvoke_imports[0]).toMatchObject({
|
||||
status: "unresolved",
|
||||
basis: "no-native-candidate",
|
||||
});
|
||||
});
|
||||
|
||||
it("reports omitted native candidates when candidate limits truncate matches", () => {
|
||||
const result = verifyManagedNativeBoundaries({
|
||||
...exampleInput(),
|
||||
native_observations: [
|
||||
nativeEvidenceWithExports(["open_native", "_open_native"]),
|
||||
],
|
||||
limits: { max_native_observations: 20, max_candidates_per_import: 1 },
|
||||
});
|
||||
|
||||
expect(result.coverage).toMatchObject({
|
||||
status: "truncated",
|
||||
omitted_candidates: 1,
|
||||
});
|
||||
expect(result.pinvoke_imports[0]?.candidates).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("wraps verification in derived workflow Evidence", () => {
|
||||
const evidence = verifyManagedNativeBoundariesEvidence(exampleInput());
|
||||
|
||||
expect(evidence.ok).toBe(true);
|
||||
if (!evidence.ok) return;
|
||||
expect(evidence.value).toMatchObject({
|
||||
operation: "verify_managed_native_boundaries",
|
||||
provider: { id: "rea-dotnet-workflows" },
|
||||
confidence: "inferred",
|
||||
authority: "analyst-inference",
|
||||
normalized_result: {
|
||||
summary: { verified: 1 },
|
||||
},
|
||||
});
|
||||
expect(evidence.value.evidence_links).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
@@ -121,6 +121,7 @@ describe("canonical product catalog", () => {
|
||||
"compare_managed_members",
|
||||
"import_managed_reconstruction",
|
||||
"plan_managed_runtime_correlation",
|
||||
"verify_managed_native_boundaries",
|
||||
]);
|
||||
expect(
|
||||
z.toJSONSchema(analysisSnapshotSchema).properties?.snapshot_version,
|
||||
|
||||
@@ -54,7 +54,7 @@ describe("guided prompts over MCP", () => {
|
||||
),
|
||||
);
|
||||
}
|
||||
expect((await client.listTools()).tools).toHaveLength(89);
|
||||
expect((await client.listTools()).tools).toHaveLength(90);
|
||||
const result = await client.getPrompt({
|
||||
name: "investigate_feature",
|
||||
arguments: {
|
||||
|
||||
@@ -10,7 +10,7 @@ const fixturePath = fileURLToPath(
|
||||
);
|
||||
|
||||
describe("production stdio runtime", () => {
|
||||
it("starts the built entrypoint, lists 89 tools, calls one, and shuts down", async () => {
|
||||
it("starts the built entrypoint, lists 90 tools, calls one, and shuts down", async () => {
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [mainPath],
|
||||
@@ -32,7 +32,7 @@ describe("production stdio runtime", () => {
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const tools = await client.listTools();
|
||||
expect(tools.tools).toHaveLength(89);
|
||||
expect(tools.tools).toHaveLength(90);
|
||||
const result = await client.callTool({
|
||||
name: "current_document",
|
||||
arguments: {},
|
||||
@@ -78,7 +78,7 @@ describe("production stdio runtime", () => {
|
||||
|
||||
try {
|
||||
await client.connect(transport);
|
||||
expect((await client.listTools()).tools).toHaveLength(89);
|
||||
expect((await client.listTools()).tools).toHaveLength(90);
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
|
||||
@@ -24,11 +24,11 @@ describe("server and catalog identity", () => {
|
||||
});
|
||||
expect(PRODUCT_IDENTITY.packageVersion).toBe(packageJson.version);
|
||||
expect(SDK_IDENTITY.server).toBe("2.0.0-beta.4");
|
||||
expect(CLI_COMMAND_NAMES).toHaveLength(49);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(49);
|
||||
expect(CLI_COMMAND_NAMES).toHaveLength(50);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(50);
|
||||
expect(CATALOG_IDENTITY.counts).toEqual({
|
||||
cli_commands: 49,
|
||||
mcp_tools: 89,
|
||||
cli_commands: 50,
|
||||
mcp_tools: 90,
|
||||
mcp_prompts: 6,
|
||||
mcp_resources: 2,
|
||||
mcp_resource_templates: 7,
|
||||
@@ -162,7 +162,7 @@ describe("server and catalog identity", () => {
|
||||
expect(status.structuredContent).toMatchObject({
|
||||
result: {
|
||||
server_identity: {
|
||||
catalog: { counts: { mcp_tools: 89, cli_commands: 49 } },
|
||||
catalog: { counts: { mcp_tools: 90, cli_commands: 50 } },
|
||||
alignment: { state: "mcp_server_restart_required" },
|
||||
},
|
||||
tool_availability: expect.arrayContaining([
|
||||
|
||||
@@ -142,7 +142,7 @@ describe("target-free MCP lifecycle", () => {
|
||||
expect(text(before)).toBe(
|
||||
"No app is open. Ask the user which app to investigate, then call open_binary with its local path.",
|
||||
);
|
||||
expect((await mcp.listTools()).tools).toHaveLength(89);
|
||||
expect((await mcp.listTools()).tools).toHaveLength(90);
|
||||
const deniedCapture = await mcp.callTool({
|
||||
name: "capture_process_scenario",
|
||||
arguments: {
|
||||
|
||||
@@ -15,7 +15,7 @@ import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolContracts.js";
|
||||
|
||||
describe("tool contract inventory", () => {
|
||||
it("publishes 71 analysis contracts and eighteen session tools", () => {
|
||||
it("publishes 72 analysis contracts and eighteen session tools", () => {
|
||||
expect(OFFICIAL_TOOL_CONTRACTS).toHaveLength(33);
|
||||
expect(ENHANCED_TOOL_CONTRACTS).toHaveLength(10);
|
||||
expect(NATIVE_TOOL_CONTRACTS).toHaveLength(5);
|
||||
@@ -27,6 +27,7 @@ describe("tool contract inventory", () => {
|
||||
]);
|
||||
expect(MANAGED_WORKFLOW_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
|
||||
"compare_managed_members",
|
||||
"verify_managed_native_boundaries",
|
||||
"import_managed_reconstruction",
|
||||
"plan_managed_runtime_correlation",
|
||||
]);
|
||||
@@ -71,8 +72,8 @@ describe("tool contract inventory", () => {
|
||||
"update_unknown",
|
||||
"verify_unknown_resolution",
|
||||
]);
|
||||
expect(TOOL_CONTRACTS).toHaveLength(89);
|
||||
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(89);
|
||||
expect(TOOL_CONTRACTS).toHaveLength(90);
|
||||
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(90);
|
||||
});
|
||||
|
||||
it("retains documented enhanced-tool limits at the input boundary", () => {
|
||||
|
||||
Reference in New Issue
Block a user