refactor: use canonical implementations and types directly
Remove forwarding wrappers and shadow aliases, migrate callers and verification scripts to their owners, and share one exhaustive semantic resource-bound projection.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { z } from "zod";
|
||||
import { isAbsolute } from "node:path";
|
||||
|
||||
import { isAbsoluteLocalPath, localPathStringSchema } from "../localPath.js";
|
||||
import { localPathStringSchema } from "../localPath.js";
|
||||
|
||||
const pathInputSchema = localPathStringSchema.refine(isAbsoluteLocalPath, {
|
||||
const pathInputSchema = localPathStringSchema.refine(isAbsolute, {
|
||||
message:
|
||||
"Electron executable, application, and root paths must be absolute local filesystem paths (for example /Applications/Electron.app/Contents/MacOS/Electron)",
|
||||
});
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
electronStaticValue,
|
||||
objectProperty,
|
||||
} from "./electronStaticAnalysisValues.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { addLocatedFinding } from "./javascriptStaticAnalysisFindings.js";
|
||||
import {
|
||||
argumentNode,
|
||||
@@ -150,7 +150,9 @@ const collectWebPreferences = (
|
||||
if (value.status === "dynamic") unknown += 1;
|
||||
preferences.push({ name, value });
|
||||
}
|
||||
preferences.sort((left, right) => compareCodePoints(left.name, right.name));
|
||||
preferences.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.name, right.name),
|
||||
);
|
||||
return {
|
||||
status: "object-literal",
|
||||
preferences,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { stripQueryAndFragment } from "../artifactPathSyntax.js";
|
||||
import type { ElectronNativeAddonBindingFinding } from "./electronStaticAnalysisTypes.js";
|
||||
import { addLocatedFinding } from "./javascriptStaticAnalysisFindings.js";
|
||||
@@ -137,7 +137,7 @@ const addBinding = (input: NativeBindingInput): void => {
|
||||
const { context, node, specifier, kind } = input;
|
||||
const unique = [
|
||||
...new Set(input.members.filter((member) => member !== "")),
|
||||
].sort(compareCodePoints);
|
||||
].sort(compareUnicodeCodePoints);
|
||||
const members = unique.length === 0 ? ["*"] : unique;
|
||||
addLocatedFinding(context, {
|
||||
collection: context.accumulator.nativeAddonBindings,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { ElectronStaticValue } from "./electronStaticAnalysisTypes.js";
|
||||
import {
|
||||
readExactJavaScriptLiteral,
|
||||
@@ -105,7 +105,7 @@ export const collectContextBridgeMembers = (
|
||||
unknown: 0,
|
||||
};
|
||||
collectMembersAt(node, "", 0, state);
|
||||
const members = [...new Set(state.members)].sort(compareCodePoints);
|
||||
const members = [...new Set(state.members)].sort(compareUnicodeCodePoints);
|
||||
return {
|
||||
status: "object-literal",
|
||||
members,
|
||||
|
||||
@@ -9,7 +9,8 @@ import type {
|
||||
ApplicationNode,
|
||||
} from "./javascriptApplicationGraphSchemas.js";
|
||||
import type { ApplicationGraphEvidence } from "./javascriptApplicationEvidenceSchemas.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { ApplicationVersionComparisonItem } from "./javascriptApplicationVersionComparisonSchemas.js";
|
||||
|
||||
interface ChangeGraphInput {
|
||||
@@ -218,7 +219,7 @@ const sourceCoverageLimits = (input: ChangeGraphInput) =>
|
||||
(limit) => [`${limit.name}\0${limit.value}\0${limit.unit}`, limit],
|
||||
),
|
||||
).values(),
|
||||
].sort((left, right) => compareCodePoints(left.name, right.name));
|
||||
].sort((left, right) => compareUnicodeCodePoints(left.name, right.name));
|
||||
|
||||
const combineOmittedCounts = (left: number | null, right: number | null) =>
|
||||
left === null || right === null ? null : left + right;
|
||||
@@ -238,7 +239,7 @@ const mergeNodes = (nodes: readonly ApplicationNode[]): ApplicationNode[] => {
|
||||
.map((observation) => [observation.observation_id, observation]),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
compareCodePoints(left.observation_id, right.observation_id),
|
||||
compareUnicodeCodePoints(left.observation_id, right.observation_id),
|
||||
);
|
||||
return createJavaScriptApplicationNode({
|
||||
kind: first.kind,
|
||||
@@ -250,11 +251,11 @@ const mergeNodes = (nodes: readonly ApplicationNode[]): ApplicationNode[] => {
|
||||
});
|
||||
});
|
||||
return merged.sort((left, right) =>
|
||||
compareCodePoints(left.node_id, right.node_id),
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
);
|
||||
};
|
||||
|
||||
const uniqueEdges = (edges: readonly ApplicationEdge[]): ApplicationEdge[] =>
|
||||
[...new Map(edges.map((edge) => [edge.edge_id, edge])).values()].sort(
|
||||
(left, right) => compareCodePoints(left.edge_id, right.edge_id),
|
||||
(left, right) => compareUnicodeCodePoints(left.edge_id, right.edge_id),
|
||||
);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { z } from "zod";
|
||||
import { canonicalDigest, canonicalJson } from "../comparisonSemantics.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { canonicalJson } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { freezeOwnedJsonSnapshotSteps } from "../immutableJson.js";
|
||||
|
||||
import type {
|
||||
@@ -37,7 +39,7 @@ const normalizeLimits = (
|
||||
limits: ApplicationGraphEvidence["coverage"]["limits"],
|
||||
): ApplicationGraphEvidence["coverage"]["limits"] =>
|
||||
[...new Map(limits.map((limit) => [limitKey(limit), limit])).values()].sort(
|
||||
(left, right) => compareCodePoints(limitKey(left), limitKey(right)),
|
||||
(left, right) => compareUnicodeCodePoints(limitKey(left), limitKey(right)),
|
||||
);
|
||||
|
||||
const normalizeEvidence = (
|
||||
@@ -65,7 +67,7 @@ const nodeSemantic = (node: Pick<ApplicationNode, "kind" | "identity">) => ({
|
||||
});
|
||||
|
||||
const nodeId = (node: Pick<ApplicationNode, "kind" | "identity">): string =>
|
||||
`jag_node_${canonicalDigest(nodeSemantic(node), "JavaScript Application Graph")}`;
|
||||
`jag_node_${digestCanonicalValue(nodeSemantic(node), "JavaScript Application Graph")}`;
|
||||
|
||||
const observationSemantic = (
|
||||
nodeIdentifier: string,
|
||||
@@ -82,14 +84,14 @@ const observationId = (
|
||||
"observation_id"
|
||||
>,
|
||||
): string =>
|
||||
`jag_observation_${canonicalDigest(
|
||||
`jag_observation_${digestCanonicalValue(
|
||||
observationSemantic(nodeIdentifier, observation),
|
||||
)}`;
|
||||
|
||||
type EdgeSemantic = Omit<ApplicationEdge, "edge_id">;
|
||||
|
||||
const edgeId = (edge: EdgeSemantic): string =>
|
||||
`jag_edge_${canonicalDigest(edge, "JavaScript Application Graph")}`;
|
||||
`jag_edge_${digestCanonicalValue(edge, "JavaScript Application Graph")}`;
|
||||
|
||||
const sortedUniqueIssue = (
|
||||
values: readonly string[],
|
||||
@@ -98,7 +100,9 @@ const sortedUniqueIssue = (
|
||||
context: z.RefinementCtx,
|
||||
): void => {
|
||||
for (let index = 1; index < values.length; index += 1) {
|
||||
if (compareCodePoints(values[index - 1] ?? "", values[index] ?? "") < 0)
|
||||
if (
|
||||
compareUnicodeCodePoints(values[index - 1] ?? "", values[index] ?? "") < 0
|
||||
)
|
||||
continue;
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -394,7 +398,7 @@ const checkGraphInvariants = (
|
||||
const { graph_id: identifier, ...semantic } = graph;
|
||||
if (
|
||||
identifier !==
|
||||
`jag_${canonicalDigest(semantic, "JavaScript Application Graph")}`
|
||||
`jag_${digestCanonicalValue(semantic, "JavaScript Application Graph")}`
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -432,7 +436,7 @@ export const createJavaScriptApplicationNode = (
|
||||
});
|
||||
})
|
||||
.sort((left, right) =>
|
||||
compareCodePoints(left.observation_id, right.observation_id),
|
||||
compareUnicodeCodePoints(left.observation_id, right.observation_id),
|
||||
);
|
||||
return applicationNodeSchema.parse({
|
||||
node_id: identifier,
|
||||
@@ -467,10 +471,10 @@ export const createJavaScriptApplicationGraph = (
|
||||
...parsed,
|
||||
root_node_ids: uniqueSorted(parsed.root_node_ids),
|
||||
nodes: [...parsed.nodes].sort((left, right) =>
|
||||
compareCodePoints(left.node_id, right.node_id),
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
),
|
||||
edges: [...parsed.edges].sort((left, right) =>
|
||||
compareCodePoints(left.edge_id, right.edge_id),
|
||||
compareUnicodeCodePoints(left.edge_id, right.edge_id),
|
||||
),
|
||||
coverage: {
|
||||
...parsed.coverage,
|
||||
@@ -480,7 +484,7 @@ export const createJavaScriptApplicationGraph = (
|
||||
};
|
||||
return javascriptApplicationGraphSchema.parse({
|
||||
...semantic,
|
||||
graph_id: `jag_${canonicalDigest(semantic, "JavaScript Application Graph")}`,
|
||||
graph_id: `jag_${digestCanonicalValue(semantic, "JavaScript Application Graph")}`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -517,7 +521,7 @@ export const parseJavaScriptApplicationGraph = (
|
||||
export const computeJavaScriptApplicationGraphSha256 = (
|
||||
input: unknown,
|
||||
): string =>
|
||||
canonicalDigest(
|
||||
digestCanonicalValue(
|
||||
parseJavaScriptApplicationGraph(input),
|
||||
"JavaScript Application Graph",
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { canonicalDigest } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import type { Evidence } from "../evidence.js";
|
||||
import { buildJavaScriptApplicationChangeGraph } from "./javascriptApplicationChangeGraph.js";
|
||||
@@ -78,7 +78,7 @@ export const compareJavaScriptApplicationVersions = (
|
||||
};
|
||||
return applicationVersionComparisonResultSchema.parse({
|
||||
...semantic,
|
||||
comparison_id: `javc_${canonicalDigest(semantic, "Application version comparison")}`,
|
||||
comparison_id: `javc_${digestCanonicalValue(semantic, "Application version comparison")}`,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ export const compareApplicationVersionsInputSchema = z
|
||||
}
|
||||
});
|
||||
|
||||
const emptyCandidateNodesSchema = emptyArraySchema;
|
||||
const candidateNodesSchema = z.tuple([nodeIdSchema]).rest(nodeIdSchema);
|
||||
const exactMatchSchema = z.strictObject({
|
||||
status: z.literal("matched"),
|
||||
@@ -49,22 +48,22 @@ const exactMatchSchema = z.strictObject({
|
||||
"exact-module-source-digest",
|
||||
]),
|
||||
confidence: z.literal("exact"),
|
||||
candidate_left_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_right_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_left_node_ids: emptyArraySchema,
|
||||
candidate_right_node_ids: emptyArraySchema,
|
||||
});
|
||||
const sourceMapMatchSchema = z.strictObject({
|
||||
status: z.literal("matched"),
|
||||
basis: z.literal("source-map-identity"),
|
||||
confidence: z.literal("high"),
|
||||
candidate_left_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_right_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_left_node_ids: emptyArraySchema,
|
||||
candidate_right_node_ids: emptyArraySchema,
|
||||
});
|
||||
const inferredMatchSchema = z.strictObject({
|
||||
status: z.literal("matched"),
|
||||
basis: z.enum(["structural-fingerprint", "semantic-key"]),
|
||||
confidence: z.literal("medium"),
|
||||
candidate_left_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_right_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_left_node_ids: emptyArraySchema,
|
||||
candidate_right_node_ids: emptyArraySchema,
|
||||
});
|
||||
const matchedItemMatchSchema = z.union([
|
||||
exactMatchSchema,
|
||||
@@ -75,14 +74,14 @@ const unmatchedItemMatchSchema = z.strictObject({
|
||||
status: z.literal("unmatched"),
|
||||
basis: z.literal("none"),
|
||||
confidence: z.literal("unknown"),
|
||||
candidate_left_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_right_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_left_node_ids: emptyArraySchema,
|
||||
candidate_right_node_ids: emptyArraySchema,
|
||||
});
|
||||
const leftAmbiguousMatchSchema = z.strictObject({
|
||||
status: z.literal("ambiguous"),
|
||||
basis: z.literal("none"),
|
||||
confidence: z.literal("unknown"),
|
||||
candidate_left_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_left_node_ids: emptyArraySchema,
|
||||
candidate_right_node_ids: candidateNodesSchema,
|
||||
});
|
||||
const rightAmbiguousMatchSchema = z.strictObject({
|
||||
@@ -90,7 +89,7 @@ const rightAmbiguousMatchSchema = z.strictObject({
|
||||
basis: z.literal("none"),
|
||||
confidence: z.literal("unknown"),
|
||||
candidate_left_node_ids: candidateNodesSchema,
|
||||
candidate_right_node_ids: emptyCandidateNodesSchema,
|
||||
candidate_right_node_ids: emptyArraySchema,
|
||||
});
|
||||
|
||||
const comparisonItemContextShape = {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import {
|
||||
absenceClaimable,
|
||||
canonicalDigest,
|
||||
canonicalJson,
|
||||
} from "../comparisonSemantics.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { absenceClaimable, canonicalJson } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { Evidence } from "../evidence.js";
|
||||
import type {
|
||||
ApplicationEdge,
|
||||
@@ -96,7 +93,9 @@ export const classifyJavaScriptApplicationVersions = (
|
||||
...matching.pairs.map((pair) => matchedItem(pair, fullContext)),
|
||||
...leftItems,
|
||||
...rightItems,
|
||||
].sort((left, right) => compareCodePoints(left.item_id, right.item_id)),
|
||||
].sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.item_id, right.item_id),
|
||||
),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -326,7 +325,7 @@ const locations = (node: ApplicationNode) =>
|
||||
evidence.location.available ? evidence.location.value : evidence.location,
|
||||
)
|
||||
.sort((left, right) =>
|
||||
compareCodePoints(canonicalJson(left), canonicalJson(right)),
|
||||
compareUnicodeCodePoints(canonicalJson(left), canonicalJson(right)),
|
||||
);
|
||||
|
||||
const properties = (node: ApplicationNode) =>
|
||||
@@ -337,7 +336,7 @@ const properties = (node: ApplicationNode) =>
|
||||
source_map_reference,
|
||||
}))
|
||||
.sort((left, right) =>
|
||||
compareCodePoints(canonicalJson(left), canonicalJson(right)),
|
||||
compareUnicodeCodePoints(canonicalJson(left), canonicalJson(right)),
|
||||
);
|
||||
|
||||
const relationshipSignature = (
|
||||
@@ -371,7 +370,7 @@ const relationshipSignature = (
|
||||
];
|
||||
return [];
|
||||
});
|
||||
return canonicalJson(signatures.sort(compareCodePoints));
|
||||
return canonicalJson(signatures.sort(compareUnicodeCodePoints));
|
||||
};
|
||||
|
||||
interface EdgeSignatureContext {
|
||||
@@ -400,7 +399,7 @@ const itemEvidenceLinks = (
|
||||
...nativeLinks(left, context.leftNativeEvidence),
|
||||
...nativeLinks(right, context.rightNativeEvidence),
|
||||
]),
|
||||
].sort(compareCodePoints);
|
||||
].sort(compareUnicodeCodePoints);
|
||||
|
||||
const nativeLinks = (
|
||||
node: ApplicationNode | undefined,
|
||||
@@ -445,7 +444,7 @@ const itemWithId = <Semantic extends ComparisonItemSemantic>(
|
||||
semantic: Semantic,
|
||||
): Semantic & { readonly item_id: string } => ({
|
||||
...semantic,
|
||||
item_id: `javc_item_${canonicalDigest(semantic, "Application version item")}`,
|
||||
item_id: `javc_item_${digestCanonicalValue(semantic, "Application version item")}`,
|
||||
});
|
||||
|
||||
const stringProperty = (node: ApplicationNode, key: string): string | null => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { canonicalJson } from "../comparisonSemantics.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { ApplicationNode } from "./javascriptApplicationGraphSchemas.js";
|
||||
import type { JsonValue } from "../jsonValue.js";
|
||||
|
||||
@@ -85,7 +85,7 @@ export const matchJavaScriptApplicationVersions = (
|
||||
const rightIds = new Set(remainingRight.map(({ node_id: id }) => id));
|
||||
return {
|
||||
pairs: pairs.sort((a, b) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
`${a.left.node_id}\0${a.right.node_id}`,
|
||||
`${b.left.node_id}\0${b.right.node_id}`,
|
||||
),
|
||||
@@ -109,7 +109,7 @@ interface TierContext {
|
||||
const applyTier = (context: TierContext): void => {
|
||||
const leftByKey = nodesByKey(context.left.values(), context.tier.key);
|
||||
const rightByKey = nodesByKey(context.right.values(), context.tier.key);
|
||||
for (const key of [...leftByKey.keys()].sort(compareCodePoints)) {
|
||||
for (const key of [...leftByKey.keys()].sort(compareUnicodeCodePoints)) {
|
||||
const leftGroup = leftByKey.get(key) ?? [];
|
||||
const rightGroup = rightByKey.get(key) ?? [];
|
||||
if (rightGroup.length === 0) continue;
|
||||
@@ -174,7 +174,7 @@ const filteredCandidates = (
|
||||
[...candidates.entries()].flatMap(([nodeId, values]) => {
|
||||
const filtered = [...values]
|
||||
.filter((value) => retained.has(value))
|
||||
.sort(compareCodePoints);
|
||||
.sort(compareUnicodeCodePoints);
|
||||
return filtered.length === 0 ? [] : [[nodeId, filtered] as const];
|
||||
}),
|
||||
);
|
||||
@@ -309,10 +309,10 @@ const stringList = (value: unknown): string[] =>
|
||||
Array.isArray(value)
|
||||
? value
|
||||
.filter((item): item is string => typeof item === "string")
|
||||
.sort(compareCodePoints)
|
||||
.sort(compareUnicodeCodePoints)
|
||||
: [];
|
||||
|
||||
const sortedNodes = (nodes: Iterable<ApplicationNode>): ApplicationNode[] =>
|
||||
[...nodes].sort((left, right) =>
|
||||
compareCodePoints(left.node_id, right.node_id),
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
);
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as t from "@babel/types";
|
||||
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { propertyName } from "./javascriptAstValues.js";
|
||||
import { stringValue } from "./javascriptStaticAnalysisHelpers.js";
|
||||
|
||||
@@ -37,7 +37,7 @@ export const collectJavaScriptExports = (node: t.Node): StaticExports => {
|
||||
},
|
||||
});
|
||||
return {
|
||||
values: [...exports].sort(compareCodePoints),
|
||||
values: [...exports].sort(compareUnicodeCodePoints),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import {
|
||||
canonicalExportShapeValue,
|
||||
digestExportShapeValue,
|
||||
@@ -107,7 +108,7 @@ const sortChanges = (
|
||||
}))
|
||||
.sort(
|
||||
(left, right) =>
|
||||
compareCodePoints(left.sortKey, right.sortKey) ||
|
||||
compareUnicodeCodePoints(left.sortKey, right.sortKey) ||
|
||||
left.index - right.index,
|
||||
)
|
||||
.map(({ change }) => change);
|
||||
|
||||
@@ -7,7 +7,6 @@ const evidenceIdSchema = prefixedDigestSchema("ev");
|
||||
const graphIdSchema = prefixedDigestSchema("jag");
|
||||
const nodeIdSchema = prefixedDigestSchema("jag_node");
|
||||
const textSchema = z.string().min(1);
|
||||
const selectorTextSchema = textSchema;
|
||||
const semanticPrimitiveSchema = z.union([
|
||||
z.string(),
|
||||
z.number().finite(),
|
||||
@@ -59,10 +58,10 @@ export const compareJavaScriptExportShapesInputSchema = z
|
||||
.strictObject({
|
||||
left: evidenceSchema,
|
||||
right: evidenceSchema,
|
||||
left_module_path: selectorTextSchema,
|
||||
left_export_name: selectorTextSchema,
|
||||
right_module_path: selectorTextSchema,
|
||||
right_export_name: selectorTextSchema,
|
||||
left_module_path: textSchema,
|
||||
left_export_name: textSchema,
|
||||
right_module_path: textSchema,
|
||||
right_export_name: textSchema,
|
||||
})
|
||||
.superRefine((input, context) => {
|
||||
if (input.left.evidence_id === input.right.evidence_id)
|
||||
@@ -151,8 +150,8 @@ const projectedReturnShapeSchema = z
|
||||
export const projectedExportReturnShapesSchema = z
|
||||
.strictObject({
|
||||
semantic_role: z.literal("export-return-shapes"),
|
||||
module_path: selectorTextSchema,
|
||||
exported_name: selectorTextSchema,
|
||||
module_path: textSchema,
|
||||
exported_name: textSchema,
|
||||
callable_id: textSchema,
|
||||
callable_kind: z.enum(["function", "class", "method"]),
|
||||
static_return_shapes: z.array(projectedReturnShapeSchema),
|
||||
@@ -179,8 +178,8 @@ export const projectedExportReturnShapesSchema = z
|
||||
|
||||
const exportCandidateSchema = z.strictObject({
|
||||
node_id: nodeIdSchema,
|
||||
module_path: selectorTextSchema,
|
||||
export_name: selectorTextSchema,
|
||||
module_path: textSchema,
|
||||
export_name: textSchema,
|
||||
matches_requested_module: z.boolean(),
|
||||
matches_requested_export: z.boolean(),
|
||||
});
|
||||
@@ -188,8 +187,8 @@ const exportCandidateSchema = z.strictObject({
|
||||
const selectorResultShape = {
|
||||
evidence_id: evidenceIdSchema,
|
||||
graph_id: graphIdSchema,
|
||||
requested_module_path: selectorTextSchema,
|
||||
requested_export_name: selectorTextSchema,
|
||||
requested_module_path: textSchema,
|
||||
requested_export_name: textSchema,
|
||||
candidates: z.array(exportCandidateSchema),
|
||||
omitted_candidates: z.number().int().min(0),
|
||||
};
|
||||
@@ -238,7 +237,8 @@ const propertyPresenceSchema = z.enum([
|
||||
"unknown-coverage",
|
||||
]);
|
||||
|
||||
const comparisonChangeSchema = z.strictObject({
|
||||
/** One change row; presence is required even when values stay unknown. */
|
||||
export const javaScriptExportShapeComparisonChangeSchema = z.strictObject({
|
||||
change_id: prefixedDigestSchema("jesc_change"),
|
||||
status: z.enum(["added", "removed", "changed", "unknown"]),
|
||||
path: jsonPointerSchema,
|
||||
@@ -255,10 +255,6 @@ const comparisonChangeSchema = z.strictObject({
|
||||
limitations: z.array(textSchema),
|
||||
});
|
||||
|
||||
/** One change row; presence is required even when values stay unknown. */
|
||||
export const javaScriptExportShapeComparisonChangeSchema =
|
||||
comparisonChangeSchema;
|
||||
|
||||
const inventoryPropertyCoverageSchema = z.strictObject({
|
||||
path: jsonPointerSchema,
|
||||
status: z.enum(["complete", "partial"]),
|
||||
@@ -286,7 +282,7 @@ export const javaScriptExportShapeComparisonResultSchema = z.strictObject({
|
||||
changed: z.number().int().min(0),
|
||||
unknown: z.number().int().min(0),
|
||||
}),
|
||||
changes: z.array(comparisonChangeSchema),
|
||||
changes: z.array(javaScriptExportShapeComparisonChangeSchema),
|
||||
coverage: z.strictObject({
|
||||
status: z.enum(["complete-within-inputs", "partial", "truncated"]),
|
||||
left_graph_status: z.enum([
|
||||
@@ -326,7 +322,7 @@ export type JavaScriptExportShapeComparisonResult = z.output<
|
||||
typeof javaScriptExportShapeComparisonResultSchema
|
||||
>;
|
||||
export type JavaScriptExportShapeComparisonChange = z.output<
|
||||
typeof comparisonChangeSchema
|
||||
typeof javaScriptExportShapeComparisonChangeSchema
|
||||
>;
|
||||
export type JavaScriptExportShapePropertyInventory = z.output<
|
||||
typeof propertyInventorySchema
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
type JavaScriptExportShapeComparisonResult,
|
||||
type ProjectedExportReturnShapes,
|
||||
} from "./javascriptExportShapeComparisonSchemas.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
|
||||
type Shape = ProjectedExportReturnShapes["static_return_shapes"][number];
|
||||
type SelectorResult = JavaScriptExportShapeComparisonResult["left"];
|
||||
@@ -196,7 +196,7 @@ const exportCandidates = (
|
||||
}
|
||||
}
|
||||
return [...candidates.values()].sort((left, right) =>
|
||||
compareCodePoints(candidateKey(left), candidateKey(right)),
|
||||
compareUnicodeCodePoints(candidateKey(left), candidateKey(right)),
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ import type {
|
||||
JavaScriptExportShapeComparisonResult,
|
||||
JavaScriptExportShapePropertyInventory,
|
||||
} from "./javascriptExportShapeComparisonSchemas.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type {
|
||||
SelectedJavaScriptExport,
|
||||
RetainedJavaScriptExportShapes,
|
||||
@@ -252,7 +253,7 @@ const compareDiscriminants = (
|
||||
left: Discriminant,
|
||||
right: Discriminant,
|
||||
): number =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
canonicalExportShapeValue(left),
|
||||
canonicalExportShapeValue(right),
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { ApplicationNode } from "./javascriptApplicationGraphSchemas.js";
|
||||
import {
|
||||
featureSeedMatchMode,
|
||||
@@ -30,7 +30,7 @@ export const findApplicationFeatureSeeds = (
|
||||
nodes
|
||||
.flatMap((node) => seedMatch(node, seed))
|
||||
.sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
`${left.node_id}\0${left.basis}\0${left.field}`,
|
||||
`${right.node_id}\0${right.basis}\0${right.field}`,
|
||||
),
|
||||
@@ -230,7 +230,9 @@ const propertyFields = (
|
||||
continue;
|
||||
}
|
||||
if (current !== null && typeof current === "object") {
|
||||
for (const key of Object.keys(current).sort(compareCodePoints).reverse())
|
||||
for (const key of Object.keys(current)
|
||||
.sort(compareUnicodeCodePoints)
|
||||
.reverse())
|
||||
pending.push({
|
||||
current: current[key] ?? null,
|
||||
path: `${path}.${key}`,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { canonicalDigest } from "../comparisonSemantics.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { Evidence } from "../evidence.js";
|
||||
import {
|
||||
createJavaScriptApplicationGraph,
|
||||
@@ -86,7 +87,7 @@ export const traceApplicationFeature = (
|
||||
};
|
||||
return applicationFeatureTraceResultSchema.parse({
|
||||
...semantic,
|
||||
trace_id: `jatr_${canonicalDigest(semantic, "Feature trace")}`,
|
||||
trace_id: `jatr_${digestCanonicalValue(semantic, "Feature trace")}`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -126,7 +127,7 @@ const noMatchResult = (
|
||||
};
|
||||
return applicationFeatureTraceResultSchema.parse({
|
||||
...semantic,
|
||||
trace_id: `jatr_${canonicalDigest(semantic, "Feature trace")}`,
|
||||
trace_id: `jatr_${digestCanonicalValue(semantic, "Feature trace")}`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -170,7 +171,9 @@ const terminalPaths = (
|
||||
)
|
||||
.map((node) => pathTo(node, traversal.predecessors, edgeById))
|
||||
.filter((path): path is NonNullable<typeof path> => path !== null)
|
||||
.sort((left, right) => compareCodePoints(left.path_id, right.path_id));
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.path_id, right.path_id),
|
||||
);
|
||||
};
|
||||
|
||||
const pathTo = (
|
||||
@@ -207,7 +210,7 @@ const pathTo = (
|
||||
};
|
||||
return {
|
||||
...semantic,
|
||||
path_id: `jatp_${canonicalDigest(semantic, "Feature trace")}`,
|
||||
path_id: `jatp_${digestCanonicalValue(semantic, "Feature trace")}`,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
ApplicationNode,
|
||||
} from "./javascriptApplicationGraphSchemas.js";
|
||||
import type { JavaScriptApplicationGraph } from "./javascriptApplicationGraph.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
|
||||
interface AdjacencyEntry {
|
||||
readonly edge: ApplicationEdge;
|
||||
@@ -53,9 +53,11 @@ export const traverseApplicationFeature = (
|
||||
nodes: [...visited]
|
||||
.map((nodeId) => nodeById.get(nodeId))
|
||||
.filter((node): node is ApplicationNode => node !== undefined)
|
||||
.sort((left, right) => compareCodePoints(left.node_id, right.node_id)),
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
),
|
||||
edges: [...retainedEdges.values()].sort((left, right) =>
|
||||
compareCodePoints(left.edge_id, right.edge_id),
|
||||
compareUnicodeCodePoints(left.edge_id, right.edge_id),
|
||||
),
|
||||
predecessors,
|
||||
};
|
||||
@@ -80,7 +82,7 @@ const buildAdjacency = (
|
||||
}
|
||||
for (const entries of adjacency.values())
|
||||
entries.sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
`${left.edge.edge_id}\0${left.nextNodeId}`,
|
||||
`${right.edge.edge_id}\0${right.nextNodeId}`,
|
||||
),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { Evidence } from "../evidence.js";
|
||||
import {
|
||||
type ApplicationEdge,
|
||||
@@ -38,7 +38,7 @@ export const buildJavaScriptNativeHandoffs = (
|
||||
providers: uniqueProviders(linked),
|
||||
evidence_ids: linked
|
||||
.map(({ evidence_id: id }) => id)
|
||||
.sort(compareCodePoints),
|
||||
.sort(compareUnicodeCodePoints),
|
||||
recommended_tools: [
|
||||
"open_binary" as const,
|
||||
"binary_overview" as const,
|
||||
@@ -50,7 +50,7 @@ export const buildJavaScriptNativeHandoffs = (
|
||||
];
|
||||
})
|
||||
.sort((left, right) =>
|
||||
compareCodePoints(left.native_node_id, right.native_node_id),
|
||||
compareUnicodeCodePoints(left.native_node_id, right.native_node_id),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -95,7 +95,9 @@ const nativeExportNodes = (
|
||||
return [...new Set(ids)]
|
||||
.map((id) => nodeById.get(id))
|
||||
.filter((node): node is ApplicationNode => node?.kind === "native-export")
|
||||
.sort((left, right) => compareCodePoints(left.node_id, right.node_id));
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
);
|
||||
};
|
||||
|
||||
const requestedExports = (nodes: readonly ApplicationNode[]): string[] => {
|
||||
@@ -106,7 +108,7 @@ const requestedExports = (nodes: readonly ApplicationNode[]): string[] => {
|
||||
...stringArray(observation.properties.members),
|
||||
]),
|
||||
);
|
||||
return [...new Set(values)].sort(compareCodePoints);
|
||||
return [...new Set(values)].sort(compareUnicodeCodePoints);
|
||||
};
|
||||
|
||||
const stringArray = (value: unknown): string[] =>
|
||||
@@ -125,7 +127,7 @@ const uniqueProviders = (
|
||||
]),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
`${left.id}\0${left.name}\0${left.version ?? ""}`,
|
||||
`${right.id}\0${right.name}\0${right.version ?? ""}`,
|
||||
),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isAbsolute } from "node:path";
|
||||
|
||||
import { canonicalDigest } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { isPathWithinRoot } from "../localPath.js";
|
||||
import { z } from "zod";
|
||||
|
||||
@@ -44,7 +44,7 @@ export const parseActiveElectronCapture = (
|
||||
kind: "electron-active",
|
||||
evidence,
|
||||
inspection: normalizeInspection(result),
|
||||
captureSha256: canonicalDigest(result, "Runtime reconciliation"),
|
||||
captureSha256: digestCanonicalValue(result, "Runtime reconciliation"),
|
||||
scriptsCompleteWithinScope: false,
|
||||
};
|
||||
};
|
||||
@@ -83,7 +83,7 @@ const normalizeInspection = (
|
||||
readonly completeness: BrowserCompleteness;
|
||||
} => ({
|
||||
target: {
|
||||
target_id: `electron-active:${canonicalDigest(result.application.application_path, "Runtime reconciliation").slice(0, 32)}`,
|
||||
target_id: `electron-active:${digestCanonicalValue(result.application.application_path, "Runtime reconciliation").slice(0, 32)}`,
|
||||
type: "electron-application",
|
||||
title: result.application.application_path,
|
||||
attached: true,
|
||||
|
||||
@@ -11,7 +11,8 @@ import type {
|
||||
ParsedRuntimeCapture,
|
||||
ParsedStaticLayer,
|
||||
} from "./javascriptRuntimeReconciliationParsing.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { RuntimeProjection } from "./javascriptRuntimeReconciliationRuntime.js";
|
||||
|
||||
interface ReconciledGraphInput {
|
||||
@@ -93,12 +94,14 @@ const boundGraphContent = (
|
||||
const allRoots = preferredRootIds(input);
|
||||
const rootNodeIds = allRoots;
|
||||
const sortedNodes = [...nodes].sort((left, right) =>
|
||||
compareCodePoints(left.node_id, right.node_id),
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
);
|
||||
const retainedNodes = sortedNodes;
|
||||
const retainedIds = new Set(retainedNodes.map(({ node_id: id }) => id));
|
||||
const retainedEdges = [...edges]
|
||||
.sort((left, right) => compareCodePoints(left.edge_id, right.edge_id))
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.edge_id, right.edge_id),
|
||||
)
|
||||
.filter(
|
||||
({ source_node_id: source, target_node_id: target }) =>
|
||||
retainedIds.has(source) && retainedIds.has(target),
|
||||
@@ -231,7 +234,7 @@ const mergeNodes = (nodes: readonly ApplicationNode[]): ApplicationNode[] => {
|
||||
.map((observation) => [observation.observation_id, observation]),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
compareCodePoints(left.observation_id, right.observation_id),
|
||||
compareUnicodeCodePoints(left.observation_id, right.observation_id),
|
||||
);
|
||||
return createJavaScriptApplicationNode({
|
||||
kind: first.kind,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { createJavaScriptApplicationEdge } from "./javascriptApplicationGraph.js";
|
||||
import type { ApplicationEdge } from "./javascriptApplicationGraphSchemas.js";
|
||||
import type { ApplicationGraphEvidence } from "./javascriptApplicationEvidenceSchemas.js";
|
||||
import { canonicalDigest } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import type { ParsedStaticLayer } from "./javascriptRuntimeReconciliationParsing.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { JavaScriptRuntimeReconciliationItem } from "./javascriptRuntimeReconciliationSchemas.js";
|
||||
import type { RuntimeReconciliationEntity } from "./javascriptRuntimeReconciliationRuntime.js";
|
||||
import {
|
||||
@@ -29,7 +29,7 @@ export const reconcileRuntimeEntities = (input: {
|
||||
reconcileEntity(entity, index, input.layers),
|
||||
);
|
||||
const retained = evaluated.sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
left.item.reconciliation_id,
|
||||
right.item.reconciliation_id,
|
||||
),
|
||||
@@ -177,7 +177,7 @@ const candidatesWithLocation = (
|
||||
if (!located.has(key)) located.set(key, { candidate, mapping });
|
||||
}
|
||||
return [...located.values()].sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
candidateKey(left.candidate),
|
||||
candidateKey(right.candidate),
|
||||
),
|
||||
@@ -331,7 +331,7 @@ const createItem = (
|
||||
candidate_static_nodes: candidateReferences.items,
|
||||
} satisfies Omit<JavaScriptRuntimeReconciliationItem, "reconciliation_id">;
|
||||
return {
|
||||
reconciliation_id: `jrr_item_${canonicalDigest(semantic, "Runtime reconciliation")}`,
|
||||
reconciliation_id: `jrr_item_${digestCanonicalValue(semantic, "Runtime reconciliation")}`,
|
||||
...semantic,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -22,8 +22,8 @@ import {
|
||||
type JavaScriptRuntimeObservation,
|
||||
type JavaScriptRuntimeTargetLocation,
|
||||
} from "./javascriptRuntimeObservation.js";
|
||||
import { canonicalDigest } from "../comparisonSemantics.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { parseEvidence, type Evidence } from "../evidence.js";
|
||||
import {
|
||||
javascriptApplicationAnalysisResultSchema,
|
||||
@@ -140,7 +140,9 @@ export const parseStaticLayers = (
|
||||
): ParsedStaticLayer[] =>
|
||||
layers
|
||||
.map((layer) => parseStaticLayer(layer))
|
||||
.sort((left, right) => compareCodePoints(left.layerId, right.layerId));
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.layerId, right.layerId),
|
||||
);
|
||||
|
||||
/** Parse only supported passive web/Electron inspection Evidence. */
|
||||
export const parseRuntimeCaptures = (
|
||||
@@ -149,7 +151,10 @@ export const parseRuntimeCaptures = (
|
||||
observations
|
||||
.map((observation) => parseRuntimeCapture(observation))
|
||||
.sort((left, right) =>
|
||||
compareCodePoints(left.evidence.evidence_id, right.evidence.evidence_id),
|
||||
compareUnicodeCodePoints(
|
||||
left.evidence.evidence_id,
|
||||
right.evidence.evidence_id,
|
||||
),
|
||||
);
|
||||
|
||||
const parseStaticLayer = (layer: StaticLayerInput): ParsedStaticLayer => {
|
||||
@@ -176,7 +181,7 @@ const parseStaticLayer = (layer: StaticLayerInput): ParsedStaticLayer => {
|
||||
"JavaScript application Evidence subject disagrees with its result",
|
||||
);
|
||||
return {
|
||||
layerId: `jrl_${canonicalDigest(
|
||||
layerId: `jrl_${digestCanonicalValue(
|
||||
{
|
||||
role: layer.role,
|
||||
evidence_id: evidence.evidence_id,
|
||||
@@ -219,7 +224,7 @@ const parseRuntimeCapture = (input: Evidence): ParsedRuntimeCapture => {
|
||||
kind: "browser",
|
||||
evidence,
|
||||
inspection,
|
||||
captureSha256: canonicalDigest(inspection, "Runtime reconciliation"),
|
||||
captureSha256: digestCanonicalValue(inspection, "Runtime reconciliation"),
|
||||
scriptsCompleteWithinScope: scriptsComplete(inspection.completeness),
|
||||
};
|
||||
}
|
||||
@@ -247,7 +252,7 @@ const parseRuntimeCapture = (input: Evidence): ParsedRuntimeCapture => {
|
||||
kind: "electron",
|
||||
evidence,
|
||||
inspection,
|
||||
captureSha256: canonicalDigest(inspection, "Runtime reconciliation"),
|
||||
captureSha256: digestCanonicalValue(inspection, "Runtime reconciliation"),
|
||||
scriptsCompleteWithinScope: scriptsComplete(inspection.completeness),
|
||||
};
|
||||
}
|
||||
@@ -270,7 +275,7 @@ const parseRuntimeCapture = (input: Evidence): ParsedRuntimeCapture => {
|
||||
kind: "v8-inspector",
|
||||
evidence,
|
||||
inspection,
|
||||
captureSha256: canonicalDigest(result, "Runtime reconciliation"),
|
||||
captureSha256: digestCanonicalValue(result, "Runtime reconciliation"),
|
||||
scriptsCompleteWithinScope: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type JavaScriptApplicationGraph } from "./javascriptApplicationGraph.js";
|
||||
import { canonicalDigest } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import type { StaticLoadStateProjection } from "./javascriptRuntimeLoadState.js";
|
||||
import type { RuntimeMatchingProjection } from "./javascriptRuntimeReconciliationMatching.js";
|
||||
@@ -49,7 +49,7 @@ export const createJavaScriptRuntimeReconciliationResult = (
|
||||
limitations: reconciliationLimitations(completion),
|
||||
};
|
||||
return javascriptRuntimeReconciliationResultSchema.parse({
|
||||
reconciliation_id: `jrr_${canonicalDigest(semantic, "Runtime reconciliation")}`,
|
||||
reconciliation_id: `jrr_${digestCanonicalValue(semantic, "Runtime reconciliation")}`,
|
||||
...semantic,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { evidenceSchema } from "../evidence.js";
|
||||
import { javascriptRuntimeUnresolvedLocationSchema } from "./javascriptRuntimeObservation.js";
|
||||
import { javascriptApplicationGraphSchema } from "./javascriptApplicationGraph.js";
|
||||
@@ -85,7 +85,7 @@ function normalizeRuntimeMappings(
|
||||
mappings.map((mapping) => [runtimeMappingKey(mapping), mapping]),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
compareCodePoints(runtimeMappingKey(left), runtimeMappingKey(right)),
|
||||
compareUnicodeCodePoints(runtimeMappingKey(left), runtimeMappingKey(right)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@ import { posix, relative, win32 } from "node:path";
|
||||
|
||||
import type { ApplicationNode } from "./javascriptApplicationGraphSchemas.js";
|
||||
import type { JavaScriptApplicationGraph } from "./javascriptApplicationGraph.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { ParsedStaticLayer } from "./javascriptRuntimeReconciliationParsing.js";
|
||||
import type { RuntimeReconciliationEntity } from "./javascriptRuntimeReconciliationRuntime.js";
|
||||
|
||||
@@ -39,8 +40,8 @@ export const collectStaticRuntimeCandidates = (
|
||||
.flatMap((layer) => candidatesForLayer(layer))
|
||||
.sort(
|
||||
(left, right) =>
|
||||
compareCodePoints(left.layer.layerId, right.layer.layerId) ||
|
||||
compareCodePoints(left.node.node_id, right.node.node_id),
|
||||
compareUnicodeCodePoints(left.layer.layerId, right.layer.layerId) ||
|
||||
compareUnicodeCodePoints(left.node.node_id, right.node.node_id),
|
||||
);
|
||||
|
||||
/** Translate one already-authorized runtime location into artifact paths. */
|
||||
@@ -284,7 +285,7 @@ const activeArtifactPrefixes = (
|
||||
)
|
||||
)
|
||||
prefixes.add(mapping.artifact_prefix);
|
||||
return [...prefixes].sort(compareCodePoints);
|
||||
return [...prefixes].sort(compareUnicodeCodePoints);
|
||||
};
|
||||
|
||||
const pathWithinPrefix = (path: string, prefix: string): boolean =>
|
||||
@@ -315,6 +316,6 @@ const uniqueMappedPaths = (
|
||||
).values(),
|
||||
].sort(
|
||||
(left, right) =>
|
||||
compareCodePoints(left.path, right.path) ||
|
||||
compareCodePoints(left.basis, right.basis),
|
||||
compareUnicodeCodePoints(left.path, right.path) ||
|
||||
compareUnicodeCodePoints(left.basis, right.basis),
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
|
||||
import { semanticBinding } from "./javascriptSemanticIr.js";
|
||||
import {
|
||||
bindingById,
|
||||
onlyCallable,
|
||||
topLevelBinding,
|
||||
} from "./javascriptSemanticAnalysis.fixture.js";
|
||||
@@ -39,7 +39,7 @@ describe("JavaScript semantic analysis: calls 1", () => {
|
||||
.filter(({ callSiteId }) => callSiteId === call.callSiteId)
|
||||
.map(({ argumentIndex, parameterBindingId }) => ({
|
||||
argumentIndex,
|
||||
parameter: semanticBinding(ir, parameterBindingId)?.name,
|
||||
parameter: bindingById(ir, parameterBindingId)?.name,
|
||||
})),
|
||||
).toEqual([
|
||||
{ argumentIndex: 0, parameter: "value" },
|
||||
@@ -309,7 +309,7 @@ describe("JavaScript semantic rest parameter flow", () => {
|
||||
expect(
|
||||
ir.argumentFlows.map(({ argumentIndex, parameterBindingId }) => [
|
||||
argumentIndex,
|
||||
semanticBinding(ir, parameterBindingId)?.name,
|
||||
bindingById(ir, parameterBindingId)?.name,
|
||||
]),
|
||||
).toEqual(expected);
|
||||
},
|
||||
|
||||
@@ -17,6 +17,12 @@ export const bindingsNamed = (
|
||||
): JavaScriptSemanticBinding[] =>
|
||||
ir.bindings.filter(({ name: candidate }) => candidate === name);
|
||||
|
||||
export const bindingById = (
|
||||
ir: JavaScriptSemanticIr,
|
||||
bindingId: string,
|
||||
): JavaScriptSemanticBinding | undefined =>
|
||||
ir.bindings.find(({ bindingId: candidate }) => candidate === bindingId);
|
||||
|
||||
export const onlyBinding = (
|
||||
ir: JavaScriptSemanticIr,
|
||||
name: string,
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptSemantics } from "./javascriptSemanticAnalysis.js";
|
||||
import {
|
||||
semanticBinding,
|
||||
semanticReferenceAt,
|
||||
} from "./javascriptSemanticIr.js";
|
||||
import {
|
||||
programScope,
|
||||
bindingById,
|
||||
bindingsNamed,
|
||||
onlyBinding,
|
||||
topLevelBinding,
|
||||
@@ -88,12 +85,12 @@ describe("JavaScript semantic analysis: structure 1", () => {
|
||||
);
|
||||
if (shadowReference === undefined || shadowReference.bindingId === null)
|
||||
throw new Error("Missing shadow reference");
|
||||
expect(semanticBinding(ir, shadowReference.bindingId)).toEqual(shadow);
|
||||
expect(bindingById(ir, shadowReference.bindingId)).toEqual(shadow);
|
||||
expect(
|
||||
semanticReferenceAt(
|
||||
ir,
|
||||
shadowReference.location.start.line,
|
||||
shadowReference.location.start.column,
|
||||
ir.references.find(
|
||||
({ location }) =>
|
||||
location.start.line === shadowReference.location.start.line &&
|
||||
location.start.column === shadowReference.location.start.column,
|
||||
),
|
||||
).toEqual(shadowReference);
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
JavaScriptSemanticArgumentFlow,
|
||||
JavaScriptSemanticCallable,
|
||||
} from "./javascriptSemanticIr.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { semanticCallableIdForNode } from "./javascriptSemanticProjection.js";
|
||||
import {
|
||||
resolveSemanticBindingState,
|
||||
@@ -182,7 +182,9 @@ export const parameterBindings = (
|
||||
parameterAcceptsArgument(callable, location, index, state),
|
||||
),
|
||||
)
|
||||
.sort((left, right) => compareCodePoints(left.bindingId, right.bindingId));
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.bindingId, right.bindingId),
|
||||
);
|
||||
};
|
||||
|
||||
const parameterAcceptsArgument = (
|
||||
@@ -216,4 +218,4 @@ const rangeContains = (
|
||||
outer.end.column >= inner.end.column));
|
||||
|
||||
const uniqueCallableIds = (values: readonly string[]): string[] =>
|
||||
[...new Set(values)].sort(compareCodePoints);
|
||||
[...new Set(values)].sort(compareUnicodeCodePoints);
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
type JavaScriptSemanticAnalysisState,
|
||||
type JavaScriptSemanticBindingState,
|
||||
} from "./javascriptSemanticState.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
import { range } from "./javascriptStaticAnalysisHelpers.js";
|
||||
import {
|
||||
@@ -219,7 +219,7 @@ const childInteraction = (
|
||||
processBindingId: binding?.bindingId ?? null,
|
||||
linkedProcessIds: linked
|
||||
.map((candidate) => spawnId(candidate))
|
||||
.sort(compareCodePoints),
|
||||
.sort(compareUnicodeCodePoints),
|
||||
eventName: kind === "listener" ? eventName : null,
|
||||
signalName:
|
||||
kind === "signal"
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import type { JavaScriptSemanticResourceLimit } from "./javascriptSemanticValueTypes.js";
|
||||
import type { ApplicationCoverage } from "./javascriptApplicationEvidenceSchemas.js";
|
||||
import {
|
||||
SEMANTIC_EXPRESSION_DEPTH_LIMIT,
|
||||
SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT,
|
||||
SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT,
|
||||
} from "./javascriptSemanticResourceLimits.js";
|
||||
|
||||
/** Exact retention state for one callable's direct returns. */
|
||||
export type JavaScriptSemanticReturnCoverage = {
|
||||
@@ -40,6 +46,33 @@ export const semanticCoverageResourceLimits = (
|
||||
coverage: JavaScriptSemanticCoverage,
|
||||
): readonly JavaScriptSemanticResourceLimit[] => coverage.resourceLimits ?? [];
|
||||
|
||||
const semanticResourceBounds: Record<
|
||||
JavaScriptSemanticResourceLimit,
|
||||
Pick<ApplicationCoverage["limits"][number], "value" | "unit">
|
||||
> = {
|
||||
"primitive-candidates": {
|
||||
value: SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT,
|
||||
unit: "items",
|
||||
},
|
||||
"primitive-bytes": {
|
||||
value: SEMANTIC_PRIMITIVE_JSON_BYTES_LIMIT,
|
||||
unit: "bytes",
|
||||
},
|
||||
"expression-depth": {
|
||||
value: SEMANTIC_EXPRESSION_DEPTH_LIMIT,
|
||||
unit: "depth",
|
||||
},
|
||||
};
|
||||
|
||||
/** Map semantic evaluator bounds to their caller-visible application coverage. */
|
||||
export const semanticResourceLimitCoverage = (
|
||||
resourceLimits: readonly JavaScriptSemanticResourceLimit[],
|
||||
): ApplicationCoverage["limits"] =>
|
||||
resourceLimits.map((resourceLimit) => ({
|
||||
name: `javascript_semantic_${resourceLimit.replaceAll("-", "_")}`,
|
||||
...semanticResourceBounds[resourceLimit],
|
||||
}));
|
||||
|
||||
/** Classify one callable's direct-return coverage. */
|
||||
export const semanticReturnCoverage = (
|
||||
retainedCount: number,
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
JavaScriptSemanticConfigurationOperation,
|
||||
JavaScriptSemanticRequestOperation,
|
||||
} from "./javascriptSemanticIr.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import {
|
||||
semanticStaticPropertyKey,
|
||||
semanticStaticPropertyName,
|
||||
@@ -301,7 +301,7 @@ const collectResponseConsumers = (
|
||||
),
|
||||
linkedRequestIds: linked
|
||||
.map(({ operation }) => operation.requestId)
|
||||
.sort(compareCodePoints),
|
||||
.sort(compareUnicodeCodePoints),
|
||||
endpoint: null,
|
||||
fields: [],
|
||||
resolution:
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
||||
|
||||
import * as t from "@babel/types";
|
||||
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { JavaScriptSemanticCallAnalysis } from "./javascriptSemanticCalls.js";
|
||||
import type {
|
||||
JavaScriptSemanticCallable,
|
||||
@@ -100,7 +100,7 @@ export const collectJavaScriptSemanticFingerprints = (
|
||||
),
|
||||
),
|
||||
literalSetSha256: digest(
|
||||
[...new Set(syntax.literals)].sort(compareCodePoints),
|
||||
[...new Set(syntax.literals)].sort(compareUnicodeCodePoints),
|
||||
),
|
||||
effects: [
|
||||
...(isAsyncCallable(node) ? (["async"] as const) : []),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { canonicalDigest, canonicalJson } from "../comparisonSemantics.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { canonicalJson } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { canonicalJsonDigestSteps } from "../canonicalJsonDigestSteps.js";
|
||||
import { freezeOwnedJsonSnapshotSteps } from "../immutableJson.js";
|
||||
import type { ApplicationGraphEvidence } from "./javascriptApplicationEvidenceSchemas.js";
|
||||
@@ -30,7 +32,7 @@ const normalizeEvidence = (
|
||||
coverage: {
|
||||
...evidence.coverage,
|
||||
limits: [...evidence.coverage.limits].sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
canonicalJson(left, "JavaScript semantic graph"),
|
||||
canonicalJson(right, "JavaScript semantic graph"),
|
||||
),
|
||||
@@ -44,7 +46,7 @@ const normalizeEvidence = (
|
||||
export const javaScriptSemanticNodeId = (
|
||||
node: Pick<JavaScriptSemanticGraphNode, "kind" | "identity">,
|
||||
): string =>
|
||||
`jsrg_node_${canonicalDigest({ kind: node.kind, identity: node.identity }, "JavaScript semantic graph")}`;
|
||||
`jsrg_node_${digestCanonicalValue({ kind: node.kind, identity: node.identity }, "JavaScript semantic graph")}`;
|
||||
|
||||
/** Normalize one semantic entity and derive its artifact-version identifier. */
|
||||
export const createJavaScriptSemanticGraphNode = (
|
||||
@@ -81,7 +83,7 @@ export const createJavaScriptSemanticGraphRelation = (
|
||||
};
|
||||
return javaScriptSemanticRelationSchema.parse({
|
||||
...semantic,
|
||||
relation_id: `jsrg_relation_${canonicalDigest(semantic, "JavaScript semantic graph")}`,
|
||||
relation_id: `jsrg_relation_${digestCanonicalValue(semantic, "JavaScript semantic graph")}`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -96,7 +98,7 @@ export const createJavaScriptSemanticGraphUnknown = (input: unknown) => {
|
||||
};
|
||||
return javaScriptSemanticUnknownSchema.parse({
|
||||
...semantic,
|
||||
unknown_id: `jsrg_unknown_${canonicalDigest(semantic, "JavaScript semantic graph")}`,
|
||||
unknown_id: `jsrg_unknown_${digestCanonicalValue(semantic, "JavaScript semantic graph")}`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -112,14 +114,14 @@ export const createJavaScriptSemanticFingerprint = (input: unknown) => {
|
||||
limitations: uniqueSorted(parsed.limitations),
|
||||
evidence: normalizeEvidence(parsed.evidence),
|
||||
};
|
||||
const fingerprintSha256 = canonicalDigest(
|
||||
const fingerprintSha256 = digestCanonicalValue(
|
||||
semantic.components,
|
||||
"JavaScript semantic graph",
|
||||
);
|
||||
return javaScriptSemanticFingerprintSchema.parse({
|
||||
...semantic,
|
||||
fingerprint_sha256: fingerprintSha256,
|
||||
fingerprint_id: `jsrg_fingerprint_${canonicalDigest(
|
||||
fingerprint_id: `jsrg_fingerprint_${digestCanonicalValue(
|
||||
{
|
||||
function_node_id: semantic.function_node_id,
|
||||
algorithm: semantic.algorithm,
|
||||
@@ -149,7 +151,9 @@ const sortedUniqueIssue = (
|
||||
context: GraphIssueReporter,
|
||||
): void => {
|
||||
for (let index = 1; index < values.length; index += 1) {
|
||||
if (compareCodePoints(values[index - 1] ?? "", values[index] ?? "") < 0)
|
||||
if (
|
||||
compareUnicodeCodePoints(values[index - 1] ?? "", values[index] ?? "") < 0
|
||||
)
|
||||
continue;
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -326,7 +330,8 @@ function* checkRelationsSteps(
|
||||
const { relation_id: identifier, ...semantic } = relation;
|
||||
if (
|
||||
identifier !==
|
||||
"jsrg_relation_" + canonicalDigest(semantic, "JavaScript semantic graph")
|
||||
"jsrg_relation_" +
|
||||
digestCanonicalValue(semantic, "JavaScript semantic graph")
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -370,7 +375,8 @@ function* checkUnknownsSteps(
|
||||
const { unknown_id: identifier, ...semantic } = unknown;
|
||||
if (
|
||||
identifier !==
|
||||
"jsrg_unknown_" + canonicalDigest(semantic, "JavaScript semantic graph")
|
||||
"jsrg_unknown_" +
|
||||
digestCanonicalValue(semantic, "JavaScript semantic graph")
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -439,7 +445,7 @@ function* checkFingerprintsSteps(
|
||||
});
|
||||
if (
|
||||
fingerprint.fingerprint_sha256 !==
|
||||
canonicalDigest(fingerprint.components, "JavaScript semantic graph")
|
||||
digestCanonicalValue(fingerprint.components, "JavaScript semantic graph")
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -448,7 +454,7 @@ function* checkFingerprintsSteps(
|
||||
});
|
||||
const expectedIdentifier =
|
||||
"jsrg_fingerprint_" +
|
||||
canonicalDigest(
|
||||
digestCanonicalValue(
|
||||
{
|
||||
function_node_id: fingerprint.function_node_id,
|
||||
algorithm: fingerprint.algorithm,
|
||||
@@ -514,7 +520,7 @@ const checkGraph = (graph: GraphRecord, context: GraphIssueReporter): void => {
|
||||
const { graph_id: identifier, ...semantic } = graph;
|
||||
if (
|
||||
identifier !==
|
||||
"jsrg_" + canonicalDigest(semantic, "JavaScript semantic graph")
|
||||
"jsrg_" + digestCanonicalValue(semantic, "JavaScript semantic graph")
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
@@ -538,21 +544,21 @@ const normalizeGraphInput = (
|
||||
...parsed,
|
||||
root_node_ids: uniqueSorted(parsed.root_node_ids),
|
||||
nodes: [...parsed.nodes].sort((left, right) =>
|
||||
compareCodePoints(left.node_id, right.node_id),
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
),
|
||||
relations: [...parsed.relations].sort((left, right) =>
|
||||
compareCodePoints(left.relation_id, right.relation_id),
|
||||
compareUnicodeCodePoints(left.relation_id, right.relation_id),
|
||||
),
|
||||
fingerprints: [...parsed.fingerprints].sort((left, right) =>
|
||||
compareCodePoints(left.fingerprint_id, right.fingerprint_id),
|
||||
compareUnicodeCodePoints(left.fingerprint_id, right.fingerprint_id),
|
||||
),
|
||||
unknowns: [...parsed.unknowns].sort((left, right) =>
|
||||
compareCodePoints(left.unknown_id, right.unknown_id),
|
||||
compareUnicodeCodePoints(left.unknown_id, right.unknown_id),
|
||||
),
|
||||
coverage: {
|
||||
...parsed.coverage,
|
||||
limits: [...parsed.coverage.limits].sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
canonicalJson(left, "JavaScript semantic graph"),
|
||||
canonicalJson(right, "JavaScript semantic graph"),
|
||||
),
|
||||
@@ -562,7 +568,9 @@ const normalizeGraphInput = (
|
||||
...family,
|
||||
unknown_ids: uniqueSorted(family.unknown_ids),
|
||||
}))
|
||||
.sort((left, right) => compareCodePoints(left.family, right.family)),
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.family, right.family),
|
||||
),
|
||||
},
|
||||
limitations: uniqueSorted(parsed.limitations),
|
||||
});
|
||||
@@ -579,7 +587,7 @@ export const createJavaScriptSemanticGraph = (
|
||||
// public schema still verifies arbitrary records and their commitments.
|
||||
const record: GraphRecord = {
|
||||
...semantic,
|
||||
graph_id: `jsrg_${canonicalDigest(semantic, "JavaScript semantic graph")}`,
|
||||
graph_id: `jsrg_${digestCanonicalValue(semantic, "JavaScript semantic graph")}`,
|
||||
};
|
||||
const issues: SemanticGraphIssue[] = [];
|
||||
checkGraphContent(record, {
|
||||
|
||||
@@ -435,24 +435,6 @@ export interface JavaScriptSemanticIr {
|
||||
readonly limitations: readonly string[];
|
||||
}
|
||||
|
||||
/** Find the innermost resolved reference at one source coordinate. */
|
||||
export const semanticReferenceAt = (
|
||||
ir: JavaScriptSemanticIr,
|
||||
line: number,
|
||||
column: number,
|
||||
): JavaScriptSemanticReference | undefined =>
|
||||
ir.references.find(
|
||||
({ location }) =>
|
||||
location.start.line === line && location.start.column === column,
|
||||
);
|
||||
|
||||
/** Read one binding by its deterministic semantic identifier. */
|
||||
export const semanticBinding = (
|
||||
ir: JavaScriptSemanticIr,
|
||||
bindingId: string,
|
||||
): JavaScriptSemanticBinding | undefined =>
|
||||
ir.bindings.find(({ bindingId: candidate }) => candidate === bindingId);
|
||||
|
||||
/** Fail-closed result when Babel cannot produce an inert syntax tree. */
|
||||
export const failedJavaScriptSemanticIr = (): JavaScriptSemanticIr => ({
|
||||
schema: "JavaScriptSemanticIR",
|
||||
|
||||
@@ -2,7 +2,7 @@ import type {
|
||||
JavaScriptSemanticPrimitive,
|
||||
JavaScriptSemanticValue,
|
||||
} from "./javascriptSemanticValueTypes.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { semanticPrimitiveKey } from "./javascriptSemanticProvenance.js";
|
||||
import {
|
||||
SEMANTIC_PRIMITIVE_CANDIDATE_LIMIT,
|
||||
@@ -35,7 +35,7 @@ export const semanticPrimitiveSet = (
|
||||
return semanticResourceLimitUnknown("primitive-bytes");
|
||||
const unique = [...uniqueValues]
|
||||
.map((value) => ({ key: semanticPrimitiveKey(value), value }))
|
||||
.sort((left, right) => compareCodePoints(left.key, right.key))
|
||||
.sort((left, right) => compareUnicodeCodePoints(left.key, right.key))
|
||||
.map(({ value }) => value);
|
||||
const only = unique[0];
|
||||
return unique.length === 1 && only !== undefined
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
type JavaScriptSemanticScopeState,
|
||||
} from "./javascriptSemanticState.js";
|
||||
import { semanticRequireOrigin } from "./javascriptSemanticRequireOrigin.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
import {
|
||||
evaluateSemanticBinding,
|
||||
@@ -160,7 +160,7 @@ export const immutableSemanticScopes = (
|
||||
bindingsComplete: scope.bindingsComplete,
|
||||
bindingIds: [...scope.bindings.values()]
|
||||
.map(({ bindingId }) => bindingId)
|
||||
.sort(compareCodePoints),
|
||||
.sort(compareUnicodeCodePoints),
|
||||
}));
|
||||
|
||||
/** Evaluate and freeze bindings into deterministic IR order. */
|
||||
@@ -178,7 +178,9 @@ export const immutableSemanticBindings = (
|
||||
value: evaluateSemanticBinding(binding, state),
|
||||
provenance: evaluateSemanticProvenance(binding, state),
|
||||
}))
|
||||
.sort((left, right) => compareCodePoints(left.bindingId, right.bindingId));
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.bindingId, right.bindingId),
|
||||
);
|
||||
|
||||
const callableKind = (
|
||||
node: t.Node,
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
semanticResolutionBlocked,
|
||||
type JavaScriptSemanticAnalysisState,
|
||||
} from "./javascriptSemanticState.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { traverseJavaScriptAst } from "./javascriptSemanticTraversal.js";
|
||||
import { range } from "./javascriptStaticAnalysisHelpers.js";
|
||||
import {
|
||||
@@ -87,7 +87,7 @@ export const collectJavaScriptSemanticPromises = (
|
||||
ownerCallableId: candidate.ownerCallableId,
|
||||
...ownership,
|
||||
sourcePromiseIds: [...new Set(sources.promiseIds)].sort(
|
||||
compareCodePoints,
|
||||
compareUnicodeCodePoints,
|
||||
),
|
||||
sourceResolution: sources.status,
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
JavaScriptModuleOrigin,
|
||||
} from "./javascriptSemanticIr.js";
|
||||
import type { JavaScriptSemanticPrimitive } from "./javascriptSemanticValueTypes.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
|
||||
/** Construct exact local provenance without inventing module origins. */
|
||||
export const semanticLocalProvenance = (): JavaScriptBindingProvenance => ({
|
||||
@@ -44,7 +44,7 @@ export const uniqueSemanticOrigins = (
|
||||
origins.map((origin) => [semanticOriginKey(origin), origin]),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
compareCodePoints(semanticOriginKey(left), semanticOriginKey(right)),
|
||||
compareUnicodeCodePoints(semanticOriginKey(left), semanticOriginKey(right)),
|
||||
);
|
||||
|
||||
const semanticOriginKey = (origin: JavaScriptModuleOrigin): string =>
|
||||
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
JavaScriptSemanticGraphNode,
|
||||
JavaScriptSemanticGraphRelation,
|
||||
} from "./javascriptSemanticGraphSchemas.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { JavaScriptSemanticGraphUnknown } from "./javascriptSemanticGraphSchemas.js";
|
||||
import { isJavaScriptSemanticOwnershipRelation as ownershipRelation } from "./javascriptSemanticQueryRelations.js";
|
||||
import {
|
||||
@@ -147,7 +147,7 @@ const buildAdjacency = (
|
||||
}
|
||||
for (const entries of adjacency.values())
|
||||
entries.sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
`${left.relation.relation_id}\0${left.nextNodeId}`,
|
||||
`${right.relation.relation_id}\0${right.nextNodeId}`,
|
||||
),
|
||||
|
||||
@@ -4,7 +4,8 @@ import canonicalize from "canonicalize";
|
||||
|
||||
import type { JavaScriptSemanticGraph } from "./javascriptSemanticGraph.js";
|
||||
import type { JavaScriptSemanticGraphNode } from "./javascriptSemanticGraphSchemas.js";
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { JavaScriptSemanticQueryInput } from "./javascriptSemanticQuerySchemas.js";
|
||||
|
||||
/** Canonical JSON used by semantic query commitments and ordering. */
|
||||
@@ -66,7 +67,7 @@ export const resolveJavaScriptSemanticQuerySeeds = (
|
||||
return graph.nodes
|
||||
.filter((node) => seedMatches(node, input, fingerprintFunctions))
|
||||
.map(({ node_id }) => node_id)
|
||||
.sort(compareCodePoints);
|
||||
.sort(compareUnicodeCodePoints);
|
||||
};
|
||||
|
||||
const seedMatches = (
|
||||
|
||||
@@ -15,7 +15,7 @@ import type {
|
||||
ProjectedPropertyCoverage,
|
||||
ProjectedReturnField,
|
||||
} from "./javascriptExportShapeComparisonSchemas.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { semanticCallableIdForNode } from "./javascriptSemanticProjection.js";
|
||||
import {
|
||||
resolveSemanticBindingState,
|
||||
@@ -204,9 +204,9 @@ export const flattenSemanticReturnValue = (
|
||||
const fields: ProjectedReturnField[] = [];
|
||||
const propertyCoverage: ProjectedPropertyCoverage[] = [];
|
||||
flattenValue(value, "", fields, propertyCoverage);
|
||||
fields.sort((left, right) => compareCodePoints(left.path, right.path));
|
||||
fields.sort((left, right) => compareUnicodeCodePoints(left.path, right.path));
|
||||
propertyCoverage.sort((left, right) =>
|
||||
compareCodePoints(left.path, right.path),
|
||||
compareUnicodeCodePoints(left.path, right.path),
|
||||
);
|
||||
return { fields, propertyCoverage };
|
||||
};
|
||||
|
||||
@@ -3,12 +3,9 @@ import type {
|
||||
JavaScriptSemanticValue,
|
||||
} from "./javascriptSemanticValueTypes.js";
|
||||
|
||||
/** A container's own slot, using the value lattice's canonical presence model. */
|
||||
export type JavaScriptSemanticSlot = JavaScriptSemanticProperty;
|
||||
|
||||
/** Static container inventory; partial siblings do not weaken retained slots. */
|
||||
export interface JavaScriptSemanticContainer {
|
||||
readonly slots: readonly JavaScriptSemanticSlot[];
|
||||
readonly slots: readonly JavaScriptSemanticProperty[];
|
||||
readonly coverage:
|
||||
| { readonly status: "complete"; readonly omitted: 0 }
|
||||
| { readonly status: "partial"; readonly omitted: number | null };
|
||||
@@ -48,9 +45,9 @@ export function semanticContainer(
|
||||
export const semanticSlotAtPath = (
|
||||
value: JavaScriptSemanticValue,
|
||||
path: readonly string[],
|
||||
): JavaScriptSemanticSlot => {
|
||||
): JavaScriptSemanticProperty => {
|
||||
const leafName = path.at(-1) ?? "";
|
||||
let current: JavaScriptSemanticSlot = {
|
||||
let current: JavaScriptSemanticProperty = {
|
||||
name: "",
|
||||
presence: "present",
|
||||
value,
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
type JavaScriptSemanticBindingState,
|
||||
} from "./javascriptSemanticState.js";
|
||||
import { semanticRequireOrigin } from "./javascriptSemanticRequireOrigin.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import {
|
||||
readExactJavaScriptLiteral,
|
||||
semanticStaticPropertyKey,
|
||||
@@ -300,7 +300,7 @@ const evaluateObject = (
|
||||
});
|
||||
}
|
||||
const properties = [...propertiesByName.values()].sort((left, right) =>
|
||||
compareCodePoints(left.name, right.name),
|
||||
compareUnicodeCodePoints(left.name, right.name),
|
||||
);
|
||||
return unknownProperties
|
||||
? {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
collectJavaScriptExports,
|
||||
fingerprintJavaScriptAst,
|
||||
} from "./javascriptAstFingerprint.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { addFindingOnce } from "./javascriptStaticAnalysisFindings.js";
|
||||
import {
|
||||
argumentValue,
|
||||
@@ -66,7 +66,7 @@ export const inspectBundlerRegistration = (
|
||||
unknown_async_chunk_keys:
|
||||
runtimeValue.unknownAsyncChunkKeys + recovered.unknownAsyncChunkKeys,
|
||||
modules: recovered.modules.sort((left, right) =>
|
||||
compareCodePoints(left.module_key, right.module_key),
|
||||
compareUnicodeCodePoints(left.module_key, right.module_key),
|
||||
),
|
||||
location: range(call),
|
||||
};
|
||||
@@ -107,7 +107,7 @@ export const inspectEsbuildWrapper = (
|
||||
async_chunk_keys: recovered.asyncChunkKeys,
|
||||
unknown_async_chunk_keys: recovered.unknownAsyncChunkKeys,
|
||||
modules: recovered.modules.sort((left, right) =>
|
||||
compareCodePoints(left.module_key, right.module_key),
|
||||
compareUnicodeCodePoints(left.module_key, right.module_key),
|
||||
),
|
||||
location: range(call),
|
||||
};
|
||||
@@ -225,7 +225,7 @@ const runtimeMetadata = (node: t.Node | null | undefined): RuntimeMetadata => {
|
||||
asyncChunkKeys: [],
|
||||
unknownAsyncChunkKeys: 0,
|
||||
};
|
||||
const entries = collectBundlerEntryModuleKeys(node, requireName);
|
||||
const entries = collectBundlerCallArgumentValues(node, requireName);
|
||||
const asyncChunks = collectBundlerAsyncChunkKeys(node, requireName);
|
||||
return {
|
||||
requireName,
|
||||
@@ -236,11 +236,6 @@ const runtimeMetadata = (node: t.Node | null | undefined): RuntimeMetadata => {
|
||||
};
|
||||
};
|
||||
|
||||
const collectBundlerEntryModuleKeys = (
|
||||
factory: BundlerFunction,
|
||||
requireName: string,
|
||||
): StaticValues => collectBundlerCallArgumentValues(factory, requireName);
|
||||
|
||||
const collectBundlerAsyncChunkKeys = (
|
||||
factory: BundlerFunction,
|
||||
requireName: string | null,
|
||||
@@ -277,7 +272,7 @@ const isBundlerFunction = (
|
||||
t.isObjectMethod(node);
|
||||
|
||||
const uniqueValues = (values: readonly string[], unknown = 0): StaticValues => {
|
||||
const unique = [...new Set(values)].sort(compareCodePoints);
|
||||
const unique = [...new Set(values)].sort(compareUnicodeCodePoints);
|
||||
return {
|
||||
values: unique,
|
||||
unknown,
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
readExactJavaScriptLiteral,
|
||||
semanticStaticPropertyName,
|
||||
} from "./javascriptAstValues.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
|
||||
/** Explicit result for source text that Babel cannot parse. */
|
||||
export const failedJavaScriptStaticAnalysis = (): JavaScriptStaticAnalysis => ({
|
||||
@@ -156,17 +156,13 @@ export const staticArrayValues = (
|
||||
const value = argumentValue(element);
|
||||
return value === undefined ? [] : [value];
|
||||
});
|
||||
const values = [...new Set(staticValues)].sort(compareCodePoints);
|
||||
const values = [...new Set(staticValues)].sort(compareUnicodeCodePoints);
|
||||
return {
|
||||
values,
|
||||
unknown: array.elements.length - staticValues.length,
|
||||
};
|
||||
};
|
||||
|
||||
/** Resolve a path composed only from inert literal syntax. */
|
||||
export const staticPath = (node: t.Node): string | undefined =>
|
||||
staticPathAt(node);
|
||||
|
||||
/** Classify whether inert path syntax is a module specifier or file expression. */
|
||||
export const staticPathResolutionContext = (
|
||||
node: t.Node,
|
||||
@@ -175,13 +171,14 @@ export const staticPathResolutionContext = (
|
||||
? "filesystem-expression"
|
||||
: "module-specifier";
|
||||
|
||||
const staticPathAt = (node: t.Node): string | undefined => {
|
||||
/** Resolve a path composed only from inert literal syntax. */
|
||||
export const staticPath = (node: t.Node): string | undefined => {
|
||||
if (t.isStringLiteral(node)) return node.value;
|
||||
if (t.isTemplateLiteral(node) && node.expressions.length === 0)
|
||||
return stringValue(node);
|
||||
if (t.isBinaryExpression(node, { operator: "+" })) {
|
||||
const left = staticPathAt(node.left);
|
||||
const right = staticPathAt(node.right);
|
||||
const left = staticPath(node.left);
|
||||
const right = staticPath(node.right);
|
||||
return left === undefined || right === undefined
|
||||
? undefined
|
||||
: `${left}${right}`;
|
||||
@@ -215,7 +212,7 @@ const staticCallPath = (
|
||||
const parts: string[] = [];
|
||||
for (const argument of node.arguments) {
|
||||
if (isDirectoryIdentity(argumentNode(argument))) continue;
|
||||
const value = t.isNode(argument) ? staticPathAt(argument) : undefined;
|
||||
const value = t.isNode(argument) ? staticPath(argument) : undefined;
|
||||
if (value === undefined) return undefined;
|
||||
parts.push(value);
|
||||
}
|
||||
@@ -228,7 +225,7 @@ const staticFileUrlPath = (
|
||||
if (argument === undefined) return undefined;
|
||||
return isSourceFileUrl(argument)
|
||||
? sourceRelativeFileUrlPath(argument)
|
||||
: staticPathAt(argument);
|
||||
: staticPath(argument);
|
||||
};
|
||||
|
||||
/** Project a known source-relative URL through the actual file URL decoder. */
|
||||
@@ -284,7 +281,7 @@ const staticResolvedPath = (
|
||||
parts.push(null);
|
||||
continue;
|
||||
}
|
||||
const value = t.isNode(argument) ? staticPathAt(argument) : undefined;
|
||||
const value = t.isNode(argument) ? staticPath(argument) : undefined;
|
||||
// Validate every argument, including those before the last anchor.
|
||||
if (value === undefined) return undefined;
|
||||
parts.push(value);
|
||||
@@ -684,7 +681,7 @@ export const sortedUnique = <Value>(
|
||||
key: (value: Value) => string,
|
||||
): Value[] =>
|
||||
[...new Map(values.map((value) => [key(value), value])).values()].sort(
|
||||
(left, right) => compareCodePoints(key(left), key(right)),
|
||||
(left, right) => compareUnicodeCodePoints(key(left), key(right)),
|
||||
);
|
||||
|
||||
/** Hash exact UTF-8 source text. */
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
createJavaScriptApplicationNode,
|
||||
} from "./javascriptApplicationGraph.js";
|
||||
import { createHistoricalSourceGraph } from "../referenceSourceGraph.js";
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { compareSourceToBundle } from "./sourceToBundleComparison.js";
|
||||
import {
|
||||
SOURCE_TO_BUNDLE_SIGNAL_WEIGHTS,
|
||||
@@ -365,7 +365,7 @@ const historicalGraph = (
|
||||
content_state: "hashed" as const,
|
||||
limitations: [],
|
||||
})),
|
||||
].sort((left, right) => compareCodePoints(left.path, right.path)),
|
||||
].sort((left, right) => compareUnicodeCodePoints(left.path, right.path)),
|
||||
relationships: [],
|
||||
parse_failures: [],
|
||||
exclusions: [],
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { compareCodePoints, uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { absenceClaimable, canonicalDigest } from "../comparisonSemantics.js";
|
||||
import { uniqueSorted } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import { absenceClaimable } from "../comparisonSemantics.js";
|
||||
import { digestCanonicalValue } from "../canonicalDigest.js";
|
||||
|
||||
import type { JavaScriptApplicationGraph } from "./javascriptApplicationGraph.js";
|
||||
import type { HistoricalSourceGraph } from "../referenceSourceGraph.js";
|
||||
@@ -84,7 +86,7 @@ export const compareSourceToBundle = (
|
||||
};
|
||||
return sourceToBundleComparisonResultSchema.parse({
|
||||
...semanticResult,
|
||||
comparison_id: `stbc_${canonicalDigest(semanticResult, "Source-to-bundle comparison")}`,
|
||||
comparison_id: `stbc_${digestCanonicalValue(semanticResult, "Source-to-bundle comparison")}`,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -316,7 +318,7 @@ const mappingId = (
|
||||
input: SourceToBundleComparisonInput,
|
||||
item: Omit<SourceToBundleComparisonItem, "mapping_id">,
|
||||
): string =>
|
||||
`stbc_item_${canonicalDigest(
|
||||
`stbc_item_${digestCanonicalValue(
|
||||
{
|
||||
reference_root_sha256: input.reference.root_sha256,
|
||||
application_graph_id: input.application.graph.graph_id,
|
||||
@@ -382,4 +384,4 @@ const compareCandidates = (
|
||||
right: SourceToBundleCandidate,
|
||||
): number =>
|
||||
right.score - left.score ||
|
||||
compareCodePoints(left.current_node_id, right.current_node_id);
|
||||
compareUnicodeCodePoints(left.current_node_id, right.current_node_id);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { posix } from "node:path";
|
||||
|
||||
import { compareCodePoints } from "../canonicalOrdering.js";
|
||||
import { compareUnicodeCodePoints } from "../unicodeCodePointOrder.js";
|
||||
import type { ApplicationNode } from "./javascriptApplicationGraphSchemas.js";
|
||||
import type { HistoricalSourceGraph } from "../referenceSourceGraph.js";
|
||||
import {
|
||||
@@ -70,7 +70,9 @@ export const sourceBearingNodes = (
|
||||
): ApplicationNode[] =>
|
||||
nodes
|
||||
.filter(({ kind }) => RELEVANT_NODE_KINDS.has(kind))
|
||||
.sort((left, right) => compareCodePoints(left.node_id, right.node_id));
|
||||
.sort((left, right) =>
|
||||
compareUnicodeCodePoints(left.node_id, right.node_id),
|
||||
);
|
||||
|
||||
/** Keep historical source files in stable path order. */
|
||||
export const historicalSourceFiles = (
|
||||
@@ -81,7 +83,7 @@ export const historicalSourceFiles = (
|
||||
(entry): entry is SourceFile =>
|
||||
entry.kind === "file" && entry.classifications.includes("source"),
|
||||
)
|
||||
.sort((left, right) => compareCodePoints(left.path, right.path));
|
||||
.sort((left, right) => compareUnicodeCodePoints(left.path, right.path));
|
||||
|
||||
/** Build deterministic candidate indices without assigning fuzzy matches. */
|
||||
export const buildSourceToBundleCandidateIndex = (
|
||||
@@ -130,7 +132,7 @@ export const candidateIdsForSource = (
|
||||
const output: string[] = [];
|
||||
for (const group of groups) {
|
||||
if (group === undefined) continue;
|
||||
for (const nodeId of [...group].sort(compareCodePoints)) {
|
||||
for (const nodeId of [...group].sort(compareUnicodeCodePoints)) {
|
||||
if (seen.has(nodeId)) continue;
|
||||
seen.add(nodeId);
|
||||
output.push(nodeId);
|
||||
@@ -256,7 +258,7 @@ const signal = (
|
||||
kind,
|
||||
weight: signalWeight(kind),
|
||||
source_value: sourceValue,
|
||||
current_values: [...new Set(currentValues)].sort(compareCodePoints),
|
||||
current_values: [...new Set(currentValues)].sort(compareUnicodeCodePoints),
|
||||
});
|
||||
|
||||
const candidateConfidence = (
|
||||
@@ -325,7 +327,7 @@ const uniquePaths = (paths: readonly CurrentPath[]): CurrentPath[] =>
|
||||
]),
|
||||
).values(),
|
||||
].sort((left, right) =>
|
||||
compareCodePoints(
|
||||
compareUnicodeCodePoints(
|
||||
`${left.kind}\0${left.value}`,
|
||||
`${right.kind}\0${right.value}`,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user