refactor!: enforce canonical evidence and provider boundaries

Deliver complete Evidence directly through MCP with required nullable analysis profiles and immutable per-server delivery settings. Bind selected environments at construction and require typed cleanup outcomes with retained retry ownership.

Remove test-only routing, duplicate session and snapshot metadata, producer-field repairs, and ambiguous provider arguments. Separate artifact byte identity from occurrence classification and retain typed source-map and partial native facts across CLI, MCP, and verifier consumers.

BREAKING CHANGE: obsolete Evidence envelopes, session aliases, incomplete snapshots, and missing normalized producer facts are no longer accepted.
This commit is contained in:
morluto
2026-10-09 20:18:52 +08:00
parent 2a7746998d
commit 63bf91405c
514 changed files with 9296 additions and 5825 deletions
@@ -1,10 +1,34 @@
import { electronActiveObservationResultSchema } from "./electronActiveObservation.js";
import {
electronActiveObservationResultSchema,
type ElectronActiveObservationResult,
} from "./electronActiveObservation.js";
/** Create an active-capture result for MCP contract tests. */
export const createElectronActiveObservationFixtureResult = (
applicationPath: string,
) =>
electronActiveObservationResultSchema.parse({
): ElectronActiveObservationResult => {
const event: ElectronActiveObservationResult["timeline"]["events"][number] = {
sequence: 1,
correlation_id: null,
kind: "main-handler-invocation",
event: null,
phase: "observed",
channel: "readiness:echo",
direction: "renderer-to-main",
sender: null,
receiver: "main",
frame: null,
target: null,
argument_shapes: ["string"],
result_shape: "object",
process_type: "main",
source: "electron-active-hook",
capture_method: "api-wrapper",
artifact_path: null,
artifact_sha256: null,
error: false,
};
return electronActiveObservationResultSchema.parse({
application: {
executable_path: process.execPath,
application_path: applicationPath,
@@ -37,17 +61,12 @@ export const createElectronActiveObservationFixtureResult = (
items: [{ pid: 1234, type: "Browser", name: null, service_name: null }],
},
ipc: {
events: [
{
sequence: 1,
kind: "main-handler-invocation",
channel: "readiness:echo",
argument_shapes: ["string"],
result_shape: "object",
process_type: "main",
error: false,
},
],
events: [event],
observed: 1,
dropped: 0,
},
timeline: {
events: [event],
observed: 1,
dropped: 0,
},
@@ -64,7 +83,15 @@ export const createElectronActiveObservationFixtureResult = (
observed_runtime: 0,
dropped_runtime: 0,
},
coverage: {
status: "partial_attach",
observed_event_families: ["ipc"],
unavailable_event_families: ["renderer-ipc", "preload"],
observed_roles: ["main"],
pre_capture_activity: "unavailable",
},
limitations: [
"IPC payloads are represented by value shapes; payload values are never retained.",
],
});
};
@@ -89,58 +89,10 @@ export type ElectronActiveObservationInput = z.infer<
typeof electronActiveObservationInputSchema
>;
const ipcEventSchema = z.strictObject({
/** Canonical active Electron event shared by the hook boundary and public timeline. */
export const electronActiveTimelineEventSchema = z.strictObject({
sequence: z.number().int().min(1),
correlation_id: z.string().nullable().default(null),
kind: z.enum([
"main-handler-invocation",
"main-event-invocation",
"utility-process-fork",
"utility-process-message",
"ipc-main-to-renderer",
"ipc-utility-to-main",
"ipc-renderer-send",
"ipc-renderer-invoke",
"ipc-renderer-post-message",
]),
event: z.string().nullable().optional(),
phase: z
.enum(["attempted", "completed", "blocked", "failed", "observed"])
.nullable()
.optional(),
channel: z.string().nullable(),
direction: z
.enum([
"renderer-to-main",
"main-to-renderer",
"main-to-utility",
"utility-to-main",
])
.nullable()
.optional(),
sender: z.string().nullable().optional(),
receiver: z.string().nullable().optional(),
frame: z.string().nullable().default(null),
target: z.string().nullable().optional(),
argument_shapes: z.array(z.string()),
result_shape: z.string().nullable(),
process_type: z.string().nullable(),
source: z.string().default("electron-active-hook"),
capture_method: z
.enum(["api-wrapper", "event-emitter", "process-hook"])
.default("api-wrapper"),
artifact_path: z.string().nullable().default(null),
artifact_sha256: z
.string()
.regex(/^[a-f0-9]{64}$/u)
.nullable()
.default(null),
error: z.boolean(),
});
const timelineEventSchema = z.strictObject({
sequence: z.number().int().min(1),
correlation_id: z.string().nullable().default(null),
correlation_id: z.string().nullable(),
kind: z.enum([
"main-handler-invocation",
"main-event-invocation",
@@ -194,6 +146,20 @@ const timelineEventSchema = z.strictObject({
error: z.boolean(),
});
const ipcEventSchema = electronActiveTimelineEventSchema.extend({
kind: z.enum([
"main-handler-invocation",
"main-event-invocation",
"utility-process-fork",
"utility-process-message",
"ipc-main-to-renderer",
"ipc-utility-to-main",
"ipc-renderer-send",
"ipc-renderer-invoke",
"ipc-renderer-post-message",
]),
});
const processMetricSchema = z.strictObject({
pid: z.number().int().min(1),
type: z.string().min(1),
@@ -268,48 +234,37 @@ export const electronActiveObservationResultSchema = z.strictObject({
ipc: z.strictObject({
events: z.array(ipcEventSchema),
observed: z.number().int().min(0),
dropped: z.number().int().min(0).nullable().default(null),
dropped: z.number().int().min(0),
}),
timeline: z
.strictObject({
events: z.array(timelineEventSchema),
observed: z.number().int().min(0),
dropped: z.number().int().min(0).nullable().default(null),
})
.default({ events: [], observed: 0, dropped: null }),
retention: z
.strictObject({
budget_bytes: z.number().int().min(0),
estimated_retained_bytes: z.number().int().min(0),
event_serialized_byte_upper_bound: z.number().int().min(0),
retained: z.number().int().min(0),
dropped: z.number().int().min(0),
dropped_event_families: z.array(
z.strictObject({
family: z.string().min(1),
count: z.number().int().min(1),
}),
),
dropped_event_roles: z.array(
z.strictObject({
role: z.string().min(1),
count: z.number().int().min(1),
}),
),
observed_ipc: z.number().int().min(0),
dropped_ipc: z.number().int().min(0),
observed_runtime: z.number().int().min(0),
dropped_runtime: z.number().int().min(0),
})
.nullable()
.default(null),
coverage: coverageSchema.default({
status: "partial_attach",
observed_event_families: [],
unavailable_event_families: [],
observed_roles: [],
pre_capture_activity: "unavailable",
timeline: z.strictObject({
events: z.array(electronActiveTimelineEventSchema),
observed: z.number().int().min(0),
dropped: z.number().int().min(0),
}),
retention: z.strictObject({
budget_bytes: z.number().int().min(0),
estimated_retained_bytes: z.number().int().min(0),
event_serialized_byte_upper_bound: z.number().int().min(0),
retained: z.number().int().min(0),
dropped: z.number().int().min(0),
dropped_event_families: z.array(
z.strictObject({
family: z.string().min(1),
count: z.number().int().min(1),
}),
),
dropped_event_roles: z.array(
z.strictObject({
role: z.string().min(1),
count: z.number().int().min(1),
}),
),
observed_ipc: z.number().int().min(0),
dropped_ipc: z.number().int().min(0),
observed_runtime: z.number().int().min(0),
dropped_runtime: z.number().int().min(0),
}),
coverage: coverageSchema,
limitations: z.array(z.string()),
});
export type ElectronActiveObservationResult = z.infer<
+16 -3
View File
@@ -100,9 +100,22 @@ export const electronPageInspectionSchema = z.object({
script_key: prefixedDigestSchema("electron_script"),
frame_id: z.string().nullable().default(null),
file_path: z.string(),
cdp_hash: z.string(),
length: z.number().int().min(0),
is_module: z.boolean(),
cdp_hash: z
.string()
.nullable()
.describe("Producer-reported script hash; null when unavailable."),
length: z
.number()
.int()
.min(0)
.nullable()
.describe("Producer-reported script length; null when unavailable."),
is_module: z
.boolean()
.nullable()
.describe(
"Producer-reported module classification; null when unavailable.",
),
language: z.string().nullable(),
source: electronSourceSchema,
}),
@@ -421,6 +421,8 @@ export const applicationNodeIdentitySchema = z.discriminatedUnion("strategy", [
source_map_sha256: digestSchema,
// The exact `sources` entry; `""` is a legal relative reference.
original_source: z.string(),
// Exact leaf-local root; null means omitted or explicitly null.
source_root: z.string().nullable(),
source_sha256: digestSchema.nullable(),
}),
z.strictObject({
@@ -9,10 +9,6 @@ import {
serializeJavaScriptApplicationGraph,
type JavaScriptApplicationGraph,
} from "./javascriptApplicationGraph.js";
import {
JAVASCRIPT_APPLICATION_NODE_KINDS,
JAVASCRIPT_APPLICATION_RELATIONS,
} from "./javascriptApplicationGraphSchemas.js";
import {
APPLICATION_GRAPH_DIGESTS,
artifactEvidence,
@@ -27,6 +23,7 @@ import {
unknownEvidence,
} from "./javascriptApplicationGraph.fixture.js";
import { resolveJavaScriptSourceMapReference } from "./javascriptSourceMapPaths.js";
const createLargeNativeExportGraph = (): JavaScriptApplicationGraph => {
const properties = Object.fromEntries(
Array.from({ length: 1_001 }, (_, index) => [
@@ -123,59 +120,6 @@ it("accepts deeply nested canonical application properties", () => {
});
describe("JavaScript Application Graph: vocabulary", () => {
it("defines the complete provider-neutral node and relation vocabulary", () => {
expect(JAVASCRIPT_APPLICATION_NODE_KINDS).toEqual([
"package",
"installer",
"artifact",
"asar-entry",
"electron-main",
"electron-preload",
"electron-renderer",
"electron-utility",
"javascript-asset",
"javascript-chunk",
"javascript-module",
"source-map",
"source-module",
"browser-window",
"frame",
"target",
"context-bridge-api",
"ipc-channel",
"ipc-handler",
"worker",
"service-worker",
"endpoint",
"storage",
"native-addon",
"native-export",
"managed-assembly",
"managed-module",
"managed-type",
"managed-method",
"managed-field",
"managed-pinvoke-import",
"managed-native-implementation",
"runtime-script-instance",
"unknown",
]);
expect(JAVASCRIPT_APPLICATION_RELATIONS).toEqual([
"contains",
"loads",
"imports",
"maps_to",
"exposes",
"sends",
"invokes",
"handles",
"calls",
"persists_to",
"observed_as",
"changed_from",
]);
});
it("round-trips one canonical, byte-stable graph", () => {
const graph = buildSyntheticJavaScriptApplicationGraph();
const serialized = serializeJavaScriptApplicationGraph(graph);
@@ -485,6 +429,7 @@ describe("JavaScript Application Graph: source maps and observations", () => {
kind: "source-module",
identity: {
strategy: "source-map-original",
source_root: null,
stability: "source-map-exact",
source_map_sha256: APPLICATION_GRAPH_DIGESTS.asar,
original_source: "webpack:///src/editor.ts",
@@ -493,6 +438,11 @@ describe("JavaScript Application Graph: source maps and observations", () => {
observations: [
{
label: "src/editor.ts",
source_map_reference: resolveJavaScriptSourceMapReference(
"webpack:///src/editor.ts",
null,
"dist/app.js.map",
),
properties: { recovered_from: "source-map" },
evidence: artifactEvidence(
APPLICATION_GRAPH_DIGESTS.asar,
@@ -524,6 +474,44 @@ describe("JavaScript Application Graph: source maps and observations", () => {
expect(graphForNode(sourceModule).nodes).toEqual([sourceModule]);
expect(graphForNode(observationScoped).nodes).toEqual([observationScoped]);
const sourceObservation = firstOf(
sourceModule.observations,
"source observation",
);
const {
source_map_reference,
observation_id,
identifier_strategy,
...withoutReference
} = sourceObservation;
void observation_id;
void identifier_strategy;
expect(() =>
graphForNode(
createJavaScriptApplicationNode({
kind: sourceModule.kind,
identity: sourceModule.identity,
observations: [withoutReference],
}),
),
).toThrow(/Source-map observation/u);
expect(() =>
graphForNode(
createJavaScriptApplicationNode({
kind: sourceModule.kind,
identity: sourceModule.identity,
observations: [
{
...withoutReference,
source_map_reference: {
...source_map_reference,
map_path: "different/map.js.map",
},
},
],
}),
),
).toThrow(/Source-map observation/u);
});
it("rejects unknown fields and stale commitments", () => {
@@ -149,6 +149,27 @@ const checkEvidenceNormalization = (
});
};
const sourceMapObservationMatchesIdentity = (
identity: Extract<
ApplicationNodeIdentity,
{ readonly strategy: "source-map-original" }
>,
observation: ApplicationNode["observations"][number],
): boolean => {
const { evidence, source_map_reference: reference } = observation;
return (
reference !== null &&
evidence.state === "observed" &&
evidence.artifact.available &&
evidence.artifact.sha256 === identity.source_map_sha256 &&
reference.source_name === identity.original_source &&
reference.source_root === identity.source_root &&
evidence.location.available &&
evidence.location.value.kind === "artifact-path" &&
reference.map_path === evidence.location.value.path
);
};
const observationMatchesIdentity = (
node: ApplicationNode,
observation: ApplicationNode["observations"][number],
@@ -162,11 +183,7 @@ const observationMatchesIdentity = (
evidence.artifact.sha256 === identity.sha256
);
if (identity.strategy === "source-map-original")
return (
evidence.state === "observed" &&
evidence.artifact.available &&
evidence.artifact.sha256 === identity.source_map_sha256
);
return sourceMapObservationMatchesIdentity(identity, observation);
if (identity.strategy === "canonical-path")
return (
evidence.artifact.available &&
@@ -247,6 +264,22 @@ const checkNode = (
"observation_id",
],
});
if (
node.identity.strategy === "source-map-original" &&
!observationMatchesIdentity(node, observation)
)
context.addIssue({
code: "custom",
message:
"Source-map observation must retain its exact declaration and map location",
path: [
"nodes",
index,
"observations",
observationIndex,
"source_map_reference",
],
});
checkEvidenceNormalization(
observation.evidence,
["nodes", index, "observations", observationIndex, "evidence"],
@@ -1,5 +1,6 @@
import { z } from "zod";
import { javascriptSourceMapReferenceSchema } from "./javascriptSourceMapPaths.js";
import {
applicationCoverageSchema,
applicationGraphEvidenceSchema,
@@ -76,15 +77,23 @@ const applicationPropertiesSchema = z.record(
);
/** One node observation before its semantic identifier is derived. */
const applicationNodeObservationInputSchema = z.strictObject({
const applicationNodeObservationBaseSchema = z.strictObject({
label: z.string().min(1).nullable(),
source_map_reference: javascriptSourceMapReferenceSchema.nullable(),
properties: applicationPropertiesSchema,
evidence: applicationGraphEvidenceSchema,
});
const applicationNodeObservationInputSchema =
applicationNodeObservationBaseSchema.extend({
source_map_reference: javascriptSourceMapReferenceSchema
.nullable()
.default(null),
});
/** One immutable, evidence-bearing observation attached to an entity. */
export const applicationNodeObservationSchema =
applicationNodeObservationInputSchema.extend({
applicationNodeObservationBaseSchema.extend({
observation_id: prefixedDigestSchema("jag_observation"),
identifier_strategy: z.strictObject({
strategy: z.literal("semantic-content-sha256"),
@@ -331,7 +331,11 @@ const locations = (node: ApplicationNode) =>
const properties = (node: ApplicationNode) =>
node.observations
.map(({ label, properties: values }) => ({ label, properties: values }))
.map(({ label, properties: values, source_map_reference }) => ({
label,
properties: values,
source_map_reference,
}))
.sort((left, right) =>
compareCodePoints(canonicalJson(left), canonicalJson(right)),
);
@@ -1,3 +1,4 @@
import { canonicalJson } from "../comparisonSemantics.js";
import { compareCodePoints } from "../canonicalOrdering.js";
import type { ApplicationNode } from "./javascriptApplicationGraph.js";
import type { JsonValue } from "../jsonValue.js";
@@ -195,7 +196,7 @@ const moduleSourceDigestKey = (node: ApplicationNode): string | null => {
const sourceMapKey = (node: ApplicationNode): string | null =>
node.kind === "source-module" &&
node.identity.strategy === "source-map-original"
? `source-map\0${node.identity.original_source}`
? `source-map\0${canonicalJson([node.identity.source_root, node.identity.original_source])}`
: null;
const structuralFingerprintKey = (node: ApplicationNode): string | null => {
@@ -107,6 +107,16 @@ const candidateFields = (
value: observation.label,
},
]),
...(observation.source_map_reference !== null &&
observation.source_map_reference.resolution.kind !== "unresolved"
? [
{
basis: "property" as const,
field: `observations[${String(index)}].source_map_reference.resolution.path`,
value: observation.source_map_reference.resolution.path,
},
]
: []),
...propertyFields(
observation.properties,
`observations[${String(index)}].properties`,
@@ -140,6 +150,7 @@ const relevantFields = {
".path",
".source",
".original_source",
".source_root",
".exports",
],
"native-export": [".label", ".key", ".requested_members", ".members"],
@@ -156,6 +167,15 @@ const identityFields = (node: ApplicationNode): CandidateField[] => {
field: "identity.original_source",
value: identity.original_source,
},
...(identity.source_root === null
? []
: [
{
basis: "identity" as const,
field: "identity.source_root",
value: identity.source_root,
},
]),
];
if (identity.strategy === "canonical-path")
return [
@@ -107,8 +107,18 @@ const javascriptRuntimeScriptSchema = z.strictObject({
location: javascriptRuntimeLocationSchema,
execution_context_key: z.string().nullable(),
cdp_hash: z.string().nullable(),
length: z.number().int().min(0),
is_module: z.boolean(),
length: z
.number()
.int()
.min(0)
.nullable()
.describe("Producer-reported script length; null when unavailable."),
is_module: z
.boolean()
.nullable()
.describe(
"Producer-reported module classification; null when unavailable.",
),
status: z.literal("observed-loaded"),
});
@@ -81,9 +81,9 @@ interface NormalizedV8Inspection {
readonly items: readonly (Readonly<{
script_key: string;
frame_id: string | null;
cdp_hash: string;
length: number;
is_module: boolean;
cdp_hash: string | null;
length: number | null;
is_module: boolean | null;
language: null;
source: { readonly included: false; readonly reason: string };
}> &
@@ -319,7 +319,7 @@ const normalizeV8Inspection = (
script_key: script.script_key,
frame_id: script.execution_context_key,
...runtimeLocation(script.location),
cdp_hash: script.cdp_hash ?? "",
cdp_hash: script.cdp_hash,
length: script.length,
is_module: script.is_module,
language: null,
@@ -1,47 +1,104 @@
import { posix } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
interface SourceMapPath {
readonly value: string;
readonly scope: "artifact-relative" | "suffix";
}
import { z } from "zod";
/** Map-scoped source declaration and its path interpretation for matching. */
export const javascriptSourceMapReferenceSchema = z.strictObject({
source_name: z.string(),
source_root: z.string().nullable(),
map_path: z.string().min(1),
resolution: z.discriminatedUnion("kind", [
z.strictObject({
kind: z.enum(["artifact-relative", "suffix"]),
path: z.string().min(1),
}),
z.strictObject({
kind: z.literal("unresolved"),
reason: z.string().min(1),
}),
]),
});
/** Typed source-map context retained through graph serialization. */
export type JavaScriptSourceMapReference = z.infer<
typeof javascriptSourceMapReferenceSchema
>;
/** Interpret a declaration once at the source-map ingestion boundary. */
export const resolveJavaScriptSourceMapReference = (
sourceName: string,
sourceRoot: string | null,
mapPath: string,
): JavaScriptSourceMapReference => {
// TraceMap's producer prefixes sourceRoot before resolving the URL reference.
const reference = `${sourceRoot ? `${sourceRoot}/` : ""}${sourceName}`;
return {
source_name: sourceName,
source_root: sourceRoot,
map_path: mapPath,
resolution: resolveJavaScriptSourceMapPath(reference, mapPath),
};
};
/** Resolve a source-map URL reference without changing its recorded identity. */
export const resolveJavaScriptSourceMapPath = (
const resolveJavaScriptSourceMapPath = (
source: string,
mapPath?: string,
): SourceMapPath | null => {
mapPath: string,
): JavaScriptSourceMapReference["resolution"] => {
const portable = source.replaceAll("\\", "/");
const windowsPath = /^[a-z]:\//iu.test(portable) || source.startsWith("\\\\");
// Preserve parent traversal rather than letting URL resolution clamp at '/'.
const anchor = `/${"source/".repeat(portable.split("/").length + 1)}`;
const directory = posix.join(
anchor,
posix.dirname(mapPath?.replaceAll("\\", "/") ?? "."),
posix.dirname(mapPath.replaceAll("\\", "/")),
);
const base = pathToFileURL(`${directory}/`, { windows: false });
const absolute = windowsPath ? windowsFileUrl(source) : URL.parse(source);
const resolved = windowsPath ? absolute : URL.parse(source, base);
if (
resolved === null ||
!resolved.pathname.startsWith("/") ||
resolved.pathname.endsWith("/")
)
return null;
if (resolved === null)
return {
kind: "unresolved",
reason: "Source reference is not a valid URL or filesystem path.",
};
if (!resolved.pathname.startsWith("/"))
return {
kind: "unresolved",
reason:
"Source reference uses a non-hierarchical URL without a file pathname.",
};
if (resolved.pathname.endsWith("/"))
return {
kind: "unresolved",
reason: "Source reference names a directory rather than a file.",
};
// Encoded separators must not manufacture a different filesystem hierarchy.
if (/%(?:2f|5c)/iu.test(resolved.pathname))
return {
kind: "unresolved",
reason: "Source reference contains an encoded path separator.",
};
const relative =
absolute === null
? !portable.startsWith("/")
: absolute.href !== resolved.href;
const path = decodedUrlPath(resolved);
if (path === null) return null;
if (path === null)
return {
kind: "unresolved",
reason:
"Source reference has malformed URL encoding or an invalid file URL.",
};
const value = relative
? posix.relative(anchor, path)
: path.replace(/^\/+/, "");
if (value === "" || value === ".." || value.startsWith("../")) return null;
return {
value,
scope: relative && mapPath !== undefined ? "artifact-relative" : "suffix",
};
if (value === "" || value === ".." || value.startsWith("../"))
return {
kind: "unresolved",
reason: "Source reference resolves outside the inventoried artifact.",
};
return { path: value, kind: relative ? "artifact-relative" : "suffix" };
};
const windowsFileUrl = (path: string): URL | null => {
@@ -54,8 +111,6 @@ const windowsFileUrl = (path: string): URL | null => {
};
const decodedUrlPath = (url: URL): string | null => {
// Encoded separators must not manufacture a different filesystem hierarchy.
if (/%(?:2f|5c)/iu.test(url.pathname)) return null;
try {
if (url.protocol === "file:")
return fileURLToPath(url, {
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { resolveJavaScriptSourceMapReference } from "./javascriptSourceMapPaths.js";
import {
createJavaScriptApplicationGraph,
createJavaScriptApplicationNode,
@@ -143,6 +144,7 @@ describe("source to bundle digest changes", () => {
kind: "source-module",
identity: {
strategy: "source-map-original",
source_root: null,
stability: "source-map-exact",
source_map_sha256: HASH.artifact,
original_source: "webpack://fixture/./src/modified.ts",
@@ -150,8 +152,16 @@ describe("source to bundle digest changes", () => {
},
observations: [
{
label: "src/modified.ts",
properties: { source_sha256: HASH.unchanged },
label: "display label",
source_map_reference: resolveJavaScriptSourceMapReference(
"webpack://fixture/./src/modified.ts",
null,
"dist/main.js.map",
),
properties: {
source_sha256: HASH.unchanged,
source: "src/removed.ts",
},
evidence: artifactEvidence(HASH.artifact, "dist/main.js.map"),
},
],
@@ -170,7 +180,10 @@ describe("source to bundle digest changes", () => {
limitations: [],
});
const result = compareSourceToBundle({
reference: historicalGraph("complete", ["src/modified.ts"]),
reference: historicalGraph("complete", [
"src/modified.ts",
"src/removed.ts",
]),
application: {
evidenceId: EVIDENCE_ID,
rootArtifactSha256: HASH.artifact,
@@ -179,6 +192,7 @@ describe("source to bundle digest changes", () => {
});
expect(result.summary).toMatchObject({ modified: 1, unknown: 0 });
expect(item(result, "src/removed.ts").candidates).toEqual([]);
expect(item(result, "src/modified.ts")).toMatchObject({
status: "modified",
confidence: "high",
+16 -49
View File
@@ -9,7 +9,6 @@ import {
type SourceToBundleSignal,
} from "./sourceToBundleComparisonSchemas.js";
import { isDigest } from "../digests.js";
import { resolveJavaScriptSourceMapPath } from "./javascriptSourceMapPaths.js";
type SourceFile = Extract<
HistoricalSourceGraph["entries"][number],
@@ -174,40 +173,24 @@ const projectCurrentNode = (node: ApplicationNode): CurrentProjection => {
if (node.identity.strategy === "source-map-original") {
if (node.identity.source_sha256 !== null)
digests.add(node.identity.source_sha256);
const mapLocations = node.observations.flatMap(({ evidence }) =>
evidence.extractor.operation === "parse-local-source-map" &&
evidence.location.available &&
evidence.location.value.kind === "artifact-path"
? [evidence.location.value.path]
: [],
);
if (mapLocations.length === 0)
addPath(paths, "source-map-original", node.identity.original_source);
for (const mapPath of mapLocations)
addPath(
paths,
"source-map-original",
node.identity.original_source,
mapPath,
);
}
if (node.identity.strategy === "canonical-path")
addPath(paths, "canonical-path", node.identity.path);
for (const observation of node.observations) {
const sourceDigest = observation.properties.source_sha256;
if (typeof sourceDigest === "string" && isDigest(sourceDigest))
digests.add(sourceDigest);
for (const key of PATH_PROPERTIES) {
const location = observation.evidence.location;
const mapPath =
node.identity.strategy === "source-map-original" &&
observation.evidence.extractor.operation === "parse-local-source-map" &&
(key === "source" || key === "original_source") &&
location.available &&
location.value.kind === "artifact-path"
? location.value.path
: undefined;
addJsonPath(paths, observation.properties[key], mapPath);
if (node.identity.strategy === "source-map-original") {
const resolution = observation.source_map_reference?.resolution;
if (resolution !== undefined && resolution.kind !== "unresolved")
paths.push({
kind: "source-map-original",
value: resolution.path,
allowSuffix: resolution.kind === "suffix",
});
} else {
const sourceDigest = observation.properties.source_sha256;
if (typeof sourceDigest === "string" && isDigest(sourceDigest))
digests.add(sourceDigest);
for (const key of PATH_PROPERTIES)
addJsonPath(paths, observation.properties[key]);
}
}
return {
@@ -298,31 +281,15 @@ const matchingPaths = (
)
.map(({ value }) => value);
const addJsonPath = (
paths: CurrentPath[],
value: unknown,
mapPath?: string,
): void => {
if (typeof value === "string")
addPath(paths, "observation-path", value, mapPath);
const addJsonPath = (paths: CurrentPath[], value: unknown): void => {
if (typeof value === "string") addPath(paths, "observation-path", value);
};
const addPath = (
paths: CurrentPath[],
kind: CurrentPathKind,
raw: string,
mapPath?: string,
): void => {
if (kind === "source-map-original" || mapPath !== undefined) {
const resolved = resolveJavaScriptSourceMapPath(raw, mapPath);
if (resolved !== null)
paths.push({
kind,
value: resolved.value,
allowSuffix: resolved.scope === "suffix",
});
return;
}
const value = normalizeCurrentPath(raw);
if (value !== null) paths.push({ kind, value, allowSuffix: true });
};