feat(dotnet): add managed artifact triage
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(83);
|
||||
expect(tools.tools).toHaveLength(84);
|
||||
expect(tools.tools.map(({ name }) => name)).toEqual(
|
||||
expect.arrayContaining([
|
||||
"list_browser_targets",
|
||||
|
||||
@@ -8,11 +8,13 @@ import {
|
||||
} from "../src/contracts/toolContracts.js";
|
||||
import { NATIVE_TOOL_CONTRACTS } from "../src/contracts/nativeToolContracts.js";
|
||||
import { ARTIFACT_TOOL_CONTRACTS } from "../src/contracts/artifactToolContracts.js";
|
||||
import { MANAGED_TOOL_CONTRACTS } from "../src/contracts/managedToolContracts.js";
|
||||
import { BROWSER_TOOL_CONTRACTS } from "../src/contracts/browserToolContracts.js";
|
||||
import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.js";
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolContracts.js";
|
||||
import {
|
||||
enhancedOutputSchemas,
|
||||
managedOutputSchemas,
|
||||
officialOutputSchemas,
|
||||
sessionOutputSchemas,
|
||||
} from "../src/contracts/toolOutputSchemas.js";
|
||||
@@ -56,11 +58,12 @@ describe("tool contract surface", () => {
|
||||
...ENHANCED_TOOL_CONTRACTS,
|
||||
...NATIVE_TOOL_CONTRACTS,
|
||||
...ARTIFACT_TOOL_CONTRACTS,
|
||||
...MANAGED_TOOL_CONTRACTS,
|
||||
...BROWSER_TOOL_CONTRACTS,
|
||||
...ELECTRON_TOOL_CONTRACTS,
|
||||
...APPLICATION_TOOL_CONTRACTS,
|
||||
];
|
||||
expect(contracts).toHaveLength(65);
|
||||
expect(contracts).toHaveLength(66);
|
||||
for (const contract of contracts) {
|
||||
const inputSchema = contractJsonSchema(contract.inputSchema);
|
||||
const outputSchema = contractJsonSchema(contract.outputSchema);
|
||||
@@ -137,10 +140,14 @@ describe("tool contract surface", () => {
|
||||
expect(Object.keys(sessionOutputSchemas).sort()).toEqual(
|
||||
SESSION_TOOL_CONTRACTS.map(({ name }) => name).sort(),
|
||||
);
|
||||
expect(Object.keys(managedOutputSchemas).sort()).toEqual(
|
||||
MANAGED_TOOL_CONTRACTS.map(({ name }) => name).sort(),
|
||||
);
|
||||
|
||||
for (const contract of [
|
||||
...OFFICIAL_TOOL_CONTRACTS,
|
||||
...ENHANCED_TOOL_CONTRACTS,
|
||||
...MANAGED_TOOL_CONTRACTS,
|
||||
...SESSION_TOOL_CONTRACTS,
|
||||
]) {
|
||||
const schema = contractJsonSchema(contract.outputSchema);
|
||||
@@ -150,18 +157,19 @@ describe("tool contract surface", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("publishes no unconstrained output-schema holes across all 83 tools", () => {
|
||||
it("publishes no unconstrained output-schema holes across all 84 tools", () => {
|
||||
const contracts = [
|
||||
...OFFICIAL_TOOL_CONTRACTS,
|
||||
...ENHANCED_TOOL_CONTRACTS,
|
||||
...NATIVE_TOOL_CONTRACTS,
|
||||
...ARTIFACT_TOOL_CONTRACTS,
|
||||
...MANAGED_TOOL_CONTRACTS,
|
||||
...BROWSER_TOOL_CONTRACTS,
|
||||
...ELECTRON_TOOL_CONTRACTS,
|
||||
...APPLICATION_TOOL_CONTRACTS,
|
||||
...SESSION_TOOL_CONTRACTS,
|
||||
];
|
||||
expect(contracts).toHaveLength(83);
|
||||
expect(contracts).toHaveLength(84);
|
||||
for (const contract of contracts) {
|
||||
const schema = contractJsonSchema(contract.outputSchema);
|
||||
expect(emptySchemaPaths(schema), contract.name).toEqual([]);
|
||||
|
||||
Vendored
+306
@@ -0,0 +1,306 @@
|
||||
interface ManagedPeFixtureOptions {
|
||||
readonly cliFlags?: number;
|
||||
readonly corruptMetadataSignature?: boolean;
|
||||
readonly metadataValidMaskExtra?: bigint;
|
||||
readonly readyToRun?: boolean;
|
||||
readonly references?: readonly string[];
|
||||
readonly resourceData?: Buffer;
|
||||
readonly targetFramework?: string;
|
||||
}
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
|
||||
const align4 = (value: number): number => (value + 3) & ~3;
|
||||
|
||||
const cString = (value: string): Buffer => Buffer.from(`${value}\0`, "utf8");
|
||||
|
||||
class StringHeap {
|
||||
readonly #chunks: Buffer[] = [Buffer.from([0])];
|
||||
#size = 1;
|
||||
|
||||
add(value: string): number {
|
||||
if (value.length === 0) return 0;
|
||||
const index = this.#size;
|
||||
const chunk = cString(value);
|
||||
this.#chunks.push(chunk);
|
||||
this.#size += chunk.length;
|
||||
return index;
|
||||
}
|
||||
|
||||
toBuffer(): Buffer {
|
||||
return Buffer.concat(this.#chunks);
|
||||
}
|
||||
}
|
||||
|
||||
class BlobHeap {
|
||||
readonly #chunks: Buffer[] = [Buffer.from([0])];
|
||||
#size = 1;
|
||||
|
||||
add(value: Buffer): number {
|
||||
if (value.length === 0) return 0;
|
||||
if (value.length > 0x7f)
|
||||
throw new RangeError("Managed PE fixture blob is too large");
|
||||
const index = this.#size;
|
||||
this.#chunks.push(Buffer.from([value.length]), value);
|
||||
this.#size += value.length + 1;
|
||||
return index;
|
||||
}
|
||||
|
||||
toBuffer(): Buffer {
|
||||
return Buffer.concat(this.#chunks);
|
||||
}
|
||||
}
|
||||
|
||||
const guidHeap = (): Buffer =>
|
||||
Buffer.from([
|
||||
0x33, 0x22, 0x11, 0x00, 0x55, 0x44, 0x77, 0x66, 0x88, 0x99, 0xaa, 0xbb,
|
||||
0xcc, 0xdd, 0xee, 0xff,
|
||||
]);
|
||||
|
||||
const u16 = (value: number): Buffer => {
|
||||
const bytes = Buffer.alloc(2);
|
||||
bytes.writeUInt16LE(value, 0);
|
||||
return bytes;
|
||||
};
|
||||
|
||||
const u32 = (value: number): Buffer => {
|
||||
const bytes = Buffer.alloc(4);
|
||||
bytes.writeUInt32LE(value, 0);
|
||||
return bytes;
|
||||
};
|
||||
|
||||
const moduleRow = (name: number): Buffer =>
|
||||
Buffer.concat([u16(0), u16(name), u16(1), u16(0), u16(0)]);
|
||||
|
||||
const typeRefRow = (name: number, namespace: number): Buffer =>
|
||||
Buffer.concat([u16(0), u16(name), u16(namespace)]);
|
||||
|
||||
const methodDefRow = (name: number, signature: number): Buffer =>
|
||||
Buffer.concat([u32(0), u16(0), u16(0), u16(name), u16(signature), u16(0)]);
|
||||
|
||||
const memberRefRow = (name: number, signature: number): Buffer =>
|
||||
Buffer.concat([u16((1 << 3) | 1), u16(name), u16(signature)]);
|
||||
|
||||
const assemblyRow = (name: number): Buffer =>
|
||||
Buffer.concat([
|
||||
u32(0x0000_8004),
|
||||
u16(1),
|
||||
u16(2),
|
||||
u16(3),
|
||||
u16(4),
|
||||
u32(0),
|
||||
u16(0),
|
||||
u16(name),
|
||||
u16(0),
|
||||
]);
|
||||
|
||||
const assemblyRefRow = (name: number, keyOrToken: number): Buffer =>
|
||||
Buffer.concat([
|
||||
u16(8),
|
||||
u16(0),
|
||||
u16(0),
|
||||
u16(0),
|
||||
u32(0),
|
||||
u16(keyOrToken),
|
||||
u16(name),
|
||||
u16(0),
|
||||
u16(0),
|
||||
]);
|
||||
|
||||
const customAttributeRow = (value: number): Buffer =>
|
||||
Buffer.concat([u16((1 << 5) | 14), u16((1 << 3) | 3), u16(value)]);
|
||||
|
||||
const manifestResourceRow = (name: number): Buffer =>
|
||||
Buffer.concat([u32(0), u32(2), u16(name), u16(0)]);
|
||||
|
||||
const fixedStringAttributeBlob = (value: string): Buffer => {
|
||||
const bytes = Buffer.from(textEncoder.encode(value));
|
||||
if (bytes.length > 0x7f)
|
||||
throw new RangeError("Managed PE fixture target framework is too long");
|
||||
return Buffer.concat([Buffer.from([1, 0, bytes.length]), bytes, u16(0)]);
|
||||
};
|
||||
|
||||
const metadataStreamHeader = (
|
||||
relativeOffset: number,
|
||||
size: number,
|
||||
name: string,
|
||||
): Buffer => {
|
||||
const named = cString(name);
|
||||
const paddedName = Buffer.alloc(align4(named.length));
|
||||
named.copy(paddedName);
|
||||
return Buffer.concat([u32(relativeOffset), u32(size), paddedName]);
|
||||
};
|
||||
|
||||
const metadataRoot = (
|
||||
tables: Buffer,
|
||||
strings: Buffer,
|
||||
guid: Buffer,
|
||||
blob: Buffer,
|
||||
): Buffer => {
|
||||
const version = Buffer.from("v4.0.30319\0\0", "utf8");
|
||||
const header = Buffer.concat([
|
||||
u32(0x424a_5342),
|
||||
u16(1),
|
||||
u16(1),
|
||||
u32(0),
|
||||
u32(version.length),
|
||||
version,
|
||||
u16(0),
|
||||
u16(4),
|
||||
]);
|
||||
const streamHeaderSize =
|
||||
metadataStreamHeader(0, 0, "#~").length +
|
||||
metadataStreamHeader(0, 0, "#Strings").length +
|
||||
metadataStreamHeader(0, 0, "#GUID").length +
|
||||
metadataStreamHeader(0, 0, "#Blob").length;
|
||||
let offset = align4(header.length + streamHeaderSize);
|
||||
const tablesOffset = offset;
|
||||
offset = align4(offset + tables.length);
|
||||
const stringsOffset = offset;
|
||||
offset = align4(offset + strings.length);
|
||||
const guidOffset = offset;
|
||||
offset = align4(offset + guid.length);
|
||||
const blobOffset = offset;
|
||||
const headers = Buffer.concat([
|
||||
metadataStreamHeader(tablesOffset, tables.length, "#~"),
|
||||
metadataStreamHeader(stringsOffset, strings.length, "#Strings"),
|
||||
metadataStreamHeader(guidOffset, guid.length, "#GUID"),
|
||||
metadataStreamHeader(blobOffset, blob.length, "#Blob"),
|
||||
]);
|
||||
const root = Buffer.alloc(align4(blobOffset + blob.length));
|
||||
header.copy(root, 0);
|
||||
headers.copy(root, header.length);
|
||||
tables.copy(root, tablesOffset);
|
||||
strings.copy(root, stringsOffset);
|
||||
guid.copy(root, guidOffset);
|
||||
blob.copy(root, blobOffset);
|
||||
return root;
|
||||
};
|
||||
|
||||
const tablesStream = (
|
||||
rows: ReadonlyMap<number, readonly Buffer[]>,
|
||||
extraValidMask: bigint,
|
||||
): Buffer => {
|
||||
let valid = extraValidMask;
|
||||
for (const table of rows.keys()) valid |= 1n << BigInt(table);
|
||||
const header = Buffer.alloc(24);
|
||||
header.writeUInt8(2, 4);
|
||||
header.writeUInt8(1, 7);
|
||||
header.writeBigUInt64LE(valid, 8);
|
||||
const counts: Buffer[] = [];
|
||||
for (let index = 0; index <= 44; index += 1) {
|
||||
const tableRows = rows.get(index);
|
||||
if (tableRows === undefined) continue;
|
||||
counts.push(u32(tableRows.length));
|
||||
}
|
||||
const data: Buffer[] = [];
|
||||
for (let index = 0; index <= 44; index += 1) {
|
||||
const tableRows = rows.get(index);
|
||||
if (tableRows === undefined) continue;
|
||||
data.push(...tableRows);
|
||||
}
|
||||
return Buffer.concat([header, ...counts, ...data]);
|
||||
};
|
||||
|
||||
/** Build a source-owned PE32/CLI fixture without committing compiled binaries. */
|
||||
export const buildManagedPeFixture = (
|
||||
options: ManagedPeFixtureOptions = {},
|
||||
): Buffer => {
|
||||
const strings = new StringHeap();
|
||||
const blobs = new BlobHeap();
|
||||
const moduleName = strings.add("Fixture.dll");
|
||||
const assemblyName = strings.add("Fixture.Managed");
|
||||
const attributeName = strings.add("TargetFrameworkAttribute");
|
||||
const attributeNamespace = strings.add("System.Runtime.Versioning");
|
||||
const constructorName = strings.add(".ctor");
|
||||
const methodName = strings.add("Main");
|
||||
const resourceName = strings.add("Fixture.resources");
|
||||
const referenceNames = options.references ?? ["System.Runtime"];
|
||||
const referenceStringIndexes = referenceNames.map((name) =>
|
||||
strings.add(name),
|
||||
);
|
||||
const tokenBlob = blobs.add(Buffer.from("b77a5c561934e089", "hex"));
|
||||
const methodSignature = blobs.add(Buffer.from([0x00, 0x00]));
|
||||
const constructorSignature = blobs.add(Buffer.from([0x20, 0x01, 0x01]));
|
||||
const attributeBlob = blobs.add(
|
||||
fixedStringAttributeBlob(
|
||||
options.targetFramework ?? ".NETCoreApp,Version=v8.0",
|
||||
),
|
||||
);
|
||||
const rows = new Map<number, readonly Buffer[]>([
|
||||
[0, [moduleRow(moduleName)]],
|
||||
[1, [typeRefRow(attributeName, attributeNamespace)]],
|
||||
[6, [methodDefRow(methodName, methodSignature)]],
|
||||
[10, [memberRefRow(constructorName, constructorSignature)]],
|
||||
[12, [customAttributeRow(attributeBlob)]],
|
||||
[32, [assemblyRow(assemblyName)]],
|
||||
[35, referenceStringIndexes.map((name) => assemblyRefRow(name, tokenBlob))],
|
||||
[40, [manifestResourceRow(resourceName)]],
|
||||
]);
|
||||
const metadata = metadataRoot(
|
||||
tablesStream(rows, options.metadataValidMaskExtra ?? 0n),
|
||||
strings.toBuffer(),
|
||||
guidHeap(),
|
||||
blobs.toBuffer(),
|
||||
);
|
||||
if (options.corruptMetadataSignature === true) metadata.writeUInt32LE(0, 0);
|
||||
const resourceData = options.resourceData ?? Buffer.from("resource-data");
|
||||
const resourceDirectory = Buffer.concat([
|
||||
u32(resourceData.length),
|
||||
resourceData,
|
||||
]);
|
||||
const image = Buffer.alloc(0x1000);
|
||||
image.write("MZ", 0, "ascii");
|
||||
image.writeUInt32LE(0x80, 0x3c);
|
||||
image.writeUInt32LE(0x0000_4550, 0x80);
|
||||
const coff = 0x84;
|
||||
image.writeUInt16LE(0x014c, coff);
|
||||
image.writeUInt16LE(1, coff + 2);
|
||||
image.writeUInt16LE(0x00e0, coff + 16);
|
||||
image.writeUInt16LE(0x0102, coff + 18);
|
||||
const optional = coff + 20;
|
||||
image.writeUInt16LE(0x010b, optional);
|
||||
image.writeUInt32LE(0x2000, optional + 20);
|
||||
image.writeUInt32LE(0x0040_0000, optional + 28);
|
||||
image.writeUInt32LE(0x1000, optional + 32);
|
||||
image.writeUInt32LE(0x200, optional + 36);
|
||||
image.writeUInt32LE(0x3000, optional + 56);
|
||||
image.writeUInt32LE(0x200, optional + 60);
|
||||
image.writeUInt32LE(16, optional + 92);
|
||||
image.writeUInt32LE(0x2000, optional + 96 + 14 * 8);
|
||||
image.writeUInt32LE(72, optional + 96 + 14 * 8 + 4);
|
||||
const section = optional + 0x00e0;
|
||||
image.write(".text\0\0\0", section, "ascii");
|
||||
image.writeUInt32LE(0x1000, section + 8);
|
||||
image.writeUInt32LE(0x2000, section + 12);
|
||||
image.writeUInt32LE(0x0e00, section + 16);
|
||||
image.writeUInt32LE(0x0200, section + 20);
|
||||
image.writeUInt32LE(0x6000_0020, section + 36);
|
||||
const cli = 0x0200;
|
||||
image.writeUInt32LE(72, cli);
|
||||
image.writeUInt16LE(2, cli + 4);
|
||||
image.writeUInt16LE(5, cli + 6);
|
||||
image.writeUInt32LE(0x2100, cli + 8);
|
||||
image.writeUInt32LE(metadata.length, cli + 12);
|
||||
image.writeUInt32LE(options.cliFlags ?? 1, cli + 16);
|
||||
image.writeUInt32LE(0x0600_0001, cli + 20);
|
||||
image.writeUInt32LE(0x2600, cli + 24);
|
||||
image.writeUInt32LE(resourceDirectory.length, cli + 28);
|
||||
if (options.readyToRun === true) {
|
||||
image.writeUInt32LE(0x2700, cli + 64);
|
||||
image.writeUInt32LE(4, cli + 68);
|
||||
image.write("RTR\0", 0x0900, "ascii");
|
||||
}
|
||||
metadata.copy(image, 0x0300);
|
||||
resourceDirectory.copy(image, 0x0800);
|
||||
return image;
|
||||
};
|
||||
|
||||
/** Build a syntactically valid PE32 fixture with no CLI directory. */
|
||||
export const buildNativePeFixture = (): Buffer => {
|
||||
const image = buildManagedPeFixture();
|
||||
const cliDirectory = 0x84 + 20 + 96 + 14 * 8;
|
||||
image.writeUInt32LE(0, cliDirectory);
|
||||
image.writeUInt32LE(0, cliDirectory + 4);
|
||||
return image;
|
||||
};
|
||||
@@ -131,7 +131,7 @@ describe("full MCP integration with multi-tool sequences", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the complete 83-tool inventory with a session", async () => {
|
||||
it("preserves the complete 84-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(83);
|
||||
expect(listed.tools).toHaveLength(84);
|
||||
const names = listed.tools.map((t) => t.name);
|
||||
expect(names).toContain("open_binary");
|
||||
expect(names).toContain("close_binary");
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { runProviderAnalysis } from "../src/application/DirectAnalysis.js";
|
||||
import type { AnalysisExecution } from "../src/application/AnalysisProvider.js";
|
||||
import { managedArtifactInspectionSchema } from "../src/domain/managedArtifact.js";
|
||||
import type { BinaryTarget } from "../src/domain/binaryTarget.js";
|
||||
import { parseBinaryTarget } from "../src/domain/binaryTarget.js";
|
||||
import { parseEvidence } from "../src/domain/evidence.js";
|
||||
import { ManagedStaticProvider } from "../src/dotnet/ManagedStaticProvider.js";
|
||||
import { inspectManagedArtifactBytes } from "../src/dotnet/ManagedArtifactInspector.js";
|
||||
import {
|
||||
buildManagedPeFixture,
|
||||
buildNativePeFixture,
|
||||
} from "./fixtures/managedPe.js";
|
||||
|
||||
const limits = {
|
||||
referenceOffset: 0,
|
||||
referenceLimit: 100,
|
||||
resourceOffset: 0,
|
||||
resourceLimit: 100,
|
||||
attributeOffset: 0,
|
||||
attributeLimit: 100,
|
||||
maxMetadataBytes: 1024 * 1024,
|
||||
maxTableRows: 1_000,
|
||||
maxHeapItemBytes: 1024 * 1024,
|
||||
};
|
||||
|
||||
describe("managed PE/CLI static provider", () => {
|
||||
it("inventories module, assembly, framework, references, and resources without loading CLR code", () => {
|
||||
const resource = Buffer.from("source-owned resource");
|
||||
const bytes = buildManagedPeFixture({ resourceData: resource });
|
||||
const result = inspectManagedArtifactBytes(bytes, target(bytes), limits);
|
||||
|
||||
expect(result.classification).toMatchObject({
|
||||
status: "managed",
|
||||
runtime_family: "modern-dotnet",
|
||||
implementation: "cil",
|
||||
managed_architecture: "anycpu",
|
||||
});
|
||||
expect(result.pe.cli).toMatchObject({
|
||||
flag_names: ["il-only"],
|
||||
entry_point: { kind: "metadata-token", value: "0x06000001" },
|
||||
});
|
||||
expect(result.module).toMatchObject({
|
||||
name: "Fixture.dll",
|
||||
mvid: "00112233-4455-6677-8899-aabbccddeeff",
|
||||
token: "0x00000001",
|
||||
});
|
||||
expect(result.assembly).toMatchObject({
|
||||
name: "Fixture.Managed",
|
||||
version: "1.2.3.4",
|
||||
token: "0x20000001",
|
||||
});
|
||||
expect(result.target_frameworks).toEqual([".NETCoreApp,Version=v8.0"]);
|
||||
expect(result.references).toMatchObject({
|
||||
total: 1,
|
||||
returned: 1,
|
||||
complete: true,
|
||||
items: [expect.objectContaining({ name: "System.Runtime" })],
|
||||
});
|
||||
expect(result.resources.items).toEqual([
|
||||
expect.objectContaining({
|
||||
name: "Fixture.resources",
|
||||
embedded: true,
|
||||
visibility: "private",
|
||||
data_length: resource.length,
|
||||
data_sha256: createHash("sha256").update(resource).digest("hex"),
|
||||
}),
|
||||
]);
|
||||
expect(result.coverage).toMatchObject({ state: "complete", issues: [] });
|
||||
});
|
||||
|
||||
it("keeps classification evidence complete when caller pages visible references", () => {
|
||||
const bytes = buildManagedPeFixture({
|
||||
references: ["System.Runtime", "UnityEngine.CoreModule"],
|
||||
});
|
||||
const result = inspectManagedArtifactBytes(bytes, target(bytes), {
|
||||
...limits,
|
||||
referenceLimit: 1,
|
||||
});
|
||||
|
||||
expect(result.classification.runtime_family).toBe("unity-mono");
|
||||
expect(result.references).toMatchObject({
|
||||
total: 2,
|
||||
returned: 1,
|
||||
complete: false,
|
||||
});
|
||||
expect(result.coverage.state).toBe("partial");
|
||||
expect(result.coverage.issues).toEqual([]);
|
||||
});
|
||||
|
||||
it("reports native PE, malformed metadata, and bounded metadata failures as typed results", () => {
|
||||
const native = inspectManagedArtifactBytes(
|
||||
buildNativePeFixture(),
|
||||
target(buildNativePeFixture()),
|
||||
limits,
|
||||
);
|
||||
expect(native.classification.status).toBe("not-managed");
|
||||
expect(native.metadata.status).toBe("absent");
|
||||
expect(native.coverage.state).toBe("unavailable");
|
||||
|
||||
const malformedBytes = buildManagedPeFixture({
|
||||
corruptMetadataSignature: true,
|
||||
});
|
||||
const malformed = inspectManagedArtifactBytes(
|
||||
malformedBytes,
|
||||
target(malformedBytes),
|
||||
limits,
|
||||
);
|
||||
expect(malformed.classification.status).toBe("malformed");
|
||||
expect(malformed.coverage.issues).toEqual([
|
||||
expect.objectContaining({ code: "invalid-metadata-root" }),
|
||||
]);
|
||||
|
||||
const unsupportedTableBytes = buildManagedPeFixture({
|
||||
metadataValidMaskExtra: 1n << 50n,
|
||||
});
|
||||
const unsupportedTable = inspectManagedArtifactBytes(
|
||||
unsupportedTableBytes,
|
||||
target(unsupportedTableBytes),
|
||||
limits,
|
||||
);
|
||||
expect(unsupportedTable.coverage.issues).toEqual([
|
||||
expect.objectContaining({ code: "invalid-tables" }),
|
||||
]);
|
||||
|
||||
const limited = inspectManagedArtifactBytes(
|
||||
buildManagedPeFixture(),
|
||||
target(buildManagedPeFixture()),
|
||||
{ ...limits, maxMetadataBytes: 256 },
|
||||
);
|
||||
expect(limited.metadata.status).toBe("partial");
|
||||
expect(limited.coverage.issues).toEqual([
|
||||
expect.objectContaining({ code: "limit-exceeded" }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("executes as a read-only auxiliary provider with digest, cancellation, and format boundaries", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-provider-"));
|
||||
const bytes = buildManagedPeFixture();
|
||||
const path = join(directory, "fixture.exe");
|
||||
await writeFile(path, bytes);
|
||||
const parsed = await parseBinaryTarget(path);
|
||||
expect(parsed.ok).toBe(true);
|
||||
if (!parsed.ok) return;
|
||||
|
||||
const client = new ManagedStaticProvider().createClient(parsed.value);
|
||||
const observed = await client.execute("inspect_managed_artifact", {});
|
||||
expect(observed.ok).toBe(true);
|
||||
if (!observed.ok) return;
|
||||
expect(asManagedResult(observed.value)).toMatchObject({
|
||||
classification: { status: "managed", runtime_family: "modern-dotnet" },
|
||||
artifact: { path, sha256: parsed.value.sha256, format: "pe" },
|
||||
});
|
||||
expect(observed.value.provider.id).toBe("rea-dotnet-static");
|
||||
expect(observed.value.subject).toMatchObject({ path, format: "pe" });
|
||||
|
||||
const cancelled = new AbortController();
|
||||
cancelled.abort();
|
||||
const cancelledResult = await client.execute(
|
||||
"inspect_managed_artifact",
|
||||
{},
|
||||
{ signal: cancelled.signal },
|
||||
);
|
||||
expect(cancelledResult).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCancelledError" },
|
||||
});
|
||||
|
||||
const changed = Buffer.from(bytes);
|
||||
changed[0x300] = 0;
|
||||
await writeFile(path, changed);
|
||||
const staleDigest = await client.execute("inspect_managed_artifact", {});
|
||||
expect(staleDigest).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "EvidenceIntegrityError" },
|
||||
});
|
||||
|
||||
await client.close();
|
||||
const nativeClient = new ManagedStaticProvider().createClient({
|
||||
...parsed.value,
|
||||
format: "elf",
|
||||
});
|
||||
await expect(
|
||||
nativeClient.execute("inspect_managed_artifact", {}),
|
||||
).resolves.toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "AnalysisCapabilityUnavailableError" },
|
||||
});
|
||||
});
|
||||
|
||||
it("has the same evidence shape through direct CLI analysis plumbing", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-cli-"));
|
||||
const path = join(directory, "fixture.exe");
|
||||
await writeFile(path, buildManagedPeFixture());
|
||||
|
||||
const evidence = parseEvidence(
|
||||
await runProviderAnalysis(path, "inspect_managed_artifact", {
|
||||
reference_limit: 1,
|
||||
}),
|
||||
);
|
||||
expect(evidence).toMatchObject({
|
||||
operation: "inspect_managed_artifact",
|
||||
provider: { id: "rea-dotnet-static" },
|
||||
subject: { local_path: path, format: "pe" },
|
||||
normalized_result: {
|
||||
classification: { status: "managed", runtime_family: "modern-dotnet" },
|
||||
references: { limit: 1 },
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const target = (bytes: Buffer): BinaryTarget => ({
|
||||
path: "/fixture.exe",
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
kind: "executable",
|
||||
format: "pe",
|
||||
architecture: "x86",
|
||||
availableArchitectures: ["x86"],
|
||||
});
|
||||
|
||||
const asManagedResult = (execution: AnalysisExecution) =>
|
||||
managedArtifactInspectionSchema.parse(execution.result);
|
||||
@@ -0,0 +1,76 @@
|
||||
import { mkdtemp, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { AnalysisProviderRegistry } from "../src/application/AnalysisProviderRegistry.js";
|
||||
import { BinarySession } from "../src/application/BinarySession.js";
|
||||
import { SessionProviderRouter } from "../src/application/SessionProviderRouter.js";
|
||||
import { ManagedStaticProvider } from "../src/dotnet/ManagedStaticProvider.js";
|
||||
import { createServer } from "../src/server/createServer.js";
|
||||
import { buildManagedPeFixture } from "./fixtures/managedPe.js";
|
||||
|
||||
describe("managed artifact MCP tools", () => {
|
||||
it("opens a managed PE and executes the managed static provider through MCP", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-managed-mcp-"));
|
||||
const path = join(directory, "fixture.exe");
|
||||
await writeFile(path, buildManagedPeFixture());
|
||||
const session = new BinarySession(
|
||||
SessionProviderRouter.selectable(new AnalysisProviderRegistry([]), [
|
||||
new ManagedStaticProvider(),
|
||||
]),
|
||||
);
|
||||
const server = createServer(session, session);
|
||||
const client = new Client({ name: "managed-mcp-test", version: "1.0.0" });
|
||||
const [clientTransport, serverTransport] =
|
||||
InMemoryTransport.createLinkedPair();
|
||||
try {
|
||||
await server.connect(serverTransport);
|
||||
await client.connect(clientTransport);
|
||||
const tools = await client.listTools();
|
||||
expect(tools.tools.map(({ name }) => name)).toContain(
|
||||
"inspect_managed_artifact",
|
||||
);
|
||||
|
||||
await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path },
|
||||
});
|
||||
const inspected = structured(
|
||||
await client.callTool({
|
||||
name: "inspect_managed_artifact",
|
||||
arguments: { reference_limit: 1 },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(inspected).toMatchObject({
|
||||
operation: "inspect_managed_artifact",
|
||||
provider: { id: "rea-dotnet-static" },
|
||||
subject: { local_path: path, format: "pe" },
|
||||
normalized_result: {
|
||||
classification: {
|
||||
status: "managed",
|
||||
runtime_family: "modern-dotnet",
|
||||
},
|
||||
references: { limit: 1 },
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
await Promise.all([client.close(), server.close()]);
|
||||
await session.close();
|
||||
}
|
||||
}, 30_000);
|
||||
});
|
||||
|
||||
const structured = (result: CallToolResult): Record<string, unknown> => {
|
||||
if (
|
||||
typeof result.structuredContent !== "object" ||
|
||||
result.structuredContent === null
|
||||
)
|
||||
throw new Error("missing structured result");
|
||||
return z.record(z.string(), z.unknown()).parse(result.structuredContent);
|
||||
};
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
JAVASCRIPT_APPLICATION_PROVIDER,
|
||||
JAVASCRIPT_APPLICATION_WORKFLOW_PROVIDER,
|
||||
JAVASCRIPT_RUNTIME_RECONCILIATION_PROVIDER,
|
||||
MANAGED_STATIC_PROVIDER,
|
||||
} from "../src/application/InvestigationProviders.js";
|
||||
import { CDP_BROWSER_PROVIDER_IDENTITY } from "../src/browser/CdpBrowserProvider.js";
|
||||
import { CDP_ELECTRON_PROVIDER_IDENTITY } from "../src/browser/CdpElectronProvider.js";
|
||||
@@ -69,6 +70,7 @@ describe("canonical product catalog", () => {
|
||||
GHIDRA_PROVIDER_IDENTITY,
|
||||
NATIVE_MACOS_PROVIDER_IDENTITY,
|
||||
ARTIFACT_GRAPH_PROVIDER,
|
||||
MANAGED_STATIC_PROVIDER,
|
||||
CDP_BROWSER_PROVIDER_IDENTITY,
|
||||
CDP_ELECTRON_PROVIDER_IDENTITY,
|
||||
JAVASCRIPT_APPLICATION_PROVIDER,
|
||||
|
||||
@@ -54,7 +54,7 @@ describe("guided prompts over MCP", () => {
|
||||
),
|
||||
);
|
||||
}
|
||||
expect((await client.listTools()).tools).toHaveLength(83);
|
||||
expect((await client.listTools()).tools).toHaveLength(84);
|
||||
const result = await client.getPrompt({
|
||||
name: "investigate_feature",
|
||||
arguments: {
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from "../src/contracts/toolContracts.js";
|
||||
import { NATIVE_TOOL_CONTRACTS } from "../src/contracts/nativeToolContracts.js";
|
||||
import { ARTIFACT_TOOL_CONTRACTS } from "../src/contracts/artifactToolContracts.js";
|
||||
import { MANAGED_TOOL_CONTRACTS } from "../src/contracts/managedToolContracts.js";
|
||||
import { BROWSER_TOOL_CONTRACTS } from "../src/contracts/browserToolContracts.js";
|
||||
import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.js";
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolContracts.js";
|
||||
@@ -28,6 +29,7 @@ const expectedToolCounts = [
|
||||
ENHANCED_TOOL_CONTRACTS.length,
|
||||
NATIVE_TOOL_CONTRACTS.length,
|
||||
ARTIFACT_TOOL_CONTRACTS.length,
|
||||
MANAGED_TOOL_CONTRACTS.length,
|
||||
BROWSER_TOOL_CONTRACTS.length,
|
||||
ELECTRON_TOOL_CONTRACTS.length,
|
||||
APPLICATION_TOOL_CONTRACTS.length,
|
||||
|
||||
@@ -10,7 +10,7 @@ const fixturePath = fileURLToPath(
|
||||
);
|
||||
|
||||
describe("production stdio runtime", () => {
|
||||
it("starts the built entrypoint, lists 83 tools, calls one, and shuts down", async () => {
|
||||
it("starts the built entrypoint, lists 84 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(83);
|
||||
expect(tools.tools).toHaveLength(84);
|
||||
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(83);
|
||||
expect((await client.listTools()).tools).toHaveLength(84);
|
||||
} 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(43);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(43);
|
||||
expect(CLI_COMMAND_NAMES).toHaveLength(44);
|
||||
expect(new Set(CLI_COMMAND_NAMES).size).toBe(44);
|
||||
expect(CATALOG_IDENTITY.counts).toEqual({
|
||||
cli_commands: 43,
|
||||
mcp_tools: 83,
|
||||
cli_commands: 44,
|
||||
mcp_tools: 84,
|
||||
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: 83, cli_commands: 43 } },
|
||||
catalog: { counts: { mcp_tools: 84, cli_commands: 44 } },
|
||||
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(83);
|
||||
expect((await mcp.listTools()).tools).toHaveLength(84);
|
||||
const deniedCapture = await mcp.callTool({
|
||||
name: "capture_process_scenario",
|
||||
arguments: {
|
||||
|
||||
@@ -7,17 +7,21 @@ import {
|
||||
TOOL_CONTRACTS,
|
||||
} from "../src/contracts/toolContracts.js";
|
||||
import { ARTIFACT_TOOL_CONTRACTS } from "../src/contracts/artifactToolContracts.js";
|
||||
import { MANAGED_TOOL_CONTRACTS } from "../src/contracts/managedToolContracts.js";
|
||||
import { NATIVE_TOOL_CONTRACTS } from "../src/contracts/nativeToolContracts.js";
|
||||
import { BROWSER_TOOL_CONTRACTS } from "../src/contracts/browserToolContracts.js";
|
||||
import { ELECTRON_TOOL_CONTRACTS } from "../src/contracts/electronToolContracts.js";
|
||||
import { APPLICATION_TOOL_CONTRACTS } from "../src/contracts/applicationToolContracts.js";
|
||||
|
||||
describe("tool contract inventory", () => {
|
||||
it("publishes 65 analysis contracts and eighteen session tools", () => {
|
||||
it("publishes 66 analysis contracts and eighteen session tools", () => {
|
||||
expect(OFFICIAL_TOOL_CONTRACTS).toHaveLength(33);
|
||||
expect(ENHANCED_TOOL_CONTRACTS).toHaveLength(10);
|
||||
expect(NATIVE_TOOL_CONTRACTS).toHaveLength(5);
|
||||
expect(ARTIFACT_TOOL_CONTRACTS).toHaveLength(2);
|
||||
expect(MANAGED_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
|
||||
"inspect_managed_artifact",
|
||||
]);
|
||||
expect(BROWSER_TOOL_CONTRACTS.map(({ name }) => name)).toEqual([
|
||||
"list_browser_targets",
|
||||
"inspect_web_page",
|
||||
@@ -59,8 +63,8 @@ describe("tool contract inventory", () => {
|
||||
"update_unknown",
|
||||
"verify_unknown_resolution",
|
||||
]);
|
||||
expect(TOOL_CONTRACTS).toHaveLength(83);
|
||||
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(83);
|
||||
expect(TOOL_CONTRACTS).toHaveLength(84);
|
||||
expect(new Set(TOOL_CONTRACTS.map(({ name }) => name)).size).toBe(84);
|
||||
});
|
||||
|
||||
it("retains documented enhanced-tool limits at the input boundary", () => {
|
||||
|
||||
Reference in New Issue
Block a user