refactor: consolidate boundary semantics and prune redundant tests
Share parser modes and collision-free composite keys, enforce architecture guards, and consolidate redundant unit assertions into filesystem, CLI, MCP, and producer-backed workflows. Preserve concurrent upstream boundary fixes and exclude legacy Objective-C class-name bookkeeping labels. Validation: source/composition suites (3358 passing), focused canonical digest and MCP checks, typecheck/lint, Knip, formatting, architecture guards, and real Foundation archive and Apple legacy simulator CLI/MCP verification. No real Hopper, Ghidra, or IDA verification claim.
This commit is contained in:
@@ -148,8 +148,27 @@ try {
|
||||
target,
|
||||
status,
|
||||
})),
|
||||
[{ source: null, path: ["UID"], target: 1, status: "resolved" }],
|
||||
[
|
||||
{ source: null, path: ["CF$UID"], target: 1, status: "resolved" },
|
||||
{ source: null, path: ["UID"], target: 1, status: "resolved" },
|
||||
],
|
||||
);
|
||||
const selected = await artifactCli("inspect-keyed-archive", path, [
|
||||
"--root",
|
||||
"UID",
|
||||
]);
|
||||
assert.deepEqual(
|
||||
selected.references,
|
||||
uidGraph.references.filter(({ path }) => path[0] === "UID"),
|
||||
);
|
||||
await withArtifactMcp(path, async (client) => {
|
||||
assert.deepEqual(
|
||||
await artifactMcpResult(client, "inspect_keyed_archive", {
|
||||
root: "UID",
|
||||
}),
|
||||
selected,
|
||||
);
|
||||
});
|
||||
}
|
||||
const numericTests = spawnSync(
|
||||
"npm",
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import {
|
||||
artifactCliEvidence,
|
||||
artifactMcpResult,
|
||||
withArtifactMcp,
|
||||
} from "../../lib/artifact-e2e.mjs";
|
||||
|
||||
const exec = promisify(execFile);
|
||||
|
||||
if (process.platform !== "darwin")
|
||||
throw new Error(
|
||||
"Legacy simulator verification requires a macOS host with full Xcode.",
|
||||
);
|
||||
for (const tool of ["clang", "ld", "vtool", "otool"])
|
||||
await exec("/usr/bin/xcrun", ["--find", tool], { timeout: 30_000 });
|
||||
const { stdout: sdk } = await exec(
|
||||
"/usr/bin/xcrun",
|
||||
["--sdk", "iphonesimulator", "--show-sdk-path"],
|
||||
{ timeout: 30_000 },
|
||||
);
|
||||
const sdkPath = sdk.trim();
|
||||
assert.ok(sdkPath.length > 0, "iPhoneSimulator SDK path is empty");
|
||||
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-legacy-simulator-"));
|
||||
const xcrun = (...args) =>
|
||||
exec("/usr/bin/xcrun", args, {
|
||||
timeout: 120_000,
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
});
|
||||
try {
|
||||
// Source-owned fixture, never executed: a legacy deployment target makes
|
||||
// the Apple driver emit LC_VERSION_MIN_IPHONEOS (no simulator flag), while
|
||||
// the modern dylib carries LC_BUILD_VERSION with an explicit simulator ID.
|
||||
await writeFile(join(root, "library.c"), "int fixture(void) { return 7; }\n");
|
||||
await writeFile(
|
||||
join(root, "main.c"),
|
||||
"extern int fixture(void);\nint main(void) { return fixture(); }\n",
|
||||
);
|
||||
for (const [source, deployment] of [
|
||||
["library", "14.0"],
|
||||
["main", "9.0"],
|
||||
]) {
|
||||
await xcrun(
|
||||
"clang",
|
||||
"-target",
|
||||
`x86_64-apple-ios${deployment}-simulator`,
|
||||
"-isysroot",
|
||||
sdkPath,
|
||||
"-c",
|
||||
join(root, `${source}.c`),
|
||||
"-o",
|
||||
join(root, `${source}.o`),
|
||||
);
|
||||
}
|
||||
const common = ["-arch", "x86_64", "-syslibroot", sdkPath, "-lSystem"];
|
||||
await xcrun(
|
||||
"ld",
|
||||
...common,
|
||||
"-dylib",
|
||||
"-platform_version",
|
||||
"ios-simulator",
|
||||
"14.0",
|
||||
"14.0",
|
||||
"-install_name",
|
||||
"@rpath/libFixture.dylib",
|
||||
join(root, "library.o"),
|
||||
"-o",
|
||||
join(root, "libFixture.dylib"),
|
||||
);
|
||||
await xcrun(
|
||||
"clang",
|
||||
"-target",
|
||||
"x86_64-apple-ios9.0-simulator",
|
||||
"-isysroot",
|
||||
sdkPath,
|
||||
"-e",
|
||||
"_main",
|
||||
"-rpath",
|
||||
"@loader_path",
|
||||
join(root, "main.o"),
|
||||
join(root, "libFixture.dylib"),
|
||||
"-o",
|
||||
join(root, "Main"),
|
||||
);
|
||||
|
||||
// Apple oracle: the executable really uses the legacy command, the dylib
|
||||
// really declares the modern simulator platform.
|
||||
const { stdout: legacyBuild } = await xcrun(
|
||||
"vtool",
|
||||
"-show-build",
|
||||
join(root, "Main"),
|
||||
);
|
||||
assert.match(legacyBuild, /LC_VERSION_MIN_IPHONEOS/u);
|
||||
assert.doesNotMatch(legacyBuild, /LC_BUILD_VERSION/u);
|
||||
const { stdout: modernBuild } = await xcrun(
|
||||
"vtool",
|
||||
"-show-build",
|
||||
join(root, "libFixture.dylib"),
|
||||
);
|
||||
assert.match(modernBuild, /IOSSIMULATOR/u);
|
||||
|
||||
// Real CLI over the fixture: the target is the executable file (plain
|
||||
// directories are not binary targets); @loader_path resolves against its
|
||||
// directory. The legacy x86 image must classify as iOS simulator
|
||||
// (platform 7) and resolve against the modern dylib.
|
||||
// The fixture is inspected, never executed or loaded into this process.
|
||||
const mainPath = join(root, "Main");
|
||||
const trace = (await artifactCliEvidence("trace-dylib-resolution", mainPath))
|
||||
.normalized_result;
|
||||
const main = trace.images.find(({ path }) => path === "Main");
|
||||
assert.ok(main, "trace omitted the Main image");
|
||||
assert.equal(main.parse_status, "parsed");
|
||||
assert.deepEqual(main.slices[0]?.platforms, [7]);
|
||||
const edge = trace.edges.find(
|
||||
({ loader, install_name: name }) =>
|
||||
loader === "Main" && name === "@rpath/libFixture.dylib",
|
||||
);
|
||||
assert.ok(edge, "trace omitted the @rpath edge");
|
||||
assert.deepEqual(edge.resolution, {
|
||||
status: "resolved",
|
||||
image: "libFixture.dylib",
|
||||
});
|
||||
|
||||
await withArtifactMcp(mainPath, async (client) => {
|
||||
assert.deepEqual(
|
||||
await artifactMcpResult(client, "trace_dylib_resolution"),
|
||||
trace,
|
||||
);
|
||||
});
|
||||
console.log(
|
||||
"Legacy simulator verification passed against Apple clang, ld, vtool, and otool.",
|
||||
);
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true });
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
// Architecture guards for the strict-identity / best-effort-inference split.
|
||||
// - Evidence ordering must be locale-independent (ICU varies by host), so
|
||||
// src/domain orders with compareUnicodeCodePoints, never localeCompare.
|
||||
// - Composite dedup keys must not NUL-join variable-length or free-form
|
||||
// MIDDLE fields: ["a\0b"] collapses with ["a", "b"] and drops a finding.
|
||||
// compositeKey (JSON tuple) is the single owner for composite keys.
|
||||
// - Transparent wrappers unwrap in exactly one place
|
||||
// (javascriptAstValues.unwrapJavaScriptExpression); direct isTS* unwrapping
|
||||
// elsewhere drifts (the `satisfies` class of bug).
|
||||
// - AST walks go through traverseJavaScriptAst/childNodes: bespoke
|
||||
// Object.values walkers diverge on loc/comment fields and overflow the
|
||||
// stack on deep generated chains.
|
||||
|
||||
const root = new URL("../../", import.meta.url).pathname;
|
||||
|
||||
const listFiles = async (dir) => {
|
||||
const output = [];
|
||||
for (const entry of await readdir(dir, { withFileTypes: true })) {
|
||||
const path = join(dir, entry.name);
|
||||
if (entry.isDirectory()) output.push(...(await listFiles(path)));
|
||||
else if (
|
||||
entry.name.endsWith(".ts") &&
|
||||
!entry.name.endsWith(".test.ts") &&
|
||||
!entry.name.endsWith(".fixture.ts")
|
||||
)
|
||||
output.push(path);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
const stripComments = (content) =>
|
||||
content
|
||||
.split("\n")
|
||||
.filter((line) => !line.trimStart().startsWith("//"))
|
||||
.join("\n")
|
||||
.replace(/\/\*[\s\S]*?\*\//gu, "");
|
||||
|
||||
const sources = await listFiles(join(root, "src"));
|
||||
const files = await Promise.all(
|
||||
sources.map(async (path) => ({
|
||||
path: path.slice(root.length),
|
||||
content: stripComments(await readFile(path, "utf8")),
|
||||
})),
|
||||
);
|
||||
const inDir = (dir) => files.filter((file) => file.path.startsWith(dir));
|
||||
|
||||
const failures = [];
|
||||
const check = (label, selected, pattern, allow = []) => {
|
||||
const offenders = selected.filter(
|
||||
(file) => pattern.test(file.content) && !allow.includes(file.path),
|
||||
);
|
||||
if (offenders.length > 0)
|
||||
failures.push(
|
||||
`${label}:\n${offenders.map((file) => ` ${file.path}`).join("\n")}`,
|
||||
);
|
||||
};
|
||||
|
||||
check(
|
||||
"src/domain uses localeCompare (use compareUnicodeCodePoints)",
|
||||
inDir("src/domain/"),
|
||||
/\.localeCompare\(/,
|
||||
);
|
||||
|
||||
check(
|
||||
"NUL-joined list key (use compositeKey)",
|
||||
files,
|
||||
/\.join\(["']\\0["']\)/,
|
||||
[
|
||||
// Sorted pair of constrained trace IDs; documented in plan.
|
||||
"src/domain/process/processTraceSpecification.ts",
|
||||
],
|
||||
);
|
||||
|
||||
check(
|
||||
"direct transparent-wrapper unwrap outside javascriptAstValues (use unwrapJavaScriptExpression)",
|
||||
files,
|
||||
/isTSAsExpression|isTSSatisfiesExpression|isTSNonNullExpression|isTSTypeAssertion|isTSInstantiationExpression|isParenthesizedExpression/,
|
||||
["src/domain/javascript/javascriptAstValues.ts"],
|
||||
);
|
||||
|
||||
check(
|
||||
"bespoke AST child walker (use traverseJavaScriptAst/childNodes)",
|
||||
files,
|
||||
/VISITOR_KEYS/,
|
||||
["src/domain/javascript/javascriptSemanticTraversal.ts"],
|
||||
);
|
||||
|
||||
// Fixed-arity backtick keys audited 2026-10-10: every prefix field is NUL-free
|
||||
// (hex digests, file paths, enums, numbers, or compositeKey JSON which escapes
|
||||
// NUL), with free-form source strings only in final position. New backtick-\0
|
||||
// keys must either meet that shape (and extend this list with justification)
|
||||
// or use compositeKey.
|
||||
check(
|
||||
"new backtick-NUL composite key (audit against the rule above)",
|
||||
files,
|
||||
/`[^`\n]*\\0/,
|
||||
[
|
||||
"src/application/javascript/ElectronBoundaryAnalysis.ts",
|
||||
"src/application/javascript/ElectronBoundaryGraphContext.ts",
|
||||
"src/application/javascript/JavaScriptArtifactGraphContext.ts",
|
||||
"src/browser/CdpCaptureCompleteness.ts",
|
||||
"src/browser/CdpCaptureEventHandlers.ts",
|
||||
"src/browser/CdpPageCapture.ts",
|
||||
"src/browser/WebSourceMapFetcher.ts",
|
||||
"src/domain/javascript/electronStaticAnalysisBrowser.ts",
|
||||
"src/domain/javascript/electronStaticAnalysisIpc.ts",
|
||||
"src/domain/javascript/javascriptApplicationChangeGraph.ts",
|
||||
"src/domain/javascript/javascriptApplicationVersionItems.ts",
|
||||
"src/domain/javascript/javascriptApplicationVersionKeys.ts",
|
||||
"src/domain/javascript/javascriptExportShapeSelection.ts",
|
||||
"src/domain/javascript/javascriptFeatureSeed.ts",
|
||||
"src/domain/javascript/javascriptFeatureTraversal.ts",
|
||||
"src/domain/javascript/javascriptNativeHandoff.ts",
|
||||
"src/domain/javascript/javascriptRuntimeReconciliationMatching.ts",
|
||||
"src/domain/javascript/javascriptRuntimeReconciliationSchemas.ts",
|
||||
"src/domain/javascript/javascriptSemanticQuery.ts",
|
||||
"src/domain/javascript/javascriptStaticAnalysisBundler.ts",
|
||||
"src/domain/javascript/javascriptStaticAnalysisCalls.ts",
|
||||
"src/domain/javascript/javascriptStaticAnalysisFindings.ts",
|
||||
"src/domain/localPath.ts",
|
||||
"src/domain/process/processTraceEvaluation.ts",
|
||||
"src/domain/process/processTraceSpecification.ts",
|
||||
"src/domain/unicodeCodePointOrder.ts",
|
||||
"src/domain/webBundleAnalyzerInspection.ts",
|
||||
],
|
||||
);
|
||||
|
||||
if (failures.length > 0) {
|
||||
console.error(`Architecture guards failed:\n\n${failures.join("\n\n")}\n`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log(`Architecture guards passed across ${files.length} source files.`);
|
||||
Reference in New Issue
Block a user