mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 17:59:08 +00:00
test: overhaul deterministic suite architecture
This commit is contained in:
1 parent
7f2348619a
commit
513d9b1555
371 files changed
+30879
-24389
No files matched your search
+287
-288
@@ -96,305 +96,304 @@ export const runtimeEvidence = (
|
||||
evidence_ids: [],
|
||||
});
|
||||
|
||||
type FixtureNode = ReturnType<typeof createJavaScriptApplicationNode>;
|
||||
type NodeProperties = FixtureNode["observations"][number]["properties"];
|
||||
|
||||
type FixtureNodeArguments = [
|
||||
kind: FixtureNode["kind"],
|
||||
identity: FixtureNode["identity"],
|
||||
label: string,
|
||||
properties: NodeProperties,
|
||||
evidence: ApplicationGraphEvidence,
|
||||
];
|
||||
|
||||
const fixtureNode = (
|
||||
...[kind, identity, label, properties, evidence]: FixtureNodeArguments
|
||||
): FixtureNode =>
|
||||
createJavaScriptApplicationNode({
|
||||
kind,
|
||||
identity,
|
||||
observations: [{ label, properties, evidence }],
|
||||
});
|
||||
|
||||
const buildArtifactNodes = (): FixtureNode[] => [
|
||||
fixtureNode(
|
||||
"package",
|
||||
{
|
||||
strategy: "content-digest",
|
||||
stability: "global-exact",
|
||||
sha256: APPLICATION_GRAPH_DIGESTS.package,
|
||||
},
|
||||
"Synthetic desktop package",
|
||||
{ format: "directory" },
|
||||
artifactEvidence(APPLICATION_GRAPH_DIGESTS.package, "package.json"),
|
||||
),
|
||||
fixtureNode(
|
||||
"artifact",
|
||||
{
|
||||
strategy: "content-digest",
|
||||
stability: "global-exact",
|
||||
sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
},
|
||||
"resources/app.asar",
|
||||
{ format: "asar" },
|
||||
artifactEvidence(APPLICATION_GRAPH_DIGESTS.asar, "resources/app.asar"),
|
||||
),
|
||||
fixtureNode(
|
||||
"electron-preload",
|
||||
{
|
||||
strategy: "canonical-path",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
path: "dist/preload.js",
|
||||
},
|
||||
"desktop preload",
|
||||
{ sandboxed: true },
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
const buildInteractionNodes = (): FixtureNode[] => [
|
||||
fixtureNode(
|
||||
"context-bridge-api",
|
||||
{
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
namespace: "contextBridge",
|
||||
key: "desktopApi",
|
||||
},
|
||||
"desktopApi",
|
||||
{ methods: ["openProject"] },
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
fixtureNode(
|
||||
"ipc-channel",
|
||||
{
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
namespace: "electron-ipc",
|
||||
key: "project:open",
|
||||
},
|
||||
"project:open",
|
||||
{ mode: "invoke" },
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
fixtureNode(
|
||||
"ipc-handler",
|
||||
{
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
namespace: "ipcMain.handle",
|
||||
key: "project:open",
|
||||
},
|
||||
"project open handler",
|
||||
{ process: "main" },
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/main.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
const buildNativeRuntimeNodes = (): FixtureNode[] => [
|
||||
fixtureNode(
|
||||
"native-addon",
|
||||
{
|
||||
strategy: "content-digest",
|
||||
stability: "global-exact",
|
||||
sha256: APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
},
|
||||
"synthetic.node",
|
||||
{ abi: "napi" },
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
"native/synthetic.node",
|
||||
"native-analysis-provider",
|
||||
),
|
||||
),
|
||||
fixtureNode(
|
||||
"native-export",
|
||||
{
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
namespace: "napi-export",
|
||||
key: "openProject",
|
||||
},
|
||||
"openProject",
|
||||
{ calling_convention: "napi" },
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
"native/synthetic.node",
|
||||
"native-analysis-provider",
|
||||
),
|
||||
),
|
||||
fixtureNode(
|
||||
"runtime-script-instance",
|
||||
{
|
||||
strategy: "runtime-instance",
|
||||
stability: "capture-only",
|
||||
capture_sha256: APPLICATION_GRAPH_DIGESTS.capture,
|
||||
runtime_key: "script-preload",
|
||||
},
|
||||
"preload runtime script",
|
||||
{ url: "file:///synthetic/dist/preload.js" },
|
||||
runtimeEvidence("script-preload"),
|
||||
),
|
||||
];
|
||||
|
||||
const observedEdge = (
|
||||
sourceNodeId: string,
|
||||
targetNodeId: string,
|
||||
relation: "contains" | "exposes" | "handles",
|
||||
evidence: ApplicationGraphEvidence,
|
||||
) =>
|
||||
createJavaScriptApplicationEdge({
|
||||
source_node_id: sourceNodeId,
|
||||
target_node_id: targetNodeId,
|
||||
relation,
|
||||
properties: {},
|
||||
evidence,
|
||||
});
|
||||
|
||||
const inferredEdge = (
|
||||
sourceNodeId: string,
|
||||
targetNodeId: string,
|
||||
relation: "invokes" | "calls" | "loads",
|
||||
path: string,
|
||||
) =>
|
||||
createJavaScriptApplicationEdge({
|
||||
source_node_id: sourceNodeId,
|
||||
target_node_id: targetNodeId,
|
||||
relation,
|
||||
properties: {},
|
||||
evidence: inferredArtifactEvidence(APPLICATION_GRAPH_DIGESTS.asar, path),
|
||||
});
|
||||
|
||||
const buildEdges = (nodes: FixtureNode[]) => {
|
||||
const [packageNode, asarNode, preloadNode, bridgeNode, channelNode] = nodes;
|
||||
const [handlerNode, addonNode, exportNode, runtimeNode] = nodes.slice(5);
|
||||
if (
|
||||
packageNode === undefined ||
|
||||
asarNode === undefined ||
|
||||
preloadNode === undefined ||
|
||||
bridgeNode === undefined ||
|
||||
channelNode === undefined ||
|
||||
handlerNode === undefined ||
|
||||
addonNode === undefined ||
|
||||
exportNode === undefined ||
|
||||
runtimeNode === undefined
|
||||
) {
|
||||
throw new Error(
|
||||
"Synthetic application graph fixture nodes are incomplete.",
|
||||
);
|
||||
}
|
||||
return [
|
||||
observedEdge(
|
||||
packageNode.node_id,
|
||||
asarNode.node_id,
|
||||
"contains",
|
||||
artifactEvidence(APPLICATION_GRAPH_DIGESTS.package, "resources/app.asar"),
|
||||
),
|
||||
observedEdge(
|
||||
asarNode.node_id,
|
||||
preloadNode.node_id,
|
||||
"contains",
|
||||
artifactEvidence(APPLICATION_GRAPH_DIGESTS.asar, "dist/preload.js"),
|
||||
),
|
||||
observedEdge(
|
||||
preloadNode.node_id,
|
||||
bridgeNode.node_id,
|
||||
"exposes",
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
inferredEdge(
|
||||
bridgeNode.node_id,
|
||||
channelNode.node_id,
|
||||
"invokes",
|
||||
"dist/preload.js",
|
||||
),
|
||||
observedEdge(
|
||||
channelNode.node_id,
|
||||
handlerNode.node_id,
|
||||
"handles",
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/main.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
inferredEdge(
|
||||
handlerNode.node_id,
|
||||
addonNode.node_id,
|
||||
"loads",
|
||||
"dist/main.js",
|
||||
),
|
||||
inferredEdge(
|
||||
handlerNode.node_id,
|
||||
exportNode.node_id,
|
||||
"calls",
|
||||
"dist/main.js",
|
||||
),
|
||||
observedEdge(
|
||||
addonNode.node_id,
|
||||
exportNode.node_id,
|
||||
"contains",
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
"native/synthetic.node",
|
||||
"native-analysis-provider",
|
||||
),
|
||||
),
|
||||
createJavaScriptApplicationEdge({
|
||||
source_node_id: preloadNode.node_id,
|
||||
target_node_id: runtimeNode.node_id,
|
||||
relation: "observed_as",
|
||||
properties: {},
|
||||
evidence: runtimeEvidence("script-preload"),
|
||||
}),
|
||||
];
|
||||
};
|
||||
|
||||
/** Build a synthetic cross-layer Electron graph without proprietary artifacts. */
|
||||
export const buildSyntheticJavaScriptApplicationGraph =
|
||||
(): JavaScriptApplicationGraph => {
|
||||
const packageNode = createJavaScriptApplicationNode({
|
||||
kind: "package",
|
||||
identity: {
|
||||
strategy: "content-digest",
|
||||
stability: "global-exact",
|
||||
sha256: APPLICATION_GRAPH_DIGESTS.package,
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "Synthetic desktop package",
|
||||
properties: { format: "directory" },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.package,
|
||||
"package.json",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const asarNode = createJavaScriptApplicationNode({
|
||||
kind: "artifact",
|
||||
identity: {
|
||||
strategy: "content-digest",
|
||||
stability: "global-exact",
|
||||
sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "resources/app.asar",
|
||||
properties: { format: "asar" },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"resources/app.asar",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const preloadNode = createJavaScriptApplicationNode({
|
||||
kind: "electron-preload",
|
||||
identity: {
|
||||
strategy: "canonical-path",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
path: "dist/preload.js",
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "desktop preload",
|
||||
properties: { sandboxed: true },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const bridgeNode = createJavaScriptApplicationNode({
|
||||
kind: "context-bridge-api",
|
||||
identity: {
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
namespace: "contextBridge",
|
||||
key: "desktopApi",
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "desktopApi",
|
||||
properties: { methods: ["openProject"] },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const channelNode = createJavaScriptApplicationNode({
|
||||
kind: "ipc-channel",
|
||||
identity: {
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
namespace: "electron-ipc",
|
||||
key: "project:open",
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "project:open",
|
||||
properties: { mode: "invoke" },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const handlerNode = createJavaScriptApplicationNode({
|
||||
kind: "ipc-handler",
|
||||
identity: {
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.asar,
|
||||
namespace: "ipcMain.handle",
|
||||
key: "project:open",
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "project open handler",
|
||||
properties: { process: "main" },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/main.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const addonNode = createJavaScriptApplicationNode({
|
||||
kind: "native-addon",
|
||||
identity: {
|
||||
strategy: "content-digest",
|
||||
stability: "global-exact",
|
||||
sha256: APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "synthetic.node",
|
||||
properties: { abi: "napi" },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
"native/synthetic.node",
|
||||
"native-analysis-provider",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const exportNode = createJavaScriptApplicationNode({
|
||||
kind: "native-export",
|
||||
identity: {
|
||||
strategy: "artifact-local-key",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
namespace: "napi-export",
|
||||
key: "openProject",
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "openProject",
|
||||
properties: { calling_convention: "napi" },
|
||||
evidence: artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
"native/synthetic.node",
|
||||
"native-analysis-provider",
|
||||
),
|
||||
},
|
||||
],
|
||||
});
|
||||
const runtimeNode = createJavaScriptApplicationNode({
|
||||
kind: "runtime-script-instance",
|
||||
identity: {
|
||||
strategy: "runtime-instance",
|
||||
stability: "capture-only",
|
||||
capture_sha256: APPLICATION_GRAPH_DIGESTS.capture,
|
||||
runtime_key: "script-preload",
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: "preload runtime script",
|
||||
properties: { url: "file:///synthetic/dist/preload.js" },
|
||||
evidence: runtimeEvidence("script-preload"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const observedEdge = (
|
||||
sourceNodeId: string,
|
||||
targetNodeId: string,
|
||||
relation: "contains" | "exposes" | "handles",
|
||||
evidence: ApplicationGraphEvidence,
|
||||
) =>
|
||||
createJavaScriptApplicationEdge({
|
||||
source_node_id: sourceNodeId,
|
||||
target_node_id: targetNodeId,
|
||||
relation,
|
||||
properties: {},
|
||||
evidence,
|
||||
});
|
||||
const inferredEdge = (
|
||||
sourceNodeId: string,
|
||||
targetNodeId: string,
|
||||
relation: "invokes" | "calls" | "loads",
|
||||
path: string,
|
||||
) =>
|
||||
createJavaScriptApplicationEdge({
|
||||
source_node_id: sourceNodeId,
|
||||
target_node_id: targetNodeId,
|
||||
relation,
|
||||
properties: {},
|
||||
evidence: inferredArtifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
path,
|
||||
),
|
||||
});
|
||||
|
||||
const nodes = [
|
||||
packageNode,
|
||||
asarNode,
|
||||
preloadNode,
|
||||
bridgeNode,
|
||||
channelNode,
|
||||
handlerNode,
|
||||
addonNode,
|
||||
exportNode,
|
||||
runtimeNode,
|
||||
];
|
||||
const edges = [
|
||||
observedEdge(
|
||||
packageNode.node_id,
|
||||
asarNode.node_id,
|
||||
"contains",
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.package,
|
||||
"resources/app.asar",
|
||||
),
|
||||
),
|
||||
observedEdge(
|
||||
asarNode.node_id,
|
||||
preloadNode.node_id,
|
||||
"contains",
|
||||
artifactEvidence(APPLICATION_GRAPH_DIGESTS.asar, "dist/preload.js"),
|
||||
),
|
||||
observedEdge(
|
||||
preloadNode.node_id,
|
||||
bridgeNode.node_id,
|
||||
"exposes",
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/preload.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
inferredEdge(
|
||||
bridgeNode.node_id,
|
||||
channelNode.node_id,
|
||||
"invokes",
|
||||
"dist/preload.js",
|
||||
),
|
||||
observedEdge(
|
||||
channelNode.node_id,
|
||||
handlerNode.node_id,
|
||||
"handles",
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.asar,
|
||||
"dist/main.js",
|
||||
"ast-static-analysis",
|
||||
),
|
||||
),
|
||||
inferredEdge(
|
||||
handlerNode.node_id,
|
||||
addonNode.node_id,
|
||||
"loads",
|
||||
"dist/main.js",
|
||||
),
|
||||
inferredEdge(
|
||||
handlerNode.node_id,
|
||||
exportNode.node_id,
|
||||
"calls",
|
||||
"dist/main.js",
|
||||
),
|
||||
observedEdge(
|
||||
addonNode.node_id,
|
||||
exportNode.node_id,
|
||||
"contains",
|
||||
artifactEvidence(
|
||||
APPLICATION_GRAPH_DIGESTS.nativeAddon,
|
||||
"native/synthetic.node",
|
||||
"native-analysis-provider",
|
||||
),
|
||||
),
|
||||
createJavaScriptApplicationEdge({
|
||||
source_node_id: preloadNode.node_id,
|
||||
target_node_id: runtimeNode.node_id,
|
||||
relation: "observed_as",
|
||||
properties: {},
|
||||
evidence: runtimeEvidence("script-preload"),
|
||||
}),
|
||||
...buildArtifactNodes(),
|
||||
...buildInteractionNodes(),
|
||||
...buildNativeRuntimeNodes(),
|
||||
];
|
||||
const packageNode = nodes[0];
|
||||
if (packageNode === undefined) {
|
||||
throw new Error("Synthetic application graph fixture has no root node.");
|
||||
}
|
||||
|
||||
return createJavaScriptApplicationGraph({
|
||||
schema: "JavaScriptApplicationGraph",
|
||||
schema_version: 1,
|
||||
root_node_ids: [packageNode.node_id],
|
||||
nodes,
|
||||
edges,
|
||||
edges: buildEdges(nodes),
|
||||
coverage: completeCoverage,
|
||||
limitations: [
|
||||
"Synthetic fixture demonstrates identity and authority boundaries only.",
|
||||
|
||||
Reference in new issue
Block a user