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
@@ -335,6 +335,11 @@ const projectionLimitations = (
...(omissions.partialInput
? ["At least one supplied managed Evidence record has partial coverage."]
: []),
...(omissions.selectedTypes === null
? []
: [
`Managed member Evidence selected only these declaring types: ${omissions.selectedTypes.join(", ")}; type, method, and field nodes of other types are omitted, not absent.`,
]),
...(omissions.unscopedTokenRelationships
? [
"Managed boundary tokens were not linked to member nodes because matching module MVID scope was not established.",
@@ -19,8 +19,15 @@ export interface ManagedGraphCoverageSources {
export interface ManagedGraphProjectionOmissions {
readonly partialInput: boolean;
readonly unscopedTokenRelationships: boolean;
/** Declaring types the member Evidence selected; null when it inspected every type. */
readonly selectedTypes: readonly string[] | null;
}
const omitsAny = (omissions: ManagedGraphProjectionOmissions): boolean =>
omissions.partialInput ||
omissions.unscopedTokenRelationships ||
omissions.selectedTypes !== null;
const completeCoverage = (): ApplicationGraphEvidence["coverage"] => ({
status: "complete",
truncated: false,
@@ -61,13 +68,14 @@ export const assessManagedGraphOmissions = (
sources.boundaries?.coverage.state,
sources.artifact?.coverage.state,
].some((state) => state !== undefined && state !== "complete"),
selectedTypes: sources.members?.selection?.type_names ?? null,
});
/** Derive graph coverage solely from the coverage of supplied source evidence. */
export const managedGraphEvidenceCoverage = (
omissions: ManagedGraphProjectionOmissions,
): ApplicationGraphEvidence["coverage"] =>
omissions.partialInput || omissions.unscopedTokenRelationships
omitsAny(omissions)
? {
status: "partial",
truncated: false,
@@ -80,8 +88,7 @@ export const managedGraphEvidenceCoverage = (
export const managedGraphResultCoverage = (
omissions: ManagedGraphProjectionOmissions,
) => ({
status:
omissions.partialInput || omissions.unscopedTokenRelationships
? ("partial" as const)
: ("complete-within-inputs" as const),
status: omitsAny(omissions)
? ("partial" as const)
: ("complete-within-inputs" as const),
});
+8
View File
@@ -440,6 +440,14 @@ export const managedMemberInspectionSchema = z.object({
member_refs: z.array(managedMemberReferenceSchema),
call_edges: z.array(managedCallEdgeSchema),
field_accesses: z.array(managedFieldAccessSchema),
/** Caller-selected declaring types; null when every type was inspected. */
selection: z
.object({
type_names: z.array(z.string().min(1)).min(1),
unmatched_type_names: z.array(z.string().min(1)),
})
.nullable()
.default(null),
coverage: z.object({
state: z.enum(["complete", "partial", "unavailable"]),
issues: z.array(managedParseIssueSchema),
@@ -213,6 +213,11 @@ export interface ManagedMemberComparisonSide {
readonly result: ManagedMemberInspection;
}
const selectedTypes = (
result: ManagedMemberInspection,
): ReadonlySet<string> | null =>
result.selection === null ? null : new Set(result.selection.type_names);
/** Compare managed members with constrained exact and structural identities. */
export const compareManagedMembers = (
left: ManagedMemberComparisonSide,
@@ -224,6 +229,8 @@ export const compareManagedMembers = (
rightEvidenceId: right.evidenceId,
leftComplete: left.result.metadata.status === "complete",
rightComplete: right.result.metadata.status === "complete",
leftSelection: selectedTypes(left.result),
rightSelection: selectedTypes(right.result),
};
const methodItems = buildMethodItems(methodMatches, itemContext);
const fieldItems = buildFieldItems(fieldMatches, itemContext);
@@ -16,7 +16,9 @@ export const buildComparisonCoverage = ({
const leftStatus = sideCoverageStatus(left);
const rightStatus = sideCoverageStatus(right);
const unknownInput =
left.coverage.state !== "complete" || right.coverage.state !== "complete";
left.coverage.state !== "complete" ||
right.coverage.state !== "complete" ||
!sameSelection(left, right);
return {
status:
!unknownInput && leftStatus === "complete" && rightStatus === "complete"
@@ -27,6 +29,20 @@ export const buildComparisonCoverage = ({
};
};
/** Whether both observations inspected the same declaring types. */
const sameSelection = (
left: ManagedMemberInspection,
right: ManagedMemberInspection,
): boolean => {
if (left.selection === null || right.selection === null)
return left.selection === right.selection;
const rightNames = new Set(right.selection.type_names);
return (
rightNames.size === new Set(left.selection.type_names).size &&
left.selection.type_names.every((name) => rightNames.has(name))
);
};
const sideCoverageStatus = (
result: ManagedMemberInspection,
): ManagedMemberComparisonResult["coverage"]["left_status"] =>
@@ -96,6 +112,14 @@ export const comparisonLimitations = (
];
if (left.coverage.state !== "complete" || right.coverage.state !== "complete")
limitations.push("At least one managed member observation is partial.");
if (!sameSelection(left, right))
limitations.push(
"The observations select different declaring types; a member outside the other side's selection is unknown, not added or removed.",
);
else if (left.selection !== null)
limitations.push(
`Both observations cover only the selected declaring types (${left.selection.type_names.join(", ")}); member totals and statuses describe those types, not the whole assembly.`,
);
if (left.exported_types === null || right.exported_types === null)
limitations.push(
"At least one managed member observation predates ExportedType inspection; its exported and forwarded types are unknown.",
@@ -26,8 +26,21 @@ interface ComparisonItemContext {
readonly rightEvidenceId: string;
readonly leftComplete: boolean;
readonly rightComplete: boolean;
/** Declaring types each side selected; null when it inspected every type. */
readonly leftSelection: ReadonlySet<string> | null;
readonly rightSelection: ReadonlySet<string> | null;
}
/** Whether an inventory observed every member of this member's declaring type. */
const inventoryCovers = (
complete: boolean,
selection: ReadonlySet<string> | null,
member: Method | Field,
): boolean =>
complete &&
(selection === null ||
(member.declaring_type !== null && selection.has(member.declaring_type)));
/** Declared type and name of each unpaired member, per side, whose signature was not decoded. */
interface UndecodedOneSidedNames {
readonly left: ReadonlySet<string>;
@@ -123,7 +136,11 @@ const methodOnlyItem = (
): MethodItem => {
if (member.left !== undefined) {
const limitations = absenceLimitations(member.left, {
oppositeComplete: context.rightComplete,
oppositeComplete: inventoryCovers(
context.rightComplete,
context.rightSelection,
member.left,
),
oppositeUndecodedNames: undecoded.right,
opposite: "right",
inventory: "method",
@@ -141,7 +158,11 @@ const methodOnlyItem = (
}
const limitations = absenceLimitations(member.right, {
oppositeComplete: context.leftComplete,
oppositeComplete: inventoryCovers(
context.leftComplete,
context.leftSelection,
member.right,
),
oppositeUndecodedNames: undecoded.left,
opposite: "left",
inventory: "method",
@@ -233,7 +254,11 @@ const fieldOnlyItem = (
): FieldItem => {
if (member.left !== undefined) {
const limitations = absenceLimitations(member.left, {
oppositeComplete: context.rightComplete,
oppositeComplete: inventoryCovers(
context.rightComplete,
context.rightSelection,
member.left,
),
oppositeUndecodedNames: undecoded.right,
opposite: "right",
inventory: "field",
@@ -250,7 +275,11 @@ const fieldOnlyItem = (
}
const limitations = absenceLimitations(member.right, {
oppositeComplete: context.leftComplete,
oppositeComplete: inventoryCovers(
context.leftComplete,
context.leftSelection,
member.right,
),
oppositeUndecodedNames: undecoded.left,
opposite: "left",
inventory: "field",
@@ -250,22 +250,74 @@ const groupBy = <Item>(
return grouped;
};
/** Whether a side's inventory observed members of this declaring type. */
const observedBy =
(side: ManagedMemberComparisonSide) =>
({ declaring_type }: { readonly declaring_type: string | null }): boolean =>
side.result.selection === null ||
(declaring_type !== null &&
side.result.selection.type_names.includes(declaring_type));
/**
* Pair only members whose declaring type both sides observed. A member outside
* the other side's selection stays one-sided, so a type selection never yields
* a remap to a member of a type the other side did not inspect.
*/
const matchObserved = <Item extends { readonly declaring_type: string | null }>(
left: readonly Item[],
right: readonly Item[],
sides: {
readonly inLeft: (item: Item) => boolean;
readonly inRight: (item: Item) => boolean;
},
match: (
left: readonly Keyed<Item>[],
right: readonly Keyed<Item>[],
) => ReturnType<typeof matchByKeys<Item>>,
key: (item: Item) => Keyed<Item>,
): ReturnType<typeof matchByKeys<Item>> => {
const matched = match(
left.filter(sides.inRight).map(key),
right.filter(sides.inLeft).map(key),
);
return {
...matched,
leftOnly: [
...matched.leftOnly,
...left.filter((item) => !sides.inRight(item)).map(key),
],
rightOnly: [
...matched.rightOnly,
...right.filter((item) => !sides.inLeft(item)).map(key),
],
};
};
export const keyMembers = (
left: ManagedMemberComparisonSide,
right: ManagedMemberComparisonSide,
): {
readonly methodMatches: ReturnType<typeof matchMethods>;
readonly fieldMatches: ReturnType<typeof matchFields>;
} => ({
methodMatches: matchMethods(
left.result.methods.map(keyMethod),
right.result.methods.map(keyMethod),
),
fieldMatches: matchFields(
left.result.fields.map(keyField),
right.result.fields.map(keyField),
),
});
} => {
const sides = { inLeft: observedBy(left), inRight: observedBy(right) };
return {
methodMatches: matchObserved(
left.result.methods,
right.result.methods,
sides,
matchMethods,
keyMethod,
),
fieldMatches: matchObserved(
left.result.fields,
right.result.fields,
sides,
matchFields,
keyField,
),
};
};
export const parseManagedMemberEvidence = (
evidence: unknown,