mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
* fix(javascript): require exact loader suffix case * fix(javascript): share exact loader mode across import resolution * test(process): align symlink fixture with filesystem checkpoints * test(javascript): normalize the module resolution oracle path separators * test(frida): assert the CLI spawn Evidence contract * test(mcp): use an unsupported analysis-view parent * test(browser): separate source-location line bounds from parity * fix(javascript): preserve uncertain loader provenance * test(javascript): cover uncertain require resolution * fix(javascript): retain conditional Electron evidence * fix(javascript): preserve timed semantic provenance * fix(javascript): retain conditional builtin effects * test(javascript): distinguish bundled host authority * fix(javascript): preserve nested loader invocation identity * test(javascript): qualify Electron fixture authority * fix(javascript): preserve loader invocation authority * fix(javascript): respect source order for resolver escapes * fix(javascript): check nested loader callable mutations * fix(javascript): retain conditional constructor requests * fix(reference): retain constructor loader relationships * fix(reference): follow nested loader callable paths * refactor(javascript): share callable mutation interpretation * fix(javascript): require exact package loader suffixes * refactor(javascript): unify conditional relation evidence * refactor(javascript): unify conditional node evidence * fix(javascript): retain unknown authority for mixed case sources * fix(javascript): preserve loader uncertainty for dotfiles * fix(reference): classify javascript suffix dotfiles * test(reference): cover suffix dotfiles through cli * fix(javascript): retain equivalent conditional built-in origins * fix(javascript): preserve wrapped resolver operation * fix(javascript): retain nested conditional built-in receivers * test(javascript): declare CommonJS in native addon fixtures * fix(javascript): retain wrapped resolver candidates * style: format merged native command schema * fix(javascript): preserve uncertain loader authority * test(javascript): require candidate preload evidence * test(javascript): cover reference loader member writes --------- Co-authored-by: ShuaixinHuang <1836656514@qq.com>
291 lines
9.3 KiB
TypeScript
291 lines
9.3 KiB
TypeScript
import type { JavaScriptSemanticGraphNode } from "../../domain/javascript/javascriptSemanticGraphSchemas.js";
|
|
import type {
|
|
JavaScriptSemanticChildProcessInteraction,
|
|
JavaScriptSemanticChildProcessSpawn,
|
|
} from "../../domain/javascript/javascriptSemanticIr.js";
|
|
import {
|
|
retainSemanticGraphNode,
|
|
addSemanticGraphRelation,
|
|
addSemanticGraphUnknown,
|
|
} from "./JavaScriptSemanticGraphConstruction.js";
|
|
import {
|
|
unknownSemanticEvidence,
|
|
builtinSemanticNode,
|
|
builtinSemanticRelation,
|
|
} from "./JavaScriptSemanticGraphEvidence.js";
|
|
import {
|
|
projectSemanticResultBindings,
|
|
type SemanticFlowProjectionContext,
|
|
} from "./JavaScriptSemanticGraphFlowProjection.js";
|
|
|
|
interface ChildUnknownInput {
|
|
readonly context: SemanticFlowProjectionContext;
|
|
readonly node: JavaScriptSemanticGraphNode | null;
|
|
readonly location: JavaScriptSemanticChildProcessSpawn["location"];
|
|
readonly relationKinds: readonly (
|
|
| "spawns"
|
|
| "forwards-signal"
|
|
| "listens-exit"
|
|
| "listens-error"
|
|
| "connects-stdio"
|
|
)[];
|
|
readonly reason?: "unknown-value";
|
|
readonly detail: string;
|
|
readonly candidateNodeIds: readonly string[];
|
|
}
|
|
|
|
/** Project child creation, argv/env/stdio, listeners, and signals. */
|
|
export const projectSemanticChildProcesses = (
|
|
context: SemanticFlowProjectionContext,
|
|
): void => {
|
|
const processNodes = new Map(
|
|
context.ir.childProcessSpawns.flatMap((spawn) => {
|
|
const node = addChildProcessNode(context, spawn);
|
|
return node === null ? [] : [[spawn.processId, node] as const];
|
|
}),
|
|
);
|
|
for (const spawn of context.ir.childProcessSpawns) {
|
|
const child = processNodes.get(spawn.processId);
|
|
if (child === undefined) continue;
|
|
projectSpawn(context, spawn, child);
|
|
}
|
|
for (const interaction of context.ir.childProcessInteractions)
|
|
projectInteraction(context, interaction, processNodes);
|
|
};
|
|
|
|
const addChildProcessNode = (
|
|
context: SemanticFlowProjectionContext,
|
|
spawn: JavaScriptSemanticChildProcessSpawn,
|
|
): JavaScriptSemanticGraphNode | null =>
|
|
retainSemanticGraphNode(context.state, context.file, {
|
|
kind: "child-process",
|
|
roleKey: spawn.processId,
|
|
location: spawn.location,
|
|
label: spawn.command ?? spawn.method,
|
|
functionNodeId:
|
|
spawn.ownerCallableId === null
|
|
? null
|
|
: (context.callableNodes.get(spawn.ownerCallableId)?.node_id ?? null),
|
|
...builtinSemanticNode(context.file, spawn, {
|
|
argv_count: spawn.argvCount,
|
|
command: spawn.command,
|
|
environment_supplied: spawn.environmentSupplied,
|
|
method: spawn.method,
|
|
stdio_mode: spawn.stdioMode,
|
|
}),
|
|
});
|
|
|
|
const projectSpawn = (
|
|
context: SemanticFlowProjectionContext,
|
|
spawn: JavaScriptSemanticChildProcessSpawn,
|
|
child: JavaScriptSemanticGraphNode,
|
|
): void => {
|
|
const callSite = context.callSiteAt(spawn.location);
|
|
const authority = builtinSemanticRelation(
|
|
context.file,
|
|
spawn,
|
|
spawn.resolution === "complete" ? "resolved" : "candidate",
|
|
);
|
|
const candidateEvidence = authority.evidence;
|
|
addSemanticGraphRelation(context.state, {
|
|
source: callSite,
|
|
target: child,
|
|
relation: "spawns",
|
|
...authority,
|
|
...(candidateEvidence === undefined
|
|
? {}
|
|
: {
|
|
properties: { builtin_authority: "candidate" },
|
|
}),
|
|
});
|
|
projectSemanticResultBindings(
|
|
context,
|
|
child,
|
|
spawn.projectedResultBindings,
|
|
candidateEvidence,
|
|
);
|
|
if (spawn.argvCount !== null)
|
|
addSemanticGraphRelation(context.state, {
|
|
source: callSite,
|
|
target: child,
|
|
relation: "supplies-argv",
|
|
resolution: candidateEvidence === undefined ? "resolved" : "candidate",
|
|
...(candidateEvidence === undefined
|
|
? {}
|
|
: { evidence: candidateEvidence }),
|
|
properties: { argument_count: spawn.argvCount },
|
|
});
|
|
if (spawn.environmentSupplied)
|
|
addSemanticGraphRelation(context.state, {
|
|
source: callSite,
|
|
target: child,
|
|
relation: "supplies-env",
|
|
resolution: candidateEvidence === undefined ? "resolved" : "candidate",
|
|
...(candidateEvidence === undefined
|
|
? {}
|
|
: { evidence: candidateEvidence }),
|
|
});
|
|
const stdio = addStdioNode(context, spawn, child);
|
|
addSemanticGraphRelation(context.state, {
|
|
source: child,
|
|
target: stdio,
|
|
relation: "connects-stdio",
|
|
resolution:
|
|
candidateEvidence !== undefined || spawn.stdioMode === "dynamic"
|
|
? "candidate"
|
|
: "resolved",
|
|
...(candidateEvidence === undefined ? {} : { evidence: candidateEvidence }),
|
|
});
|
|
if (spawn.stdioMode === "dynamic")
|
|
addChildUnknown({
|
|
context,
|
|
node: child,
|
|
location: spawn.location,
|
|
relationKinds: ["connects-stdio"],
|
|
reason: "unknown-value",
|
|
detail: `Static ${spawn.method} stdio options remain unresolved.`,
|
|
candidateNodeIds: [],
|
|
});
|
|
if (candidateEvidence !== undefined)
|
|
addChildUnknown({
|
|
context,
|
|
node: child,
|
|
location: spawn.location,
|
|
relationKinds: ["spawns"],
|
|
detail:
|
|
"The child-process identity is conditional on loader or mutation facts.",
|
|
candidateNodeIds: [child.node_id],
|
|
});
|
|
if (spawn.resolution !== "complete")
|
|
addChildUnknown({
|
|
context,
|
|
node: child,
|
|
location: spawn.location,
|
|
relationKinds: ["spawns"],
|
|
detail: `Static ${spawn.method} command remains unresolved.`,
|
|
candidateNodeIds: [],
|
|
});
|
|
};
|
|
|
|
const addStdioNode = (
|
|
context: SemanticFlowProjectionContext,
|
|
spawn: JavaScriptSemanticChildProcessSpawn,
|
|
child: JavaScriptSemanticGraphNode,
|
|
): JavaScriptSemanticGraphNode | null =>
|
|
retainSemanticGraphNode(context.state, context.file, {
|
|
kind: "stdio",
|
|
roleKey: `stdio:${spawn.processId}`,
|
|
location: spawn.location,
|
|
label: spawn.stdioMode,
|
|
functionNodeId: child.function_node_id,
|
|
...builtinSemanticNode(context.file, spawn, {
|
|
mode: spawn.stdioMode,
|
|
}),
|
|
});
|
|
|
|
const projectInteraction = (
|
|
context: SemanticFlowProjectionContext,
|
|
interaction: JavaScriptSemanticChildProcessInteraction,
|
|
processNodes: ReadonlyMap<string, JavaScriptSemanticGraphNode>,
|
|
): void => {
|
|
const authority = builtinSemanticRelation(
|
|
context.file,
|
|
interaction,
|
|
interaction.resolution === "complete" ? "resolved" : "candidate",
|
|
);
|
|
const candidateEvidence = authority.evidence;
|
|
const children = interaction.linkedProcessIds.flatMap((identifier) => {
|
|
const child = processNodes.get(identifier);
|
|
return child === undefined ? [] : [child];
|
|
});
|
|
const effect =
|
|
interaction.kind === "listener"
|
|
? addChildListenerNode(context, interaction)
|
|
: addSignalNode(context, interaction);
|
|
for (const child of children)
|
|
addSemanticGraphRelation(context.state, {
|
|
source: interaction.kind === "listener" ? child : effect,
|
|
target: interaction.kind === "listener" ? effect : child,
|
|
relation:
|
|
interaction.kind === "signal"
|
|
? "forwards-signal"
|
|
: interaction.eventName === "exit"
|
|
? "listens-exit"
|
|
: "listens-error",
|
|
...authority,
|
|
...(candidateEvidence === undefined
|
|
? {}
|
|
: {
|
|
properties: { builtin_authority: "candidate" },
|
|
}),
|
|
});
|
|
if (interaction.resolution !== "complete")
|
|
addChildUnknown({
|
|
context,
|
|
node: effect,
|
|
location: interaction.location,
|
|
relationKinds: [
|
|
interaction.kind === "signal"
|
|
? "forwards-signal"
|
|
: interaction.eventName === "exit"
|
|
? "listens-exit"
|
|
: "listens-error",
|
|
],
|
|
detail: `Static child ${interaction.method} ownership is ambiguous.`,
|
|
candidateNodeIds: children.map(({ node_id: identifier }) => identifier),
|
|
});
|
|
};
|
|
|
|
const addChildListenerNode = (
|
|
context: SemanticFlowProjectionContext,
|
|
interaction: JavaScriptSemanticChildProcessInteraction,
|
|
): JavaScriptSemanticGraphNode | null =>
|
|
retainSemanticGraphNode(context.state, context.file, {
|
|
kind: "listener",
|
|
roleKey: interaction.interactionId,
|
|
location: interaction.listenerLocation ?? interaction.location,
|
|
label: interaction.eventName,
|
|
functionNodeId:
|
|
interaction.ownerCallableId === null
|
|
? null
|
|
: (context.callableNodes.get(interaction.ownerCallableId)?.node_id ??
|
|
null),
|
|
...builtinSemanticNode(context.file, interaction, {
|
|
event_name: interaction.eventName,
|
|
method: interaction.method,
|
|
}),
|
|
});
|
|
|
|
const addSignalNode = (
|
|
context: SemanticFlowProjectionContext,
|
|
interaction: JavaScriptSemanticChildProcessInteraction,
|
|
): JavaScriptSemanticGraphNode | null =>
|
|
retainSemanticGraphNode(context.state, context.file, {
|
|
kind: "signal",
|
|
roleKey: interaction.interactionId,
|
|
location: interaction.location,
|
|
label: interaction.signalName,
|
|
functionNodeId:
|
|
interaction.ownerCallableId === null
|
|
? null
|
|
: (context.callableNodes.get(interaction.ownerCallableId)?.node_id ??
|
|
null),
|
|
...builtinSemanticNode(context.file, interaction, {
|
|
signal_name: interaction.signalName,
|
|
}),
|
|
});
|
|
|
|
const addChildUnknown = (input: ChildUnknownInput): void => {
|
|
const { context, node, location, relationKinds, detail, candidateNodeIds } =
|
|
input;
|
|
addSemanticGraphUnknown(context.state, {
|
|
node_id: node?.node_id ?? null,
|
|
family: "child-process",
|
|
relation_kinds: relationKinds,
|
|
reason: input.reason ?? "ambiguous-target",
|
|
detail,
|
|
candidate_node_ids: candidateNodeIds,
|
|
evidence: unknownSemanticEvidence(context.file, location),
|
|
});
|
|
};
|