feat(dotnet): import managed reconstructions

This commit is contained in:
N0zoM1z0
2026-07-16 20:37:42 +09:00
committed by N0zoM1z0
parent 798631ade6
commit c506664744
88 changed files with 1251 additions and 212 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ describe("browser MCP tools", () => {
const connected = await connectBrowser(browser);
const tools = await connected.client.listTools();
expect(tools.tools).toHaveLength(88);
expect(tools.tools).toHaveLength(89);
expect(tools.tools.map(({ name }) => name)).toEqual(
expect.arrayContaining([
"list_browser_targets",
+3 -3
View File
@@ -66,7 +66,7 @@ describe("tool contract surface", () => {
...ELECTRON_TOOL_CONTRACTS,
...APPLICATION_TOOL_CONTRACTS,
];
expect(contracts).toHaveLength(70);
expect(contracts).toHaveLength(71);
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 88 tools", () => {
it("publishes no unconstrained output-schema holes across all 89 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(88);
expect(contracts).toHaveLength(89);
for (const contract of contracts) {
const schema = contractJsonSchema(contract.outputSchema);
expect(emptySchemaPaths(schema), contract.name).toEqual([]);
+2 -2
View File
@@ -131,7 +131,7 @@ describe("full MCP integration with multi-tool sequences", () => {
});
});
it("preserves the complete 88-tool inventory with a session", async () => {
it("preserves the complete 89-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(88);
expect(listed.tools).toHaveLength(89);
const names = listed.tools.map((t) => t.name);
expect(names).toContain("open_binary");
expect(names).toContain("close_binary");
+47
View File
@@ -89,6 +89,9 @@ describe("managed artifact MCP tools", () => {
expect(tools.tools.map(({ name }) => name)).toContain(
"compare_managed_members",
);
expect(tools.tools.map(({ name }) => name)).toContain(
"import_managed_reconstruction",
);
expect(tools.tools.map(({ name }) => name)).toContain(
"plan_managed_runtime_correlation",
);
@@ -205,6 +208,50 @@ describe("managed artifact MCP tools", () => {
.parse(method).items[0];
expect(methodItem).toBeDefined();
if (methodItem === undefined) return;
const imported = structured(
await client.callTool({
name: "import_managed_reconstruction",
arguments: {
static_members: members,
decompiler: {
name: "ilspycmd",
version: "9.1.0.7988",
family: "ilspy",
executable_sha256: null,
options: ["--type", "Example.Program"],
},
methods: [
{
token: methodItem.token,
signature_sha256: methodItem.signature.raw_sha256,
normalized_il_sha256: methodItem.body.normalized_il_sha256,
reconstruction: {
kind: "decompiled-csharp",
language: "csharp",
text: "internal static void Main() { }",
},
},
],
notes: ["synthetic MCP import"],
},
}),
);
expect(imported).toMatchObject({
operation: "import_managed_reconstruction",
provider: { id: "rea-dotnet-workflows" },
confidence: "inferred",
normalized_result: {
executed: false,
summary: { imported_methods: 1, decompiled_csharp_methods: 1 },
methods: [
{
token: methodItem.token,
validation: { canonical_observation: false },
},
],
},
});
const planned = structured(
await client.callTool({
name: "plan_managed_runtime_correlation",
+123
View File
@@ -0,0 +1,123 @@
import { createHash } from "node:crypto";
import { describe, expect, it } from "vitest";
import { importManagedReconstructionEvidence } from "../src/application/ManagedReconstructionService.js";
import { MANAGED_RECONSTRUCTION_IMPORT_EXAMPLE } from "../src/contracts/managedWorkflowExamples.js";
import {
importManagedReconstruction,
managedReconstructionImportInputSchema,
} from "../src/domain/managedReconstruction.js";
const exampleInput = () =>
managedReconstructionImportInputSchema.parse(
MANAGED_RECONSTRUCTION_IMPORT_EXAMPLE,
);
const exampleMethod = () => {
const method = exampleInput().methods[0];
if (method === undefined) throw new Error("missing example method");
return method;
};
describe("managed decompiler reconstruction import", () => {
it("imports decompiler output as inference locked to static IL evidence", () => {
const result = importManagedReconstruction(exampleInput());
expect(result).toMatchObject({
schema_version: 1,
phase: "reconstruction-import",
executed: false,
static_observation: {
artifact_sha256: "2".repeat(64),
mvid: "11112222-3333-4444-9555-666677778888",
},
decompiler: {
name: "ilspycmd",
version: "9.1.0.7988",
family: "ilspy",
},
summary: {
imported_methods: 1,
decompiled_csharp_methods: 1,
},
methods: [
{
token: "0x06000001",
signature_sha256: "3".repeat(64),
normalized_il_sha256: "5".repeat(64),
validation: {
matched_static_member: true,
exact_build_required: true,
canonical_observation: false,
confidence_floor: "inference",
},
},
],
});
expect(result.reconstruction_id).toMatch(/^mre_[a-f0-9]{64}$/u);
expect(result.methods[0]?.reconstruction.text_sha256).toBe(
createHash("sha256")
.update("internal static void Main() { }")
.digest("hex"),
);
expect(result.limitations.join(" ")).toContain(
"metadata and IL observations remain canonical",
);
});
it("rejects reconstruction text hash drift", () => {
expect(() =>
importManagedReconstruction({
...exampleInput(),
methods: [
{
...exampleMethod(),
reconstruction: {
...exampleMethod().reconstruction,
text_sha256: "0".repeat(64),
},
},
],
}),
).toThrow(/text hash mismatch/u);
});
it("rejects stale method locks", () => {
expect(() =>
importManagedReconstruction({
...exampleInput(),
methods: [
{
...exampleMethod(),
normalized_il_sha256: "6".repeat(64),
},
],
}),
).toThrow(/does not match/u);
});
it("wraps imported reconstruction in Evidence v2", () => {
const evidence = importManagedReconstructionEvidence(exampleInput());
expect(evidence.ok).toBe(true);
if (!evidence.ok) return;
expect(evidence.value).toMatchObject({
operation: "import_managed_reconstruction",
provider: { id: "rea-dotnet-workflows" },
confidence: "inferred",
authority: "analyst-inference",
normalized_result: {
phase: "reconstruction-import",
methods: [
{
reconstruction: {
kind: "decompiled-csharp",
language: "csharp",
},
},
],
},
});
});
});
+5 -1
View File
@@ -117,7 +117,11 @@ describe("canonical product catalog", () => {
expect(
catalog.providers.find(({ id }) => id === MANAGED_WORKFLOW_PROVIDER.id)
?.capabilities,
).toEqual(["compare_managed_members", "plan_managed_runtime_correlation"]);
).toEqual([
"compare_managed_members",
"import_managed_reconstruction",
"plan_managed_runtime_correlation",
]);
expect(
z.toJSONSchema(analysisSnapshotSchema).properties?.snapshot_version,
).toMatchObject({
+1 -1
View File
@@ -54,7 +54,7 @@ describe("guided prompts over MCP", () => {
),
);
}
expect((await client.listTools()).tools).toHaveLength(88);
expect((await client.listTools()).tools).toHaveLength(89);
const result = await client.getPrompt({
name: "investigate_feature",
arguments: {
+3 -3
View File
@@ -10,7 +10,7 @@ const fixturePath = fileURLToPath(
);
describe("production stdio runtime", () => {
it("starts the built entrypoint, lists 88 tools, calls one, and shuts down", async () => {
it("starts the built entrypoint, lists 89 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(88);
expect(tools.tools).toHaveLength(89);
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(88);
expect((await client.listTools()).tools).toHaveLength(89);
} finally {
await client.close();
await transport.close();
+5 -5
View File
@@ -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(48);
expect(new Set(CLI_COMMAND_NAMES).size).toBe(48);
expect(CLI_COMMAND_NAMES).toHaveLength(49);
expect(new Set(CLI_COMMAND_NAMES).size).toBe(49);
expect(CATALOG_IDENTITY.counts).toEqual({
cli_commands: 48,
mcp_tools: 88,
cli_commands: 49,
mcp_tools: 89,
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: 88, cli_commands: 48 } },
catalog: { counts: { mcp_tools: 89, cli_commands: 49 } },
alignment: { state: "mcp_server_restart_required" },
},
tool_availability: expect.arrayContaining([
+1 -1
View File
@@ -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(88);
expect((await mcp.listTools()).tools).toHaveLength(89);
const deniedCapture = await mcp.callTool({
name: "capture_process_scenario",
arguments: {
+4 -3
View File
@@ -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 70 analysis contracts and eighteen session tools", () => {
it("publishes 71 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",
"import_managed_reconstruction",
"plan_managed_runtime_correlation",
]);
expect(BROWSER_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
@@ -70,8 +71,8 @@ describe("tool contract inventory", () => {
"update_unknown",
"verify_unknown_resolution",
]);
expect(TOOL_CONTRACTS).toHaveLength(88);
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(88);
expect(TOOL_CONTRACTS).toHaveLength(89);
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(89);
});
it("retains documented enhanced-tool limits at the input boundary", () => {