Merge commit '5100a1a1a56b810c8246b8c7ed19ff42c4d9dbe1' into fix/ci-duplicate-boundaries-1603

This commit is contained in:
N0zoM1z0
2026-10-11 03:50:21 +08:00
120 changed files with 5518 additions and 1142 deletions
@@ -8,6 +8,10 @@ import { MANAGED_STATIC_PROVIDER } from "../../../src/application/InvestigationP
import { createEvidence, parseEvidence } from "../../../src/domain/evidence.js";
import { parseJavaScriptApplicationGraph } from "../../../src/domain/javascript/javascriptApplicationGraph.js";
import { managedApplicationGraphResultSchema } from "../../../src/domain/managed/managedApplicationGraph.js";
import {
managedMemberInspectionSchema,
managedNativeBoundaryInspectionSchema,
} from "../../../src/domain/managed/managedArtifact.js";
import { inspectManagedArtifactBytes } from "../../../src/dotnet/ManagedArtifactInspector.js";
import { inspectManagedMembersBytes } from "../../../src/dotnet/ManagedMemberInspector.js";
import { inspectManagedNativeBoundariesBytes } from "../../../src/dotnet/ManagedNativeBoundaryInspector.js";
@@ -299,6 +303,282 @@ describe("managed application graph identity facts", () => {
});
});
it("normalizes MVID casing for node identity while preserving observed values", () => {
const { memberEvidence, boundaryEvidence } = createManagedInteropEvidence();
const members = managedMemberInspectionSchema.parse(
parseEvidence(memberEvidence).normalized_result,
);
if (members.module === null)
throw new Error("Expected fixture module identity");
const uppercaseMvid = members.module.mvid?.toUpperCase();
if (uppercaseMvid === undefined || uppercaseMvid === null)
throw new Error("Expected fixture module MVID");
const uppercaseMembers = createEvidence(undefined, MANAGED_STATIC_PROVIDER, {
operation: "inspect_managed_members",
parameters: {},
result: {
...members,
module: {
...members.module,
mvid: uppercaseMvid,
enc_id: null,
enc_base_id: null,
},
identity_scope: {
...members.identity_scope,
requires_mvid: uppercaseMvid,
},
},
rawResult: null,
limitations: members.limitations,
});
const baseline = projectManagedApplicationGraphEvidence({
managed_members: memberEvidence,
managed_native_boundaries: boundaryEvidence,
});
const uppercase = projectManagedApplicationGraphEvidence({
managed_members: uppercaseMembers,
managed_native_boundaries: boundaryEvidence,
});
if (!baseline.ok) throw baseline.error;
if (!uppercase.ok) throw uppercase.error;
const baselineResult = managedApplicationGraphResultSchema.parse(
parseEvidence(baseline.value).normalized_result,
);
const uppercaseResult = managedApplicationGraphResultSchema.parse(
parseEvidence(uppercase.value).normalized_result,
);
const baselineModule = parseJavaScriptApplicationGraph(
baselineResult.graph,
).nodes.find(({ kind }) => kind === "managed-module");
const uppercaseGraph = parseJavaScriptApplicationGraph(uppercaseResult.graph);
const uppercaseModule = uppercaseGraph.nodes.find(
({ kind }) => kind === "managed-module",
);
expect(uppercaseGraph.edges).toContainEqual(
expect.objectContaining({
relation: "imports",
source_node_id: uppercaseGraph.nodes.find(
({ kind }) => kind === "managed-method",
)?.node_id,
}),
);
expect(uppercaseModule?.node_id).toBe(baselineModule?.node_id);
expect(uppercaseModule?.observations[0]?.properties.mvid).toBe(uppercaseMvid);
});
describe("managed application graph module identity consistency", () => {
it("rejects contradictory known module MVIDs across same-artifact inputs", () => {
const { artifactEvidence, memberEvidence, boundaryEvidence } =
createManagedInteropEvidence();
const boundaries = managedNativeBoundaryInspectionSchema.parse(
parseEvidence(boundaryEvidence).normalized_result,
);
const conflictingMvid = "ffffffff-ffff-ffff-ffff-ffffffffffff";
const conflictingBoundaries = createEvidence(
undefined,
MANAGED_STATIC_PROVIDER,
{
operation: "inspect_managed_native_boundaries",
parameters: {},
result: {
...boundaries,
module:
boundaries.module === null
? null
: { ...boundaries.module, mvid: conflictingMvid },
identity_scope: {
...boundaries.identity_scope,
requires_mvid: conflictingMvid,
},
},
rawResult: null,
limitations: boundaries.limitations,
},
);
const projected = projectManagedApplicationGraphEvidence({
managed_artifact: artifactEvidence,
managed_members: memberEvidence,
managed_native_boundaries: conflictingBoundaries,
});
expect(projected.ok).toBe(false);
if (projected.ok) throw new Error("conflicting MVIDs were accepted");
expect(JSON.stringify(projected.error)).toContain(
"conflicting known module MVIDs or token scopes",
);
});
it("rejects contradictory known module declaration fields", () => {
const { artifactEvidence, memberEvidence } = createManagedInteropEvidence();
const members = managedMemberInspectionSchema.parse(
parseEvidence(memberEvidence).normalized_result,
);
if (members.module === null)
throw new Error("Expected fixture module identity");
const conflictingMembers = createEvidence(
undefined,
MANAGED_STATIC_PROVIDER,
{
operation: "inspect_managed_members",
parameters: {},
result: {
...members,
module: {
...members.module,
generation: members.module.generation + 1,
},
},
rawResult: null,
limitations: members.limitations,
},
);
const projected = projectManagedApplicationGraphEvidence({
managed_artifact: artifactEvidence,
managed_members: conflictingMembers,
});
expect(projected.ok).toBe(false);
if (projected.ok)
throw new Error("conflicting module declaration was accepted");
expect(JSON.stringify(projected.error)).toContain(
"conflicting module generation values",
);
});
});
describe("managed application graph token scope", () => {
it("checks declared token artifact and MVID scopes without a subject digest", () => {
const { memberEvidence } = createManagedInteropEvidence();
const members = managedMemberInspectionSchema.parse(
parseEvidence(memberEvidence).normalized_result,
);
const wrongMvidValue = "ffffffff-ffff-ffff-ffff-ffffffffffff";
const wrongMvidEvidence = createEvidence(
undefined,
MANAGED_STATIC_PROVIDER,
{
operation: "inspect_managed_members",
parameters: {},
result: {
...members,
identity_scope: {
...members.identity_scope,
requires_mvid: wrongMvidValue,
},
},
rawResult: null,
limitations: members.limitations,
},
);
const wrongArtifactEvidence = createEvidence(
undefined,
MANAGED_STATIC_PROVIDER,
{
operation: "inspect_managed_members",
parameters: {},
result: {
...members,
identity_scope: {
...members.identity_scope,
requires_artifact_sha256: "b".repeat(64),
},
},
rawResult: null,
limitations: members.limitations,
},
);
const wrongMvidResult = projectManagedApplicationGraphEvidence({
managed_members: wrongMvidEvidence,
});
expect(wrongMvidResult.ok).toBe(false);
if (wrongMvidResult.ok)
throw new Error("mismatched token MVID was accepted");
expect(JSON.stringify(wrongMvidResult.error)).toContain("token scope MVID");
const wrongArtifact = projectManagedApplicationGraphEvidence({
managed_members: wrongArtifactEvidence,
});
expect(wrongArtifact.ok).toBe(false);
if (wrongArtifact.ok)
throw new Error("mismatched token artifact digest was accepted");
expect(JSON.stringify(wrongArtifact.error)).toContain(
"token scope SHA-256",
);
});
});
describe("unknown managed application graph token scope", () => {
it("keeps absent MVID scope unknown and marks cross-source token joins partial", () => {
const { memberEvidence, boundaryEvidence } = createManagedInteropEvidence();
const members = managedMemberInspectionSchema.parse(
parseEvidence(memberEvidence).normalized_result,
);
const boundaries = managedNativeBoundaryInspectionSchema.parse(
parseEvidence(boundaryEvidence).normalized_result,
);
const unknownMembers = createEvidence(undefined, MANAGED_STATIC_PROVIDER, {
operation: "inspect_managed_members",
parameters: {},
result: {
...members,
module:
members.module === null
? null
: {
...members.module,
mvid: null,
enc_id: null,
enc_base_id: null,
},
identity_scope: { ...members.identity_scope, requires_mvid: null },
},
rawResult: null,
limitations: members.limitations,
});
const projected = projectManagedApplicationGraphEvidence({
managed_members: unknownMembers,
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.modules).toBe(1);
expect(result.coverage.status).toBe("partial");
expect(result.limitations).toContain(
"Managed boundary tokens were not linked to member nodes because matching module MVID scope was not established.",
);
const moduleObservation = graph.nodes.find(
({ kind }) => kind === "managed-module",
)?.observations[0];
expect(moduleObservation?.properties.mvid).toBe(boundaries.module?.mvid);
expect(moduleObservation?.evidence.extractor.operation).toBe(
"inspect_managed_native_boundaries",
);
const method = graph.nodes.find(
({ kind, observations }) =>
kind === "managed-method" &&
observations[0]?.label === "Fixture.Program.Main",
);
expect(method).toBeDefined();
const importEdge = graph.edges.find(
({ relation, target_node_id }) =>
relation === "imports" &&
graph.nodes.find(({ node_id }) => node_id === target_node_id)?.kind ===
"managed-pinvoke-import",
);
expect(importEdge).toBeDefined();
expect(
graph.nodes.find(({ node_id }) => node_id === importEdge?.source_node_id)
?.kind,
).toBe("artifact");
});
});
describe("managed application graph coverage", () => {
it("preserves partial parser coverage in graph and per-fact coverage", () => {
const bytes = buildManagedPeFixture();
@@ -186,6 +186,40 @@ it("matches renderer, frame, script bytes, and worker without claiming execution
);
});
it("keeps static load states unknown when one scoped capture omits scripts", async () => {
const fixture = await applicationFixture();
const staticEvidence = await analyzeFixture(fixture);
const result = reconcileInput({
static_layers: [{ role: "application", analysis: staticEvidence }],
runtime_observations: [
electronRuntimeEvidence(fixture, SOURCE, {
includeWorker: false,
targetId: "target-complete",
}),
electronRuntimeEvidence(fixture, SOURCE, {
includeWorker: false,
scriptsUnavailable: true,
targetId: "target-incomplete",
}),
],
});
expect(
result.runtime_captures.map(
({ scripts_complete_within_scope }) => scripts_complete_within_scope,
),
).toEqual(expect.arrayContaining([false, true]));
expect(result.summary.static_not_observed).toBe(0);
expect(result.static_load_states).toEqual(
expect.arrayContaining([
expect.objectContaining({
status: "unknown",
reason: "static-or-runtime-coverage-incomplete",
}),
]),
);
});
it("reports a captured digest disagreement instead of accepting a path match", async () => {
const fixture = await applicationFixture();
const staticEvidence = await analyzeFixture(fixture);
@@ -316,7 +350,7 @@ it("imports an operator-provided cache layer through an explicit file mapping",
const application = await applicationFixture();
const cache = await createTestTempDirectory("rea-runtime-cache-static-");
const runtimeCache = await createTestTempDirectory("rea-runtime-cache-live-");
const cacheSource = "export const cachedFeature = 'fixture';\n";
const cacheSource = SOURCE;
await mkdir(join(cache, "mapped"));
await Promise.all([
writeFile(join(cache, "mapped", "chunk.js"), cacheSource),
@@ -373,6 +407,16 @@ it("imports an operator-provided cache layer through an explicit file mapping",
status: "unknown",
reason: "layer-outside-runtime-scope",
});
const sharedFile = result.graph.nodes.find(
({ observations }) =>
observations.some(({ properties }) => properties.path === "app.js") &&
observations.some(
({ properties }) => properties.path === "mapped/chunk.js",
),
);
expect(
sharedFile?.observations.map(({ properties }) => properties.path),
).toEqual(expect.arrayContaining(["app.js", "mapped/chunk.js"]));
});
const applicationFixture = async (): Promise<string> => {
@@ -410,6 +454,7 @@ const electronRuntimeEvidence = (
readonly targetId?: string;
readonly sourceIncluded?: boolean;
readonly workersUnavailable?: boolean;
readonly scriptsUnavailable?: boolean;
} = {},
) => {
const scriptFile = options.scriptFile ?? "app.js";
@@ -445,15 +490,7 @@ const electronRuntimeEvidence = (
ended_at: "2026-07-15T00:00:00.100Z",
observation_ms: 100,
},
completeness: options.workersUnavailable
? {
...completeCapture(),
status: "attach_limited" as const,
conditions: ["attach_limited" as const],
attach_limited_sections: ["workers" as const],
unavailable_sections: ["workers" as const],
}
: completeCapture(),
completeness: captureCompleteness(options),
frames: [
{
frame_id: "frame-main",
@@ -522,3 +559,21 @@ const completeCapture = () => ({
total: 0,
},
});
const captureCompleteness = (options: {
readonly workersUnavailable?: boolean;
readonly scriptsUnavailable?: boolean;
}) => {
const unavailableSections = [
...(options.scriptsUnavailable ? (["scripts"] as const) : []),
...(options.workersUnavailable ? (["workers"] as const) : []),
];
if (unavailableSections.length === 0) return completeCapture();
return {
...completeCapture(),
status: "attach_limited" as const,
conditions: ["attach_limited" as const],
attach_limited_sections: unavailableSections,
unavailable_sections: unavailableSections,
};
};