mirror of
https://github.com/morluto/rea
synced 2026-10-26 22:28:27 -04:00
fix(javascript): preserve loader ownership and unavailable artifact facts
Preserve missing ASAR companion occurrence identity, declared size and unknown content in graph nodes and resolution limitations. Apply URL text semantics once for ESM lookup while preserving literal CommonJS paths and original specifiers. Keep CJS wrapper var bindings and assignment history, recognizing only untouched wrapper redeclarations. Validation: real ASAR producer workflow and CLI/MCP path/coverage cases; semantic reassignment controls. Context7 Node documentation and direct Node wrapper execution confirm wrapper behavior. Fixes #3213 Fixes #3214 Fixes #3223 Related: #3278, #3254 Co-authored-by: Geronimo <varungore1@gmail.com> Co-authored-by: Paolo Valletta <paovalletta@hotmail.it>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import type { ArtifactInventorySnapshot } from "../../domain/artifactInventorySnapshot.js";
|
||||
import type { ApplicationNode } from "../../domain/javascript/javascriptApplicationGraphSchemas.js";
|
||||
import { htmlInlineScriptLimitation } from "./JavaScriptArtifactAnalysis.js";
|
||||
import { completeApplicationCoverage } from "../../domain/javascript/javascriptApplicationEvidenceSchemas.js";
|
||||
import {
|
||||
completeApplicationCoverage,
|
||||
partialApplicationCoverage,
|
||||
} from "../../domain/javascript/javascriptApplicationEvidenceSchemas.js";
|
||||
import type { JavaScriptModuleArtifactAnalysis } from "./JavaScriptArtifactAnalysisTypes.js";
|
||||
import { jsonValueSchema } from "../../domain/jsonValue.js";
|
||||
import { freezeJsonSnapshot } from "../../domain/immutableJson.js";
|
||||
@@ -300,8 +303,133 @@ export const addJavaScriptArtifactFiles = (
|
||||
},
|
||||
});
|
||||
}
|
||||
addUnavailableAsarEntries(context);
|
||||
};
|
||||
|
||||
const addUnavailableAsarEntries = (
|
||||
context: JavaScriptArtifactGraphContext,
|
||||
): void => {
|
||||
for (const file of context.fileSet.unavailable_relevant_files) {
|
||||
if (!isAsarContainer(context, file.container_sha256)) continue;
|
||||
const limitations = [
|
||||
...(file.limitations ?? []),
|
||||
`The inventoried ${file.kind ?? "relevant"} entry has unavailable bytes; no content artifact identity can be established.`,
|
||||
];
|
||||
const entry = context.accumulator.addNode({
|
||||
kind: "asar-entry",
|
||||
identity: {
|
||||
strategy: "canonical-path",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: file.container_sha256,
|
||||
path: file.path,
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: file.path,
|
||||
properties: {
|
||||
entry_sha256: file.sha256,
|
||||
bytes: file.bytes,
|
||||
inventory_artifact_id: file.inventory_artifact_id,
|
||||
...(file.inventory_occurrence_id === undefined
|
||||
? {}
|
||||
: { inventory_occurrence_id: file.inventory_occurrence_id }),
|
||||
hash_status: file.hash_status,
|
||||
artifact_kind: file.artifact_kind,
|
||||
...(file.kind === undefined ? {} : { kind: file.kind }),
|
||||
content_available: false,
|
||||
},
|
||||
evidence: artifactObservationEvidence({
|
||||
sha256: file.container_sha256,
|
||||
path: file.path,
|
||||
operation: "inventory-asar-unavailable-entry",
|
||||
coverage: partialApplicationCoverage([], null),
|
||||
limitations,
|
||||
}),
|
||||
},
|
||||
],
|
||||
});
|
||||
const parent =
|
||||
context.containerNodes.get(file.container_sha256) ?? context.root;
|
||||
context.accumulator.addEdge({
|
||||
source_node_id: parent.node_id,
|
||||
target_node_id: entry.node_id,
|
||||
relation: "contains",
|
||||
properties: {
|
||||
path: file.path,
|
||||
content_available: false,
|
||||
hash_status: file.hash_status,
|
||||
},
|
||||
evidence: artifactObservationEvidence({
|
||||
sha256: file.container_sha256,
|
||||
path: file.path,
|
||||
operation: "inventory-asar-unavailable-entry",
|
||||
coverage: partialApplicationCoverage([], null),
|
||||
limitations,
|
||||
}),
|
||||
});
|
||||
if (file.kind === "native-addon" || file.artifact_kind === "native-addon") {
|
||||
const addon = context.accumulator.addNode({
|
||||
kind: "native-addon",
|
||||
identity: {
|
||||
strategy: "canonical-path",
|
||||
stability: "artifact-version",
|
||||
artifact_sha256: file.container_sha256,
|
||||
path: file.path,
|
||||
},
|
||||
observations: [
|
||||
{
|
||||
label: file.path,
|
||||
properties: {
|
||||
availability: "unavailable",
|
||||
...(file.hash_status === undefined
|
||||
? {}
|
||||
: { hash_status: file.hash_status }),
|
||||
...(file.artifact_kind === undefined
|
||||
? {}
|
||||
: { artifact_kind: file.artifact_kind }),
|
||||
bytes: file.bytes,
|
||||
inventory_artifact_id: file.inventory_artifact_id,
|
||||
...(file.inventory_occurrence_id === undefined
|
||||
? {}
|
||||
: { inventory_occurrence_id: file.inventory_occurrence_id }),
|
||||
},
|
||||
evidence: artifactObservationEvidence({
|
||||
sha256: file.container_sha256,
|
||||
path: file.path,
|
||||
operation: "classify-unavailable-native-addon",
|
||||
coverage: partialApplicationCoverage([], null),
|
||||
limitations,
|
||||
}),
|
||||
},
|
||||
],
|
||||
});
|
||||
context.accumulator.addEdge({
|
||||
source_node_id: entry.node_id,
|
||||
target_node_id: addon.node_id,
|
||||
relation: "contains",
|
||||
properties: {
|
||||
classification: "native-addon",
|
||||
content_available: false,
|
||||
},
|
||||
evidence: artifactObservationEvidence({
|
||||
sha256: file.container_sha256,
|
||||
path: file.path,
|
||||
operation: "classify-unavailable-native-addon",
|
||||
coverage: partialApplicationCoverage([], null),
|
||||
limitations,
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isAsarContainer = (
|
||||
context: JavaScriptArtifactGraphContext,
|
||||
containerSha256: string,
|
||||
): boolean =>
|
||||
context.snapshot.manifest.root_format === "asar" ||
|
||||
containerSha256 !== context.snapshot.manifest.root_sha256;
|
||||
|
||||
const sourceFileRange = (
|
||||
file: JavaScriptArtifactFile,
|
||||
): JavaScriptSourceRange => {
|
||||
@@ -464,10 +592,7 @@ const createAsarEntry = (
|
||||
context: JavaScriptArtifactGraphContext,
|
||||
file: JavaScriptArtifactFile,
|
||||
): ApplicationNode | undefined => {
|
||||
const isAsar =
|
||||
context.snapshot.manifest.root_format === "asar" ||
|
||||
file.container_sha256 !== context.snapshot.manifest.root_sha256;
|
||||
if (!isAsar) return undefined;
|
||||
if (!isAsarContainer(context, file.container_sha256)) return undefined;
|
||||
return context.accumulator.addNode({
|
||||
kind: "asar-entry",
|
||||
identity: {
|
||||
|
||||
Reference in New Issue
Block a user