fix(managed): bind graph facts to their source Evidence
This commit is contained in:
@@ -151,8 +151,8 @@ export const projectManagedApplicationGraph = (
|
|||||||
};
|
};
|
||||||
const artifactNode = addArtifactNode(state);
|
const artifactNode = addArtifactNode(state);
|
||||||
addArtifactIdentityNodes(state, artifactNode, parsed);
|
addArtifactIdentityNodes(state, artifactNode, parsed);
|
||||||
const memberCounts = addMemberNodes(state, artifactNode, parsed);
|
addMemberNodes(state, artifactNode, parsed);
|
||||||
const boundaryCounts = addBoundaryNodes(state, artifactNode, parsed);
|
addBoundaryNodes(state, artifactNode, parsed);
|
||||||
const omissions = omittedCounts(parsed);
|
const omissions = omittedCounts(parsed);
|
||||||
const limitations = projectionLimitations(parsed, omissions);
|
const limitations = projectionLimitations(parsed, omissions);
|
||||||
const graph = createJavaScriptApplicationGraph({
|
const graph = createJavaScriptApplicationGraph({
|
||||||
@@ -175,10 +175,16 @@ export const projectManagedApplicationGraph = (
|
|||||||
summary: {
|
summary: {
|
||||||
graph_nodes: graph.nodes.length,
|
graph_nodes: graph.nodes.length,
|
||||||
graph_edges: graph.edges.length,
|
graph_edges: graph.edges.length,
|
||||||
assemblies: parsed.artifact?.result.assembly === null ? 0 : 1,
|
assemblies: countNodes(graph.nodes, "managed-assembly"),
|
||||||
modules: parsed.artifact?.result.module === null ? 0 : 1,
|
modules: countNodes(graph.nodes, "managed-module"),
|
||||||
...memberCounts,
|
types: countNodes(graph.nodes, "managed-type"),
|
||||||
...boundaryCounts,
|
methods: countNodes(graph.nodes, "managed-method"),
|
||||||
|
fields: countNodes(graph.nodes, "managed-field"),
|
||||||
|
pinvoke_imports: countNodes(graph.nodes, "managed-pinvoke-import"),
|
||||||
|
native_implementations: countNodes(
|
||||||
|
graph.nodes,
|
||||||
|
"managed-native-implementation",
|
||||||
|
),
|
||||||
},
|
},
|
||||||
graph,
|
graph,
|
||||||
coverage: managedGraphResultCoverage(omissions),
|
coverage: managedGraphResultCoverage(omissions),
|
||||||
@@ -191,6 +197,11 @@ export const projectManagedApplicationGraph = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const countNodes = (
|
||||||
|
nodes: readonly ApplicationNode[],
|
||||||
|
kind: ApplicationNode["kind"],
|
||||||
|
): number => nodes.filter((node) => node.kind === kind).length;
|
||||||
|
|
||||||
const parseManagedInputs = (
|
const parseManagedInputs = (
|
||||||
input: ProjectManagedApplicationGraphInput,
|
input: ProjectManagedApplicationGraphInput,
|
||||||
): ParsedManagedGraphInput => ({
|
): ParsedManagedGraphInput => ({
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import type { ParsedManagedGraphInput } from "./managedApplicationGraph.js";
|
|
||||||
|
|
||||||
/** Derive module coverage from the best available managed evidence source. */
|
|
||||||
export const moduleCoverageState = (
|
|
||||||
parsed: ParsedManagedGraphInput,
|
|
||||||
): "complete" | "partial" | "unavailable" =>
|
|
||||||
parsed.artifact !== null && parsed.artifact.result.module !== null
|
|
||||||
? parsed.artifact.result.coverage.state
|
|
||||||
: parsed.members !== null && parsed.members.result.module !== null
|
|
||||||
? parsed.members.result.coverage.state
|
|
||||||
: (parsed.boundaries?.result.coverage.state ?? "complete");
|
|
||||||
@@ -6,7 +6,9 @@ import {
|
|||||||
import type { ApplicationGraphEvidence } from "../javascript/javascriptApplicationEvidenceSchemas.js";
|
import type { ApplicationGraphEvidence } from "../javascript/javascriptApplicationEvidenceSchemas.js";
|
||||||
import type { ApplicationNode } from "../javascript/javascriptApplicationGraphSchemas.js";
|
import type { ApplicationNode } from "../javascript/javascriptApplicationGraphSchemas.js";
|
||||||
import { managedSourceCoverage } from "./managedApplicationGraphCoverage.js";
|
import { managedSourceCoverage } from "./managedApplicationGraphCoverage.js";
|
||||||
|
import type { Evidence } from "../evidence.js";
|
||||||
import {
|
import {
|
||||||
|
type ManagedArtifactInspection,
|
||||||
type ManagedMemberInspection,
|
type ManagedMemberInspection,
|
||||||
type ManagedNativeBoundaryInspection,
|
type ManagedNativeBoundaryInspection,
|
||||||
} from "./managedArtifact.js";
|
} from "./managedArtifact.js";
|
||||||
@@ -14,7 +16,6 @@ import type {
|
|||||||
GraphBuildState,
|
GraphBuildState,
|
||||||
ParsedManagedGraphInput,
|
ParsedManagedGraphInput,
|
||||||
} from "./managedApplicationGraph.js";
|
} from "./managedApplicationGraph.js";
|
||||||
import { moduleCoverageState } from "./managedApplicationGraphNodeCoverage.js";
|
|
||||||
type ManagedMethod = ManagedMemberInspection["methods"][number];
|
type ManagedMethod = ManagedMemberInspection["methods"][number];
|
||||||
type ManagedField = ManagedMemberInspection["fields"][number];
|
type ManagedField = ManagedMemberInspection["fields"][number];
|
||||||
type ManagedType = ManagedMemberInspection["types"][number];
|
type ManagedType = ManagedMemberInspection["types"][number];
|
||||||
@@ -44,7 +45,7 @@ export const addArtifactNode = (state: GraphBuildState): ApplicationNode => {
|
|||||||
format: "pe",
|
format: "pe",
|
||||||
source: "managed-application-graph",
|
source: "managed-application-graph",
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(state, "project-managed-artifact"),
|
evidence: projectedManagedEvidence(state, "project-managed-artifact"),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -58,47 +59,48 @@ export const addArtifactIdentityNodes = (
|
|||||||
artifactNode: ApplicationNode,
|
artifactNode: ApplicationNode,
|
||||||
parsed: ParsedManagedGraphInput,
|
parsed: ParsedManagedGraphInput,
|
||||||
): void => {
|
): void => {
|
||||||
const artifact = parsed.artifact?.result;
|
const artifactInput = parsed.artifact;
|
||||||
const artifactCoverage = managedSourceCoverage(
|
if (artifactInput !== null && artifactInput.result.assembly !== null) {
|
||||||
parsed.artifact?.result.coverage.state ?? "complete",
|
const assemblyFacts = artifactInput.result.assembly;
|
||||||
);
|
const artifactEvidence = sourceManagedEvidence(
|
||||||
if (artifact?.assembly !== undefined && artifact.assembly !== null) {
|
state,
|
||||||
|
artifactInput.evidence,
|
||||||
|
artifactInput.result.coverage.state,
|
||||||
|
);
|
||||||
const assembly = createJavaScriptApplicationNode({
|
const assembly = createJavaScriptApplicationNode({
|
||||||
kind: "managed-assembly",
|
kind: "managed-assembly",
|
||||||
identity: artifactLocalIdentity(
|
identity: artifactLocalIdentity(
|
||||||
state.artifactSha256,
|
state.artifactSha256,
|
||||||
"managed-assembly",
|
"managed-assembly",
|
||||||
artifact.assembly.token,
|
assemblyFacts.token,
|
||||||
),
|
),
|
||||||
observations: [
|
observations: [
|
||||||
{
|
{
|
||||||
label: artifact.assembly.name,
|
label: assemblyFacts.name,
|
||||||
properties: {
|
properties: {
|
||||||
name: artifact.assembly.name,
|
name: assemblyFacts.name,
|
||||||
version: artifact.assembly.version,
|
version: assemblyFacts.version,
|
||||||
culture: artifact.assembly.culture,
|
culture: assemblyFacts.culture,
|
||||||
public_key_kind: artifact.assembly.public_key.kind,
|
public_key_kind: assemblyFacts.public_key.kind,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(
|
evidence: artifactEvidence,
|
||||||
state,
|
|
||||||
"inspect_managed_artifact",
|
|
||||||
artifactCoverage,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
state.nodes.push(assembly);
|
state.nodes.push(assembly);
|
||||||
addContainsEdge(state, artifactNode, assembly, {
|
addContainsEdge(state, artifactNode, assembly, {
|
||||||
kind: "declares-managed-assembly",
|
kind: "declares-managed-assembly",
|
||||||
coverage: artifactCoverage,
|
coverage: artifactEvidence.coverage,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const module =
|
const moduleSource = selectModuleSource(parsed);
|
||||||
artifact?.module ??
|
if (moduleSource !== null) {
|
||||||
parsed.members?.result.module ??
|
const { module } = moduleSource;
|
||||||
parsed.boundaries?.result.module;
|
const moduleEvidence = sourceManagedEvidence(
|
||||||
if (module !== undefined && module !== null) {
|
state,
|
||||||
const moduleCoverage = managedSourceCoverage(moduleCoverageState(parsed));
|
moduleSource.evidence,
|
||||||
|
moduleSource.coverageState,
|
||||||
|
);
|
||||||
const moduleNode = createJavaScriptApplicationNode({
|
const moduleNode = createJavaScriptApplicationNode({
|
||||||
kind: "managed-module",
|
kind: "managed-module",
|
||||||
identity: artifactLocalIdentity(
|
identity: artifactLocalIdentity(
|
||||||
@@ -115,36 +117,68 @@ export const addArtifactIdentityNodes = (
|
|||||||
generation: module.generation,
|
generation: module.generation,
|
||||||
token: module.token,
|
token: module.token,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(
|
evidence: moduleEvidence,
|
||||||
state,
|
|
||||||
"inspect_managed_artifact",
|
|
||||||
moduleCoverage,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
state.nodes.push(moduleNode);
|
state.nodes.push(moduleNode);
|
||||||
addContainsEdge(state, artifactNode, moduleNode, {
|
addContainsEdge(state, artifactNode, moduleNode, {
|
||||||
kind: "declares-managed-module",
|
kind: "declares-managed-module",
|
||||||
coverage: moduleCoverage,
|
coverage: moduleEvidence.coverage,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface ManagedModuleSource {
|
||||||
|
readonly module: NonNullable<ManagedArtifactInspection["module"]>;
|
||||||
|
readonly evidence: Evidence;
|
||||||
|
readonly coverageState: ManagedArtifactInspection["coverage"]["state"];
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectModuleSource = (
|
||||||
|
parsed: ParsedManagedGraphInput,
|
||||||
|
): ManagedModuleSource | null => {
|
||||||
|
if (parsed.artifact?.result.module != null)
|
||||||
|
return {
|
||||||
|
module: parsed.artifact.result.module,
|
||||||
|
evidence: parsed.artifact.evidence,
|
||||||
|
coverageState: parsed.artifact.result.coverage.state,
|
||||||
|
};
|
||||||
|
if (parsed.members?.result.module != null)
|
||||||
|
return {
|
||||||
|
module: parsed.members.result.module,
|
||||||
|
evidence: parsed.members.evidence,
|
||||||
|
coverageState: parsed.members.result.coverage.state,
|
||||||
|
};
|
||||||
|
if (parsed.boundaries?.result.module != null)
|
||||||
|
return {
|
||||||
|
module: parsed.boundaries.result.module,
|
||||||
|
evidence: parsed.boundaries.evidence,
|
||||||
|
coverageState: parsed.boundaries.result.coverage.state,
|
||||||
|
};
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
/** Add managed type, method, and field nodes from member evidence. */
|
/** Add managed type, method, and field nodes from member evidence. */
|
||||||
export const addMemberNodes = (
|
export const addMemberNodes = (
|
||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
artifactNode: ApplicationNode,
|
artifactNode: ApplicationNode,
|
||||||
parsed: ParsedManagedGraphInput,
|
parsed: ParsedManagedGraphInput,
|
||||||
) => {
|
): void => {
|
||||||
const members = parsed.members?.result;
|
const memberInput = parsed.members;
|
||||||
if (members === undefined) return { types: 0, methods: 0, fields: 0 };
|
if (memberInput === null) return;
|
||||||
|
const members = memberInput.result;
|
||||||
const { types, methods, fields } = members;
|
const { types, methods, fields } = members;
|
||||||
const typeCoverage = managedSourceCoverage(members.coverage.state);
|
const typeCoverage = managedSourceCoverage(members.coverage.state);
|
||||||
const methodCoverage = managedSourceCoverage(members.coverage.state);
|
const methodCoverage = managedSourceCoverage(members.coverage.state);
|
||||||
const fieldCoverage = managedSourceCoverage(members.coverage.state);
|
const fieldCoverage = managedSourceCoverage(members.coverage.state);
|
||||||
|
const sourceEvidence = sourceManagedEvidence(
|
||||||
|
state,
|
||||||
|
memberInput.evidence,
|
||||||
|
members.coverage.state,
|
||||||
|
);
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
const node = typeNode(state, type, typeCoverage);
|
const node = typeNode(state, type, sourceEvidence);
|
||||||
state.nodes.push(node);
|
state.nodes.push(node);
|
||||||
state.typeNodes.set(type.token, node);
|
state.typeNodes.set(type.token, node);
|
||||||
addContainsEdge(state, artifactNode, node, {
|
addContainsEdge(state, artifactNode, node, {
|
||||||
@@ -153,7 +187,7 @@ export const addMemberNodes = (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (const method of methods) {
|
for (const method of methods) {
|
||||||
const node = methodNode(state, method, methodCoverage);
|
const node = methodNode(state, method, sourceEvidence);
|
||||||
state.nodes.push(node);
|
state.nodes.push(node);
|
||||||
state.methodNodes.set(method.token, node);
|
state.methodNodes.set(method.token, node);
|
||||||
const owner =
|
const owner =
|
||||||
@@ -166,7 +200,7 @@ export const addMemberNodes = (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
const node = fieldNode(state, field, fieldCoverage);
|
const node = fieldNode(state, field, sourceEvidence);
|
||||||
state.nodes.push(node);
|
state.nodes.push(node);
|
||||||
state.fieldNodes.set(field.token, node);
|
state.fieldNodes.set(field.token, node);
|
||||||
const owner =
|
const owner =
|
||||||
@@ -178,18 +212,13 @@ export const addMemberNodes = (
|
|||||||
coverage: fieldCoverage,
|
coverage: fieldCoverage,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
types: types.length,
|
|
||||||
methods: methods.length,
|
|
||||||
fields: fields.length,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Build a managed type application node. */
|
/** Build a managed type application node. */
|
||||||
const typeNode = (
|
const typeNode = (
|
||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
type: ManagedType,
|
type: ManagedType,
|
||||||
coverage: ApplicationGraphEvidence["coverage"],
|
evidence: ApplicationGraphEvidence,
|
||||||
): ApplicationNode =>
|
): ApplicationNode =>
|
||||||
createJavaScriptApplicationNode({
|
createJavaScriptApplicationNode({
|
||||||
kind: "managed-type",
|
kind: "managed-type",
|
||||||
@@ -209,7 +238,7 @@ const typeNode = (
|
|||||||
flags: type.flags,
|
flags: type.flags,
|
||||||
extends_token: type.extends_token,
|
extends_token: type.extends_token,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(state, "inspect_managed_members", coverage),
|
evidence,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -218,7 +247,7 @@ const typeNode = (
|
|||||||
const methodNode = (
|
const methodNode = (
|
||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
method: ManagedMethod,
|
method: ManagedMethod,
|
||||||
coverage: ApplicationGraphEvidence["coverage"],
|
evidence: ApplicationGraphEvidence,
|
||||||
): ApplicationNode =>
|
): ApplicationNode =>
|
||||||
createJavaScriptApplicationNode({
|
createJavaScriptApplicationNode({
|
||||||
kind: "managed-method",
|
kind: "managed-method",
|
||||||
@@ -245,7 +274,7 @@ const methodNode = (
|
|||||||
normalized_il_sha256: method.body.normalized_il_sha256,
|
normalized_il_sha256: method.body.normalized_il_sha256,
|
||||||
il_size: method.body.il_size,
|
il_size: method.body.il_size,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(state, "inspect_managed_members", coverage),
|
evidence,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -254,7 +283,7 @@ const methodNode = (
|
|||||||
const fieldNode = (
|
const fieldNode = (
|
||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
field: ManagedField,
|
field: ManagedField,
|
||||||
coverage: ApplicationGraphEvidence["coverage"],
|
evidence: ApplicationGraphEvidence,
|
||||||
): ApplicationNode =>
|
): ApplicationNode =>
|
||||||
createJavaScriptApplicationNode({
|
createJavaScriptApplicationNode({
|
||||||
kind: "managed-field",
|
kind: "managed-field",
|
||||||
@@ -278,7 +307,7 @@ const fieldNode = (
|
|||||||
signature_sha256: field.signature.raw_sha256,
|
signature_sha256: field.signature.raw_sha256,
|
||||||
signature_status: field.signature.parse_status,
|
signature_status: field.signature.parse_status,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(state, "inspect_managed_members", coverage),
|
evidence,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -288,23 +317,33 @@ export const addBoundaryNodes = (
|
|||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
artifactNode: ApplicationNode,
|
artifactNode: ApplicationNode,
|
||||||
parsed: ParsedManagedGraphInput,
|
parsed: ParsedManagedGraphInput,
|
||||||
) => {
|
): void => {
|
||||||
const boundaries = parsed.boundaries?.result;
|
const boundaryInput = parsed.boundaries;
|
||||||
if (boundaries === undefined)
|
if (boundaryInput === null) return;
|
||||||
return { pinvoke_imports: 0, native_implementations: 0 };
|
const boundaries = boundaryInput.result;
|
||||||
const { pinvoke_imports: pinvokes, native_implementations: implementations } =
|
const { pinvoke_imports: pinvokes, native_implementations: implementations } =
|
||||||
boundaries;
|
boundaries;
|
||||||
const pinvokeCoverage = managedSourceCoverage(boundaries.coverage.state);
|
const pinvokeCoverage = managedSourceCoverage(boundaries.coverage.state);
|
||||||
const implementationCoverage = managedSourceCoverage(
|
const implementationCoverage = managedSourceCoverage(
|
||||||
boundaries.coverage.state,
|
boundaries.coverage.state,
|
||||||
);
|
);
|
||||||
|
const sourceEvidence = sourceManagedEvidence(
|
||||||
|
state,
|
||||||
|
boundaryInput.evidence,
|
||||||
|
boundaries.coverage.state,
|
||||||
|
);
|
||||||
for (const pinvoke of pinvokes) {
|
for (const pinvoke of pinvokes) {
|
||||||
const node = pinvokeNode(state, pinvoke, pinvokeCoverage);
|
const node = pinvokeNode(state, pinvoke, sourceEvidence);
|
||||||
state.nodes.push(node);
|
state.nodes.push(node);
|
||||||
const owner =
|
const method =
|
||||||
pinvoke.member_token === null
|
pinvoke.member_token === null
|
||||||
? artifactNode
|
? undefined
|
||||||
: (state.methodNodes.get(pinvoke.member_token) ?? artifactNode);
|
: state.methodNodes.get(pinvoke.member_token);
|
||||||
|
const memberEvidence =
|
||||||
|
method === undefined || parsed.members === null
|
||||||
|
? undefined
|
||||||
|
: parsed.members.evidence;
|
||||||
|
const owner = method ?? artifactNode;
|
||||||
state.edges.push(
|
state.edges.push(
|
||||||
createJavaScriptApplicationEdge({
|
createJavaScriptApplicationEdge({
|
||||||
source_node_id: owner.node_id,
|
source_node_id: owner.node_id,
|
||||||
@@ -315,10 +354,11 @@ export const addBoundaryNodes = (
|
|||||||
import_name: pinvoke.import_name,
|
import_name: pinvoke.import_name,
|
||||||
import_scope_name: pinvoke.import_scope_name,
|
import_scope_name: pinvoke.import_scope_name,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(
|
evidence: pinvokeAssociationEvidence(
|
||||||
state,
|
state,
|
||||||
"inspect_managed_native_boundaries",
|
boundaryInput.evidence,
|
||||||
pinvokeCoverage,
|
pinvokeCoverage,
|
||||||
|
memberEvidence,
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -327,7 +367,7 @@ export const addBoundaryNodes = (
|
|||||||
const node = nativeImplementationNode(
|
const node = nativeImplementationNode(
|
||||||
state,
|
state,
|
||||||
implementation,
|
implementation,
|
||||||
implementationCoverage,
|
sourceEvidence,
|
||||||
);
|
);
|
||||||
state.nodes.push(node);
|
state.nodes.push(node);
|
||||||
const owner = state.methodNodes.get(implementation.token) ?? artifactNode;
|
const owner = state.methodNodes.get(implementation.token) ?? artifactNode;
|
||||||
@@ -336,17 +376,13 @@ export const addBoundaryNodes = (
|
|||||||
coverage: implementationCoverage,
|
coverage: implementationCoverage,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return {
|
|
||||||
pinvoke_imports: pinvokes.length,
|
|
||||||
native_implementations: implementations.length,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Build a managed P/Invoke import application node. */
|
/** Build a managed P/Invoke import application node. */
|
||||||
const pinvokeNode = (
|
const pinvokeNode = (
|
||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
pinvoke: PinvokeImport,
|
pinvoke: PinvokeImport,
|
||||||
coverage: ApplicationGraphEvidence["coverage"],
|
evidence: ApplicationGraphEvidence,
|
||||||
): ApplicationNode =>
|
): ApplicationNode =>
|
||||||
createJavaScriptApplicationNode({
|
createJavaScriptApplicationNode({
|
||||||
kind: "managed-pinvoke-import",
|
kind: "managed-pinvoke-import",
|
||||||
@@ -368,11 +404,7 @@ const pinvokeNode = (
|
|||||||
call_convention: pinvoke.call_convention,
|
call_convention: pinvoke.call_convention,
|
||||||
verification: pinvoke.verification,
|
verification: pinvoke.verification,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(
|
evidence,
|
||||||
state,
|
|
||||||
"inspect_managed_native_boundaries",
|
|
||||||
coverage,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -381,7 +413,7 @@ const pinvokeNode = (
|
|||||||
const nativeImplementationNode = (
|
const nativeImplementationNode = (
|
||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
implementation: NativeImplementation,
|
implementation: NativeImplementation,
|
||||||
coverage: ApplicationGraphEvidence["coverage"],
|
evidence: ApplicationGraphEvidence,
|
||||||
): ApplicationNode =>
|
): ApplicationNode =>
|
||||||
createJavaScriptApplicationNode({
|
createJavaScriptApplicationNode({
|
||||||
kind: "managed-native-implementation",
|
kind: "managed-native-implementation",
|
||||||
@@ -403,11 +435,7 @@ const nativeImplementationNode = (
|
|||||||
boundary_kind: implementation.boundary_kind,
|
boundary_kind: implementation.boundary_kind,
|
||||||
body_interpretation: implementation.body_interpretation,
|
body_interpretation: implementation.body_interpretation,
|
||||||
},
|
},
|
||||||
evidence: managedEvidence(
|
evidence,
|
||||||
state,
|
|
||||||
"inspect_managed_native_boundaries",
|
|
||||||
coverage,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
@@ -425,7 +453,7 @@ const addContainsEdge = (
|
|||||||
target_node_id: target.node_id,
|
target_node_id: target.node_id,
|
||||||
relation: "contains",
|
relation: "contains",
|
||||||
properties: { kind: options.kind },
|
properties: { kind: options.kind },
|
||||||
evidence: managedEvidence(
|
evidence: projectedManagedEvidence(
|
||||||
state,
|
state,
|
||||||
"project-managed-contains",
|
"project-managed-contains",
|
||||||
options.coverage,
|
options.coverage,
|
||||||
@@ -448,12 +476,43 @@ const artifactLocalIdentity = (
|
|||||||
});
|
});
|
||||||
|
|
||||||
/** Build managed static-analysis evidence for a graph observation. */
|
/** Build managed static-analysis evidence for a graph observation. */
|
||||||
const managedEvidence = (
|
const sourceManagedEvidence = (
|
||||||
|
state: GraphBuildState,
|
||||||
|
source: Evidence,
|
||||||
|
coverageState: ManagedArtifactInspection["coverage"]["state"],
|
||||||
|
): ApplicationGraphEvidence =>
|
||||||
|
createManagedEvidence(
|
||||||
|
state,
|
||||||
|
source.operation,
|
||||||
|
managedSourceCoverage(coverageState),
|
||||||
|
[source.evidence_id],
|
||||||
|
);
|
||||||
|
|
||||||
|
const projectedManagedEvidence = (
|
||||||
state: GraphBuildState,
|
state: GraphBuildState,
|
||||||
operation: string,
|
operation: string,
|
||||||
coverage: ApplicationGraphEvidence["coverage"] = managedSourceCoverage(
|
coverage: ApplicationGraphEvidence["coverage"] = managedSourceCoverage(
|
||||||
"complete",
|
"complete",
|
||||||
),
|
),
|
||||||
|
): ApplicationGraphEvidence =>
|
||||||
|
createManagedEvidence(state, operation, coverage, state.evidenceLinks);
|
||||||
|
|
||||||
|
const pinvokeAssociationEvidence = (
|
||||||
|
state: GraphBuildState,
|
||||||
|
boundaryEvidence: Evidence,
|
||||||
|
coverage: ApplicationGraphEvidence["coverage"],
|
||||||
|
memberEvidence: Evidence | undefined,
|
||||||
|
): ApplicationGraphEvidence =>
|
||||||
|
createManagedEvidence(state, boundaryEvidence.operation, coverage, [
|
||||||
|
boundaryEvidence.evidence_id,
|
||||||
|
...(memberEvidence === undefined ? [] : [memberEvidence.evidence_id]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const createManagedEvidence = (
|
||||||
|
state: GraphBuildState,
|
||||||
|
operation: string,
|
||||||
|
coverage: ApplicationGraphEvidence["coverage"],
|
||||||
|
evidenceIds: readonly string[],
|
||||||
): ApplicationGraphEvidence => ({
|
): ApplicationGraphEvidence => ({
|
||||||
authority: "managed-static-analysis",
|
authority: "managed-static-analysis",
|
||||||
state: "observed",
|
state: "observed",
|
||||||
@@ -483,7 +542,7 @@ const managedEvidence = (
|
|||||||
: [
|
: [
|
||||||
"The source managed Evidence slice is incomplete; unreturned or unavailable items remain unobserved.",
|
"The source managed Evidence slice is incomplete; unreturned or unavailable items remain unobserved.",
|
||||||
],
|
],
|
||||||
evidence_ids: state.evidenceLinks,
|
evidence_ids: [...evidenceIds],
|
||||||
});
|
});
|
||||||
|
|
||||||
/** Sanitize an artifact path into a managed graph location. */
|
/** Sanitize an artifact path into a managed graph location. */
|
||||||
|
|||||||
@@ -16,43 +16,51 @@ import {
|
|||||||
managedPeFixtureTarget,
|
managedPeFixtureTarget,
|
||||||
} from "../../../src/dotnet/ManagedPe.fixture.js";
|
} from "../../../src/dotnet/ManagedPe.fixture.js";
|
||||||
|
|
||||||
describe("managed application graph projection", () => {
|
const createManagedInteropEvidence = () => {
|
||||||
it("projects managed metadata and native declarations into authenticated graph Evidence", () => {
|
const bytes = buildManagedPeFixture({
|
||||||
const bytes = buildManagedPeFixture({
|
pinvoke: {
|
||||||
pinvoke: {
|
moduleName: "user32.dll",
|
||||||
moduleName: "user32.dll",
|
importName: "MessageBoxW",
|
||||||
importName: "MessageBoxW",
|
mappingFlags: 0x0345,
|
||||||
mappingFlags: 0x0345,
|
},
|
||||||
},
|
});
|
||||||
});
|
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
|
||||||
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
|
const managedArtifact = inspectManagedArtifactBytes(bytes, binary);
|
||||||
const managedArtifact = inspectManagedArtifactBytes(bytes, binary);
|
const members = inspectManagedMembersBytes(bytes, binary);
|
||||||
const members = inspectManagedMembersBytes(bytes, binary);
|
const boundaries = inspectManagedNativeBoundariesBytes(bytes, binary);
|
||||||
const boundaries = inspectManagedNativeBoundariesBytes(bytes, binary);
|
|
||||||
const artifactEvidence = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
return {
|
||||||
|
artifactEvidence: createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||||
operation: "inspect_managed_artifact",
|
operation: "inspect_managed_artifact",
|
||||||
parameters: {},
|
parameters: {},
|
||||||
result: managedArtifact,
|
result: managedArtifact,
|
||||||
rawResult: null,
|
rawResult: null,
|
||||||
limitations: managedArtifact.limitations,
|
limitations: managedArtifact.limitations,
|
||||||
locations: [{ kind: "artifact-path", path: binary.path }],
|
locations: [{ kind: "artifact-path", path: binary.path }],
|
||||||
});
|
}),
|
||||||
const memberEvidence = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
memberEvidence: createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||||
operation: "inspect_managed_members",
|
operation: "inspect_managed_members",
|
||||||
parameters: {},
|
parameters: {},
|
||||||
result: members,
|
result: members,
|
||||||
rawResult: null,
|
rawResult: null,
|
||||||
limitations: members.limitations,
|
limitations: members.limitations,
|
||||||
locations: [{ kind: "artifact-path", path: binary.path }],
|
locations: [{ kind: "artifact-path", path: binary.path }],
|
||||||
});
|
}),
|
||||||
const boundaryEvidence = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
boundaryEvidence: createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||||
operation: "inspect_managed_native_boundaries",
|
operation: "inspect_managed_native_boundaries",
|
||||||
parameters: {},
|
parameters: {},
|
||||||
result: boundaries,
|
result: boundaries,
|
||||||
rawResult: null,
|
rawResult: null,
|
||||||
limitations: boundaries.limitations,
|
limitations: boundaries.limitations,
|
||||||
locations: [{ kind: "artifact-path", path: binary.path }],
|
locations: [{ kind: "artifact-path", path: binary.path }],
|
||||||
});
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("managed application graph projection", () => {
|
||||||
|
it("projects managed metadata and native declarations into authenticated graph Evidence", () => {
|
||||||
|
const { artifactEvidence, memberEvidence, boundaryEvidence } =
|
||||||
|
createManagedInteropEvidence();
|
||||||
|
|
||||||
const evidence = projectManagedApplicationGraphEvidence({
|
const evidence = projectManagedApplicationGraphEvidence({
|
||||||
managed_artifact: artifactEvidence,
|
managed_artifact: artifactEvidence,
|
||||||
@@ -103,21 +111,51 @@ describe("managed application graph projection", () => {
|
|||||||
"managed-pinvoke-import",
|
"managed-pinvoke-import",
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
const allEvidenceIds = [
|
||||||
|
artifactEvidence.evidence_id,
|
||||||
|
memberEvidence.evidence_id,
|
||||||
|
boundaryEvidence.evidence_id,
|
||||||
|
].sort();
|
||||||
|
const observedEvidenceIds = (kind: string): readonly string[] => {
|
||||||
|
const observation = graph.nodes.find((node) => node.kind === kind)
|
||||||
|
?.observations[0];
|
||||||
|
if (observation === undefined)
|
||||||
|
throw new Error(`Expected ${kind} observation`);
|
||||||
|
return observation.evidence.evidence_ids;
|
||||||
|
};
|
||||||
|
expect(observedEvidenceIds("artifact")).toEqual(allEvidenceIds);
|
||||||
|
expect(observedEvidenceIds("managed-assembly")).toEqual([
|
||||||
|
artifactEvidence.evidence_id,
|
||||||
|
]);
|
||||||
|
expect(observedEvidenceIds("managed-module")).toEqual([
|
||||||
|
artifactEvidence.evidence_id,
|
||||||
|
]);
|
||||||
|
for (const kind of ["managed-type", "managed-method", "managed-field"])
|
||||||
|
expect(observedEvidenceIds(kind)).toEqual([memberEvidence.evidence_id]);
|
||||||
|
expect(observedEvidenceIds("managed-pinvoke-import")).toEqual([
|
||||||
|
boundaryEvidence.evidence_id,
|
||||||
|
]);
|
||||||
|
for (const edge of graph.edges.filter(
|
||||||
|
({ relation }) => relation === "contains",
|
||||||
|
))
|
||||||
|
expect(edge.evidence.evidence_ids).toEqual(allEvidenceIds);
|
||||||
const method = graph.nodes.find(
|
const method = graph.nodes.find(
|
||||||
({ kind, observations }) =>
|
({ kind, observations }) =>
|
||||||
kind === "managed-method" &&
|
kind === "managed-method" &&
|
||||||
observations[0]?.label === "Fixture.Program.Main",
|
observations[0]?.label === "Fixture.Program.Main",
|
||||||
);
|
);
|
||||||
expect(method).toBeDefined();
|
expect(method).toBeDefined();
|
||||||
expect(
|
const importEdge = graph.edges.find(
|
||||||
graph.edges.some(
|
({ source_node_id, relation, target_node_id }) =>
|
||||||
({ source_node_id, relation, target_node_id }) =>
|
source_node_id === method?.node_id &&
|
||||||
source_node_id === method?.node_id &&
|
relation === "imports" &&
|
||||||
relation === "imports" &&
|
graph.nodes.find(({ node_id: id }) => id === target_node_id)?.kind ===
|
||||||
graph.nodes.find(({ node_id: id }) => id === target_node_id)?.kind ===
|
"managed-pinvoke-import",
|
||||||
"managed-pinvoke-import",
|
);
|
||||||
),
|
expect(importEdge).toBeDefined();
|
||||||
).toBe(true);
|
expect(importEdge?.evidence.evidence_ids).toEqual(
|
||||||
|
[memberEvidence.evidence_id, boundaryEvidence.evidence_id].sort(),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
graph.nodes.flatMap(({ observations }) =>
|
graph.nodes.flatMap(({ observations }) =>
|
||||||
observations.map(({ evidence }) => evidence.authority),
|
observations.map(({ evidence }) => evidence.authority),
|
||||||
@@ -167,7 +205,7 @@ describe("managed application graph request", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("managed application graph coverage", () => {
|
describe("managed application graph coverage", () => {
|
||||||
it("rejects managed Evidence digest mismatch and discloses missing artifact observations", () => {
|
it("rejects managed Evidence whose artifact digest differs from its subject", () => {
|
||||||
const bytes = buildManagedPeFixture();
|
const bytes = buildManagedPeFixture();
|
||||||
const binary = managedPeFixtureTarget(bytes, "/fixture/Mismatch.dll");
|
const binary = managedPeFixtureTarget(bytes, "/fixture/Mismatch.dll");
|
||||||
const members = inspectManagedMembersBytes(bytes, binary);
|
const members = inspectManagedMembersBytes(bytes, binary);
|
||||||
@@ -191,7 +229,14 @@ describe("managed application graph coverage", () => {
|
|||||||
expect(JSON.stringify(rejected.error)).toContain(
|
expect(JSON.stringify(rejected.error)).toContain(
|
||||||
`Managed Evidence inspect_managed_members (${mismatched.evidence_id}) subject SHA-256 ${binary.sha256} does not match normalized artifact SHA-256 ${"b".repeat(64)}`,
|
`Managed Evidence inspect_managed_members (${mismatched.evidence_id}) subject SHA-256 ${binary.sha256} does not match normalized artifact SHA-256 ${"b".repeat(64)}`,
|
||||||
);
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("managed application graph identity facts", () => {
|
||||||
|
it("uses member Evidence for its module and reports only emitted identity nodes", () => {
|
||||||
|
const bytes = buildManagedPeFixture();
|
||||||
|
const binary = managedPeFixtureTarget(bytes, "/fixture/MembersOnly.dll");
|
||||||
|
const members = inspectManagedMembersBytes(bytes, binary);
|
||||||
const aligned = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
const aligned = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||||
operation: "inspect_managed_members",
|
operation: "inspect_managed_members",
|
||||||
parameters: {},
|
parameters: {},
|
||||||
@@ -204,11 +249,92 @@ describe("managed application graph coverage", () => {
|
|||||||
const result = managedApplicationGraphResultSchema.parse(
|
const result = managedApplicationGraphResultSchema.parse(
|
||||||
parseEvidence(projected.value).normalized_result,
|
parseEvidence(projected.value).normalized_result,
|
||||||
);
|
);
|
||||||
|
const graph = parseJavaScriptApplicationGraph(result.graph);
|
||||||
|
expect(result.summary).toMatchObject({ assemblies: 0, modules: 1 });
|
||||||
|
expect(
|
||||||
|
graph.nodes.find(({ kind }) => kind === "managed-module")
|
||||||
|
?.observations[0],
|
||||||
|
).toMatchObject({
|
||||||
|
evidence: {
|
||||||
|
extractor: { operation: "inspect_managed_members" },
|
||||||
|
evidence_ids: [aligned.evidence_id],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(result.evidence_links).toEqual([aligned.evidence_id]);
|
||||||
expect(result.limitations).toContain(
|
expect(result.limitations).toContain(
|
||||||
"Managed artifact Evidence was not supplied; assembly identity observations are absent.",
|
"Managed artifact Evidence was not supplied; assembly identity observations are absent.",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("binds a boundaries-only module node to the boundary Evidence that supplied it", () => {
|
||||||
|
const bytes = buildManagedPeFixture();
|
||||||
|
const binary = managedPeFixtureTarget(bytes, "/fixture/BoundariesOnly.dll");
|
||||||
|
const boundaries = inspectManagedNativeBoundariesBytes(bytes, binary);
|
||||||
|
const boundaryEvidence = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||||
|
operation: "inspect_managed_native_boundaries",
|
||||||
|
parameters: {},
|
||||||
|
result: boundaries,
|
||||||
|
rawResult: null,
|
||||||
|
limitations: boundaries.limitations,
|
||||||
|
locations: [{ kind: "artifact-path", path: binary.path }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const projected = projectManagedApplicationGraphEvidence({
|
||||||
|
managed_native_boundaries: boundaryEvidence,
|
||||||
|
});
|
||||||
|
if (!projected.ok) throw projected.error;
|
||||||
|
const result = managedApplicationGraphResultSchema.parse(
|
||||||
|
parseEvidence(projected.value).normalized_result,
|
||||||
|
);
|
||||||
|
const graph = parseJavaScriptApplicationGraph(result.graph);
|
||||||
|
expect(result.summary).toMatchObject({ assemblies: 0, modules: 1 });
|
||||||
|
expect(
|
||||||
|
graph.nodes.find(({ kind }) => kind === "managed-module")
|
||||||
|
?.observations[0],
|
||||||
|
).toMatchObject({
|
||||||
|
evidence: {
|
||||||
|
extractor: { operation: "inspect_managed_native_boundaries" },
|
||||||
|
evidence_ids: [boundaryEvidence.evidence_id],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(result.evidence_links).toEqual([boundaryEvidence.evidence_id]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reports no assembly or module when the inspector observes no identity rows", () => {
|
||||||
|
const bytes = buildManagedPeFixture({
|
||||||
|
moduleRowCount: 0,
|
||||||
|
assemblyRowCount: 0,
|
||||||
|
});
|
||||||
|
const binary = managedPeFixtureTarget(bytes, "/fixture/NoIdentityRows.exe");
|
||||||
|
const inspection = inspectManagedArtifactBytes(bytes, binary);
|
||||||
|
expect(inspection).toMatchObject({ module: null, assembly: null });
|
||||||
|
const artifactEvidence = createEvidence(binary, MANAGED_STATIC_PROVIDER, {
|
||||||
|
operation: "inspect_managed_artifact",
|
||||||
|
parameters: {},
|
||||||
|
result: inspection,
|
||||||
|
rawResult: null,
|
||||||
|
limitations: inspection.limitations,
|
||||||
|
locations: [{ kind: "artifact-path", path: binary.path }],
|
||||||
|
});
|
||||||
|
|
||||||
|
const projected = projectManagedApplicationGraphEvidence({
|
||||||
|
managed_artifact: artifactEvidence,
|
||||||
|
});
|
||||||
|
if (!projected.ok) throw projected.error;
|
||||||
|
const result = managedApplicationGraphResultSchema.parse(
|
||||||
|
parseEvidence(projected.value).normalized_result,
|
||||||
|
);
|
||||||
|
const graph = parseJavaScriptApplicationGraph(result.graph);
|
||||||
|
expect(result.summary).toMatchObject({ assemblies: 0, modules: 0 });
|
||||||
|
expect(
|
||||||
|
graph.nodes.filter(
|
||||||
|
({ kind }) => kind === "managed-assembly" || kind === "managed-module",
|
||||||
|
),
|
||||||
|
).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("managed application graph coverage", () => {
|
||||||
it("preserves partial parser coverage in graph and per-fact coverage", () => {
|
it("preserves partial parser coverage in graph and per-fact coverage", () => {
|
||||||
const bytes = buildManagedPeFixture();
|
const bytes = buildManagedPeFixture();
|
||||||
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
|
const binary = managedPeFixtureTarget(bytes, "/fixture/ManagedInterop.exe");
|
||||||
|
|||||||
Reference in New Issue
Block a user