Skip to content

Commit 392f1f3

Browse files
committed
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.
1 parent 077d6c4 commit 392f1f3

78 files changed

Lines changed: 1061 additions & 2016 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ jobs:
330330
- run: npm run verify:keyed-archive
331331
- run: npm run verify:asset-catalog
332332
- run: npm run verify:macos-bundle
333+
- name: Legacy simulator platform verification
334+
run: npm run verify:legacy-simulator
333335
- name: Native installer and compiled NIB hierarchy regressions
334336
run: npm run test:focused -- tests/boundary/filesystem/installScript.test.ts tests/boundary/filesystem/nibNativeHierarchy.test.ts tests/boundary/filesystem/interfaceBuilderBundle.test.ts
335337
- name: Real binary metadata and Interface Builder integration
@@ -423,7 +425,6 @@ jobs:
423425
tests/acceptance/webModuleCli.test.ts
424426
tests/acceptance/webSourceLocationCli.test.ts
425427
tests/boundary/cli/referenceSourceImportStatus.test.ts
426-
src/cliReferenceSourceImportStatus.test.ts
427428
tests/boundary/filesystem/asarInventoryFreshness.test.ts
428429
tests/composition/javascript-applications/javascriptArtifactReconstruction.test.ts
429430
tests/conformance/providers/ghidra/windowsCapabilities.test.ts

‎package.json‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"prebuild": "npm run deps:check",
8989
"build": "node scripts/run-exclusive.mjs artifacts turbo run artifacts:skills --force",
9090
"precheck": "npm run deps:check",
91-
"check": "node scripts/run-exclusive.mjs artifacts turbo run typecheck lint format:check knip metadata:check",
91+
"check": "node scripts/run-exclusive.mjs artifacts turbo run typecheck lint format:check knip metadata:check && npm run verify:architecture-guards",
9292
"precheck:fast": "npm run deps:check",
9393
"check:fast": "turbo run typecheck lint --output-logs=errors-only",
9494
"precheck:changed": "npm run deps:check",
@@ -144,6 +144,8 @@
144144
"verify:native-ui": "npm run build:cached && node scripts/verify-native-ui.mjs",
145145
"verify:keyed-archive": "npm run build:cached && node scripts/verify/apple/keyed-archive.mjs",
146146
"verify:macos-bundle": "npm run build:cached && node scripts/verify/apple/macos-bundle.mjs",
147+
"verify:legacy-simulator": "npm run build:cached && node scripts/verify/apple/legacy-simulator.mjs",
148+
"verify:architecture-guards": "node scripts/verify/architecture-guards.mjs",
147149
"verify:ghidra": "npm run build:cached && node scripts/verify-real-ghidra.mjs",
148150
"verify:ghidra:swift": "npm run build:cached && node scripts/verify-real-ghidra-swift.mjs",
149151
"verify:ida": "npm run build:cached && node scripts/verify-real-ida.mjs",

‎scripts/verify/apple/keyed-archive.mjs‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,27 @@ try {
148148
target,
149149
status,
150150
})),
151-
[{ source: null, path: ["UID"], target: 1, status: "resolved" }],
151+
[
152+
{ source: null, path: ["CF$UID"], target: 1, status: "resolved" },
153+
{ source: null, path: ["UID"], target: 1, status: "resolved" },
154+
],
152155
);
156+
const selected = await artifactCli("inspect-keyed-archive", path, [
157+
"--root",
158+
"UID",
159+
]);
160+
assert.deepEqual(
161+
selected.references,
162+
uidGraph.references.filter(({ path }) => path[0] === "UID"),
163+
);
164+
await withArtifactMcp(path, async (client) => {
165+
assert.deepEqual(
166+
await artifactMcpResult(client, "inspect_keyed_archive", {
167+
root: "UID",
168+
}),
169+
selected,
170+
);
171+
});
153172
}
154173
const numericTests = spawnSync(
155174
"npm",
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import assert from "node:assert/strict";
2+
import { execFile } from "node:child_process";
3+
import { createHash } from "node:crypto";
4+
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
5+
import { tmpdir } from "node:os";
6+
import { join } from "node:path";
7+
import { promisify } from "node:util";
8+
9+
import {
10+
artifactCliEvidence,
11+
artifactMcpResult,
12+
withArtifactMcp,
13+
} from "../../lib/artifact-e2e.mjs";
14+
15+
const exec = promisify(execFile);
16+
17+
if (process.platform !== "darwin")
18+
throw new Error(
19+
"Legacy simulator verification requires a macOS host with full Xcode.",
20+
);
21+
for (const tool of ["clang", "ld", "vtool", "otool"])
22+
await exec("/usr/bin/xcrun", ["--find", tool], { timeout: 30_000 });
23+
const { stdout: sdk } = await exec(
24+
"/usr/bin/xcrun",
25+
["--sdk", "iphonesimulator", "--show-sdk-path"],
26+
{ timeout: 30_000 },
27+
);
28+
const sdkPath = sdk.trim();
29+
assert.ok(sdkPath.length > 0, "iPhoneSimulator SDK path is empty");
30+
31+
const root = await mkdtemp(join(tmpdir(), "rea-legacy-simulator-"));
32+
const xcrun = (...args) =>
33+
exec("/usr/bin/xcrun", args, {
34+
timeout: 120_000,
35+
maxBuffer: 16 * 1024 * 1024,
36+
});
37+
try {
38+
// Source-owned fixture, never executed: a legacy deployment target makes
39+
// the Apple driver emit LC_VERSION_MIN_IPHONEOS (no simulator flag), while
40+
// the modern dylib carries LC_BUILD_VERSION with an explicit simulator ID.
41+
await writeFile(join(root, "library.c"), "int fixture(void) { return 7; }\n");
42+
await writeFile(
43+
join(root, "main.c"),
44+
"extern int fixture(void);\nint main(void) { return fixture(); }\n",
45+
);
46+
for (const [source, deployment] of [
47+
["library", "14.0"],
48+
["main", "9.0"],
49+
]) {
50+
await xcrun(
51+
"clang",
52+
"-target",
53+
`x86_64-apple-ios${deployment}-simulator`,
54+
"-isysroot",
55+
sdkPath,
56+
"-c",
57+
join(root, `${source}.c`),
58+
"-o",
59+
join(root, `${source}.o`),
60+
);
61+
}
62+
const common = ["-arch", "x86_64", "-syslibroot", sdkPath, "-lSystem"];
63+
await xcrun(
64+
"ld",
65+
...common,
66+
"-dylib",
67+
"-platform_version",
68+
"ios-simulator",
69+
"14.0",
70+
"14.0",
71+
"-install_name",
72+
"@rpath/libFixture.dylib",
73+
join(root, "library.o"),
74+
"-o",
75+
join(root, "libFixture.dylib"),
76+
);
77+
await xcrun(
78+
"clang",
79+
"-target",
80+
"x86_64-apple-ios9.0-simulator",
81+
"-isysroot",
82+
sdkPath,
83+
"-e",
84+
"_main",
85+
"-rpath",
86+
"@loader_path",
87+
join(root, "main.o"),
88+
join(root, "libFixture.dylib"),
89+
"-o",
90+
join(root, "Main"),
91+
);
92+
93+
// Apple oracle: the executable really uses the legacy command, the dylib
94+
// really declares the modern simulator platform.
95+
const { stdout: legacyBuild } = await xcrun(
96+
"vtool",
97+
"-show-build",
98+
join(root, "Main"),
99+
);
100+
assert.match(legacyBuild, /LC_VERSION_MIN_IPHONEOS/u);
101+
assert.doesNotMatch(legacyBuild, /LC_BUILD_VERSION/u);
102+
const { stdout: modernBuild } = await xcrun(
103+
"vtool",
104+
"-show-build",
105+
join(root, "libFixture.dylib"),
106+
);
107+
assert.match(modernBuild, /IOSSIMULATOR/u);
108+
109+
// Real CLI over the fixture: the target is the executable file (plain
110+
// directories are not binary targets); @loader_path resolves against its
111+
// directory. The legacy x86 image must classify as iOS simulator
112+
// (platform 7) and resolve against the modern dylib.
113+
// The fixture is inspected, never executed or loaded into this process.
114+
const mainPath = join(root, "Main");
115+
const trace = (await artifactCliEvidence("trace-dylib-resolution", mainPath))
116+
.normalized_result;
117+
const main = trace.images.find(({ path }) => path === "Main");
118+
assert.ok(main, "trace omitted the Main image");
119+
assert.equal(main.parse_status, "parsed");
120+
assert.deepEqual(main.slices[0]?.platforms, [7]);
121+
const edge = trace.edges.find(
122+
({ loader, install_name: name }) =>
123+
loader === "Main" && name === "@rpath/libFixture.dylib",
124+
);
125+
assert.ok(edge, "trace omitted the @rpath edge");
126+
assert.deepEqual(edge.resolution, {
127+
status: "resolved",
128+
image: "libFixture.dylib",
129+
});
130+
131+
await withArtifactMcp(mainPath, async (client) => {
132+
assert.deepEqual(
133+
await artifactMcpResult(client, "trace_dylib_resolution"),
134+
trace,
135+
);
136+
});
137+
console.log(
138+
"Legacy simulator verification passed against Apple clang, ld, vtool, and otool.",
139+
);
140+
} finally {
141+
await rm(root, { recursive: true, force: true });
142+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import assert from "node:assert/strict";
2+
import { readFile, readdir } from "node:fs/promises";
3+
import { join } from "node:path";
4+
5+
// Architecture guards for the strict-identity / best-effort-inference split.
6+
// - Evidence ordering must be locale-independent (ICU varies by host), so
7+
// src/domain orders with compareUnicodeCodePoints, never localeCompare.
8+
// - Composite dedup keys must not NUL-join variable-length or free-form
9+
// MIDDLE fields: ["a\0b"] collapses with ["a", "b"] and drops a finding.
10+
// compositeKey (JSON tuple) is the single owner for composite keys.
11+
// - Transparent wrappers unwrap in exactly one place
12+
// (javascriptAstValues.unwrapJavaScriptExpression); direct isTS* unwrapping
13+
// elsewhere drifts (the `satisfies` class of bug).
14+
// - AST walks go through traverseJavaScriptAst/childNodes: bespoke
15+
// Object.values walkers diverge on loc/comment fields and overflow the
16+
// stack on deep generated chains.
17+
18+
const root = new URL("../../", import.meta.url).pathname;
19+
20+
const listFiles = async (dir) => {
21+
const output = [];
22+
for (const entry of await readdir(dir, { withFileTypes: true })) {
23+
const path = join(dir, entry.name);
24+
if (entry.isDirectory()) output.push(...(await listFiles(path)));
25+
else if (
26+
entry.name.endsWith(".ts") &&
27+
!entry.name.endsWith(".test.ts") &&
28+
!entry.name.endsWith(".fixture.ts")
29+
)
30+
output.push(path);
31+
}
32+
return output;
33+
};
34+
35+
const stripComments = (content) =>
36+
content
37+
.split("\n")
38+
.filter((line) => !line.trimStart().startsWith("//"))
39+
.join("\n")
40+
.replace(/\/\*[\s\S]*?\*\//gu, "");
41+
42+
const sources = await listFiles(join(root, "src"));
43+
const files = await Promise.all(
44+
sources.map(async (path) => ({
45+
path: path.slice(root.length),
46+
content: stripComments(await readFile(path, "utf8")),
47+
})),
48+
);
49+
const inDir = (dir) => files.filter((file) => file.path.startsWith(dir));
50+
51+
const failures = [];
52+
const check = (label, selected, pattern, allow = []) => {
53+
const offenders = selected.filter(
54+
(file) => pattern.test(file.content) && !allow.includes(file.path),
55+
);
56+
if (offenders.length > 0)
57+
failures.push(
58+
`${label}:\n${offenders.map((file) => ` ${file.path}`).join("\n")}`,
59+
);
60+
};
61+
62+
check(
63+
"src/domain uses localeCompare (use compareUnicodeCodePoints)",
64+
inDir("src/domain/"),
65+
/\.localeCompare\(/,
66+
);
67+
68+
check(
69+
"NUL-joined list key (use compositeKey)",
70+
files,
71+
/\.join\(["']\\0["']\)/,
72+
[
73+
// Sorted pair of constrained trace IDs; documented in plan.
74+
"src/domain/process/processTraceSpecification.ts",
75+
],
76+
);
77+
78+
check(
79+
"direct transparent-wrapper unwrap outside javascriptAstValues (use unwrapJavaScriptExpression)",
80+
files,
81+
/isTSAsExpression|isTSSatisfiesExpression|isTSNonNullExpression|isTSTypeAssertion|isTSInstantiationExpression|isParenthesizedExpression/,
82+
["src/domain/javascript/javascriptAstValues.ts"],
83+
);
84+
85+
check(
86+
"bespoke AST child walker (use traverseJavaScriptAst/childNodes)",
87+
files,
88+
/VISITOR_KEYS/,
89+
["src/domain/javascript/javascriptSemanticTraversal.ts"],
90+
);
91+
92+
// Fixed-arity backtick keys audited 2026-10-10: every prefix field is NUL-free
93+
// (hex digests, file paths, enums, numbers, or compositeKey JSON which escapes
94+
// NUL), with free-form source strings only in final position. New backtick-\0
95+
// keys must either meet that shape (and extend this list with justification)
96+
// or use compositeKey.
97+
check(
98+
"new backtick-NUL composite key (audit against the rule above)",
99+
files,
100+
/`[^`\n]*\\0/,
101+
[
102+
"src/application/javascript/ElectronBoundaryAnalysis.ts",
103+
"src/application/javascript/ElectronBoundaryGraphContext.ts",
104+
"src/application/javascript/JavaScriptArtifactGraphContext.ts",
105+
"src/browser/CdpCaptureCompleteness.ts",
106+
"src/browser/CdpCaptureEventHandlers.ts",
107+
"src/browser/CdpPageCapture.ts",
108+
"src/browser/WebSourceMapFetcher.ts",
109+
"src/domain/javascript/electronStaticAnalysisBrowser.ts",
110+
"src/domain/javascript/electronStaticAnalysisIpc.ts",
111+
"src/domain/javascript/javascriptApplicationChangeGraph.ts",
112+
"src/domain/javascript/javascriptApplicationVersionItems.ts",
113+
"src/domain/javascript/javascriptApplicationVersionKeys.ts",
114+
"src/domain/javascript/javascriptExportShapeSelection.ts",
115+
"src/domain/javascript/javascriptFeatureSeed.ts",
116+
"src/domain/javascript/javascriptFeatureTraversal.ts",
117+
"src/domain/javascript/javascriptNativeHandoff.ts",
118+
"src/domain/javascript/javascriptRuntimeReconciliationMatching.ts",
119+
"src/domain/javascript/javascriptRuntimeReconciliationSchemas.ts",
120+
"src/domain/javascript/javascriptSemanticQuery.ts",
121+
"src/domain/javascript/javascriptStaticAnalysisBundler.ts",
122+
"src/domain/javascript/javascriptStaticAnalysisCalls.ts",
123+
"src/domain/javascript/javascriptStaticAnalysisFindings.ts",
124+
"src/domain/localPath.ts",
125+
"src/domain/process/processTraceEvaluation.ts",
126+
"src/domain/process/processTraceSpecification.ts",
127+
"src/domain/unicodeCodePointOrder.ts",
128+
"src/domain/webBundleAnalyzerInspection.ts",
129+
],
130+
);
131+
132+
if (failures.length > 0) {
133+
console.error(`Architecture guards failed:\n\n${failures.join("\n\n")}\n`);
134+
process.exit(1);
135+
}
136+
console.log(`Architecture guards passed across ${files.length} source files.`);

0 commit comments

Comments
 (0)