feat(managed): select declaring types in inspect_managed_members

Select exact declaring types before managed signatures and CIL bodies are decoded, preserving caller choices in CLI/MCP Evidence. Keep unmatched names and selected coverage explicit; comparisons and graphs retain unknowns outside their observed scope. Reuse existing metadata ownership/accounting and advertise unique selections through the actual SDK Schema.

Validated with 229 focused tests across 21 files, 11 managed conformance controls, fullstatic/docs checks and real Linux CLI and fresh MCP inspection of two unchanged DLLs. All 118 selected CIL hashes matched original PE-mapped bytes; result/caller-argument parity and unmatched controls passed. Full artifact/native-boundary metadata is complete; whole-assembly members retain the unchanged 64 MiB resource constraint. No target code executes.

Refs #1878

Co-authored-by: skared <190618464+skoodster@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ysopwnable <161784452+N0zoM1z0@users.noreply.github.com>
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
skoodster
2026-10-12 08:31:37 +08:00
committed by GitHub
co-authored by skared Claude Opus 5.5 Ysopwnable factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Kaoru0822
parent f28f338283
commit a149d183ef
21 changed files with 645 additions and 90 deletions
+53
View File
@@ -113,6 +113,7 @@ it("runs every managed static inspection independently of an active native targe
operation: "inspect_managed_members",
subject: { local_path: otherPath, format: "pe" },
});
await verifyManagedTypeSelection(client, path, otherPath);
const boundaries = structured(
await client.callTool({
name: "inspect_managed_native_boundaries",
@@ -445,6 +446,58 @@ const verifyImport = async (
});
};
/** Selected type names reach the provider and unmatched names stay visible. */
const verifyManagedTypeSelection = async (
client: Client,
path: string,
otherPath: string,
): Promise<void> => {
const advertised = (await client.listTools()).tools.find(
(tool) => tool.name === "inspect_managed_members",
);
if (advertised === undefined) throw new Error("missing managed member tool");
const ajv = new Ajv2020({ strict: false, validateFormats: false });
expect(ajv.validateSchema(advertised.inputSchema)).toBe(true);
const validate = ajv.compile(advertised.inputSchema);
expect(
validate({ path, type_names: ["Fixture.Program", "Missing.Type"] }),
).toBe(true);
expect(
validate({ path, type_names: ["Fixture.Program", "Fixture.Program"] }),
).toBe(false);
const selected = structured(
await client.callTool({
name: "inspect_managed_members",
arguments: { path, type_names: ["Fixture.Program", "Missing.Type"] },
}),
);
expect(selected).toMatchObject({
parameters: { path, type_names: ["Fixture.Program", "Missing.Type"] },
normalized_result: {
types: [expect.objectContaining({ full_name: "Fixture.Program" })],
methods: [expect.objectContaining({ declaring_type: "Fixture.Program" })],
selection: {
type_names: ["Fixture.Program", "Missing.Type"],
unmatched_type_names: ["Missing.Type"],
},
},
});
const repeatedSelection = await client.callTool({
name: "inspect_managed_members",
arguments: { path, type_names: ["Fixture.Program", "Fixture.Program"] },
});
expect(repeatedSelection.isError).toBe(true);
const reselectedOtherTarget = structured(
await client.callTool({
name: "inspect_managed_artifact",
arguments: { path: otherPath },
}),
);
expect(reselectedOtherTarget).toMatchObject({
subject: { local_path: otherPath, format: "pe" },
});
};
const structured = (result: CallToolResult): Record<string, unknown> => {
if (result.isError === true) return parseMcpToolError(result);
if (
@@ -459,9 +459,83 @@ describe("managed member comparison of ambiguous undecoded signatures", () => {
});
});
const inspect = (bytes: Buffer, path: string) => {
describe("managed member comparison of selected types", () => {
it("keeps members outside the other side's selection unknown", () => {
const left = inspect(buildManagedPeFixture(), "/tmp/left-all.dll");
const right = inspect(buildManagedPeFixture(), "/tmp/right-selected.dll", [
"Missing.Type",
]);
const result = compareManagedMembers(
{ evidenceId: left.evidenceId, result: left.result },
{ evidenceId: right.evidenceId, result: right.result },
);
expect(result.summary).toMatchObject({ added: 0, removed: 0, unknown: 2 });
expect(result.methods[0]).toMatchObject({
status: "unknown",
left: { token: "0x06000001" },
right: null,
});
expect(result.coverage.status).toBe("partial");
expect(result.limitations).toContain(
"The observations select different declaring types; a member outside the other side's selection is unknown, not added or removed.",
);
});
it("does not remap members across types neither side observed", () => {
const left = inspect(buildManagedPeFixture(), "/tmp/left-a.dll", [
"Fixture.Program",
]);
const right = inspect(
buildManagedPeFixture({
mvid: Buffer.from("00112233445566778899aabbccddeefe", "hex"),
typeName: "A",
typeNamespace: "X",
}),
"/tmp/right-b.dll",
["X.A"],
);
const result = compareManagedMembers(
{ evidenceId: left.evidenceId, result: left.result },
{ evidenceId: right.evidenceId, result: right.result },
);
expect(result.matching.exact_il_signature).toBe(0);
expect(result.summary).toMatchObject({
unchanged: 0,
added: 0,
removed: 0,
unknown: 4,
});
});
it("compares two identical selections within those types", () => {
const left = inspect(buildManagedPeFixture(), "/tmp/left-sel.dll", [
"Fixture.Program",
]);
const right = inspect(buildManagedPeFixture(), "/tmp/right-sel.dll", [
"Fixture.Program",
]);
const result = compareManagedMembers(
{ evidenceId: left.evidenceId, result: left.result },
{ evidenceId: right.evidenceId, result: right.result },
);
expect(result.methods[0]).toMatchObject({ status: "unchanged" });
expect(result.coverage.status).toBe("complete-within-inputs");
expect(result.limitations).toContain(
"Both observations cover only the selected declaring types (Fixture.Program); member totals and statuses describe those types, not the whole assembly.",
);
});
});
const inspect = (bytes: Buffer, path: string, typeNames?: string[]) => {
const target = managedPeFixtureTarget(bytes, path);
const result = inspectManagedMembersBytes(bytes, target);
const result = inspectManagedMembersBytes(
bytes,
target,
typeNames === undefined ? {} : { typeNames },
);
return {
result,
evidenceId: `ev_${hash(Buffer.from(path))}`,
@@ -629,3 +629,55 @@ describe("managed application graph coverage", () => {
});
});
});
describe("managed application graph type selection", () => {
const project = (result: Parameters<typeof createEvidence>[2]["result"]) => {
const bytes = buildManagedPeFixture();
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
const projection = projectManagedApplicationGraphEvidence({
managed_members: createEvidence(binary, MANAGED_STATIC_PROVIDER, {
operation: "inspect_managed_members",
parameters: {},
result,
rawResult: null,
limitations: [],
}),
});
if (!projection.ok) throw new Error("projection failed");
return managedApplicationGraphResultSchema.parse(
parseEvidence(projection.value).normalized_result,
);
};
it("marks a graph from selected member inspection partial", () => {
const bytes = buildManagedPeFixture();
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
const selected = inspectManagedMembersBytes(bytes, binary, {
typeNames: ["Fixture.Program"],
});
expect(selected.coverage.state).toBe("complete");
const result = project(selected);
expect(result.coverage).toMatchObject({ status: "partial" });
expect(result.limitations).toContain(
"Managed member Evidence selected only these declaring types: Fixture.Program; type, method, and field nodes of other types are omitted, not absent.",
);
expect(result.limitations).not.toContain(
"At least one supplied managed Evidence record has partial coverage.",
);
});
it("accepts member Evidence recorded before type selection existed", () => {
const bytes = buildManagedPeFixture();
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
const { selection: _selection, ...legacy } = inspectManagedMembersBytes(
bytes,
binary,
);
expect(managedMemberInspectionSchema.parse(legacy).selection).toBeNull();
expect(project(legacy).coverage).toMatchObject({
status: "complete-within-inputs",
});
});
});