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:
@@ -43,6 +43,24 @@ describe("DOS COM admission", () => {
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "BinaryTargetError" } });
|
||||
});
|
||||
it.each([1, 0xff00])("admits the actual file extent %i", async (length) => {
|
||||
const directory = await createTestTempDirectory("rea-com-target-");
|
||||
const path = join(directory, "fixture.com");
|
||||
const bytes = Buffer.alloc(length, 0xc3);
|
||||
await writeFile(path, bytes);
|
||||
const target = await parseBinaryTarget(path, {
|
||||
cwd: directory,
|
||||
hostArchitecture: "x64",
|
||||
formatHint: "dos-com",
|
||||
});
|
||||
if (!target.ok) throw target.error;
|
||||
expect(target.value).toMatchObject({
|
||||
format: "dos-com",
|
||||
architecture: "x86",
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
});
|
||||
expect(await readFile(path)).toEqual(bytes);
|
||||
});
|
||||
it("rejects contradictory target kind", async () => {
|
||||
const directory = await createTestTempDirectory("rea-com-target-");
|
||||
const path = join(directory, "fixture.com");
|
||||
|
||||
@@ -11,7 +11,48 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
it("distinguishes computed require member values from literal members in source evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-reference-require-members-");
|
||||
const sources = {
|
||||
const literalCallees = [
|
||||
"require",
|
||||
"require.resolve",
|
||||
'require["resolve"]',
|
||||
"require.main",
|
||||
'require["main"]',
|
||||
'require[("resolve")]',
|
||||
'require["res\\u006flve"]',
|
||||
];
|
||||
const ignoredSources = [
|
||||
'require[resolve]("./dep.js");',
|
||||
'require[main]("./dep.js");',
|
||||
'const resolve = "toString"; require[resolve]("./dep.js");',
|
||||
'const main = "toString"; require[main]("./dep.js");',
|
||||
'const resolve = "resolve"; require[resolve]("./dep.js");',
|
||||
'const main = "main"; require[main]("./dep.js");',
|
||||
'const method = "resolve"; require[method]("./dep.js");',
|
||||
'require[`resolve`]("./dep.js");',
|
||||
'require["re" + "solve"]("./dep.js");',
|
||||
...[
|
||||
"require?.",
|
||||
"require.resolve?.",
|
||||
'require["resolve"]?.',
|
||||
"require.main?.",
|
||||
'require["main"]?.',
|
||||
"require?.resolve",
|
||||
'require?.["resolve"]',
|
||||
"require?.[resolve]",
|
||||
"require?.main",
|
||||
'require?.["main"]',
|
||||
"require?.[main]",
|
||||
"(require?.resolve)",
|
||||
"require.resolve.call",
|
||||
"require.main.require",
|
||||
"module.require",
|
||||
"other.resolve",
|
||||
"other.require",
|
||||
"require.toString",
|
||||
'require["toString"]',
|
||||
].map((callee) => `${callee}("./dep.js");`),
|
||||
];
|
||||
const sources: Record<string, string> = {
|
||||
"computed.cjs": [
|
||||
'const resolve = "toString";',
|
||||
'const main = "toString";',
|
||||
@@ -21,15 +62,21 @@ it("distinguishes computed require member values from literal members in source
|
||||
].join("\n"),
|
||||
"literal.cjs": 'console.log(require["resolve"]("./dep.js"));\n',
|
||||
"dep.js": 'throw new Error("The dependency must not execute");\n',
|
||||
"ignored.cjs": ignoredSources.map((source) => `{ ${source} }`).join("\n"),
|
||||
"unknown.cjs": [
|
||||
"function load(target) {",
|
||||
" require(target);",
|
||||
" require.resolve(target);",
|
||||
' require["resolve"](target);',
|
||||
...literalCallees.flatMap((callee) => [
|
||||
` ${callee}(target);`,
|
||||
` ${callee}(\`./dep.js\`);`,
|
||||
` ${callee}(getTarget());`,
|
||||
` ${callee}();`,
|
||||
]),
|
||||
" return import(target);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
};
|
||||
for (const [index, callee] of literalCallees.entries())
|
||||
sources[`member-${index}.cjs`] = `${callee}("./dep.js");\n`;
|
||||
await Promise.all(
|
||||
Object.entries(sources).map(([path, source]) =>
|
||||
writeFile(join(root, path), source),
|
||||
@@ -67,6 +114,13 @@ it("distinguishes computed require member values from literal members in source
|
||||
resolution: "internal",
|
||||
parse_state: "parsed",
|
||||
},
|
||||
...literalCallees.map((_, index) => ({
|
||||
from_path: `member-${index}.cjs`,
|
||||
to: "dep.js",
|
||||
kind: "requires",
|
||||
resolution: "internal",
|
||||
parse_state: "parsed",
|
||||
})),
|
||||
{
|
||||
from_path: "unknown.cjs",
|
||||
to: "<dynamic-import>",
|
||||
|
||||
@@ -17,6 +17,8 @@ it("resolves dynamic source imports while retaining computed targets as unknown"
|
||||
'const lazy = import("./lazy");',
|
||||
'async function load() { return await import("./data.json", { with: { type: "json" } }); }',
|
||||
'const name = "./not-guessed.js"; import(name);',
|
||||
"import(`./${name}.js`);",
|
||||
'import("node:fs");',
|
||||
].join("\n"),
|
||||
),
|
||||
...["static.ts", "common.js", "lazy.ts"].map((path) =>
|
||||
@@ -32,7 +34,7 @@ it("resolves dynamic source imports while retaining computed targets as unknown"
|
||||
});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.parse_failures).toEqual([]);
|
||||
expect(result.value.relationships).toHaveLength(5);
|
||||
expect(result.value.relationships).toHaveLength(6);
|
||||
for (const [to, kind] of [
|
||||
["static.ts", "imports"],
|
||||
["common.js", "requires"],
|
||||
@@ -53,4 +55,11 @@ it("resolves dynamic source imports while retaining computed targets as unknown"
|
||||
resolution: "unknown",
|
||||
parse_state: "partial",
|
||||
});
|
||||
expect(result.value.relationships).toContainEqual({
|
||||
from_path: "main.ts",
|
||||
to: "node:fs",
|
||||
kind: "imports",
|
||||
resolution: "external",
|
||||
parse_state: "parsed",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,27 +11,37 @@ import {
|
||||
import { historicalSourceGraphSchema } from "../../../src/domain/referenceSourceGraph.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const sources = {
|
||||
"fatal.js": 'import "./valid";\nconst = ;',
|
||||
"ignored.py": 'import "./valid"; const missing;\n',
|
||||
"lazy.js": "export const lazy = true;\n",
|
||||
"recovered.d.cts": [
|
||||
"let duplicate: number;",
|
||||
"let duplicate: number;",
|
||||
'import dep = require("./valid");',
|
||||
'declare module "ambient-package" {}',
|
||||
].join("\n"),
|
||||
"recovered.js": [
|
||||
"const missing;",
|
||||
"let duplicate;",
|
||||
"let duplicate;",
|
||||
"let duplicate;",
|
||||
'import "./valid";',
|
||||
'require("node:fs");',
|
||||
'import("./lazy");',
|
||||
"import(moduleName);",
|
||||
].join("\n"),
|
||||
"recovered.ts": [
|
||||
"let duplicate: number;",
|
||||
"let duplicate: number;",
|
||||
'import dep = require("./valid");',
|
||||
'declare module "ambient-package" {}',
|
||||
].join("\n"),
|
||||
"valid.js":
|
||||
'export { readFile } from "node:fs"; export * from "node:path";\n',
|
||||
};
|
||||
it("preserves recovered diagnostics and file evidence through filesystem import", async () => {
|
||||
const root = await createTestTempDirectory("rea-reference-recovery-");
|
||||
const sources = {
|
||||
"fatal.js": 'import "./valid";\nconst = ;',
|
||||
"recovered.js": [
|
||||
"const missing;",
|
||||
"let duplicate;",
|
||||
"let duplicate;",
|
||||
"let duplicate;",
|
||||
'import "./valid";',
|
||||
'require("node:fs");',
|
||||
"import(moduleName);",
|
||||
].join("\n"),
|
||||
"recovered.ts": [
|
||||
"let duplicate: number;",
|
||||
"let duplicate: number;",
|
||||
'import dep = require("./valid");',
|
||||
'declare module "ambient-package" {}',
|
||||
].join("\n"),
|
||||
"valid.js": 'export * from "node:path";\n',
|
||||
};
|
||||
await mkdir(join(root, "src"));
|
||||
await Promise.all(
|
||||
Object.entries(sources).map(([path, source]) =>
|
||||
@@ -66,6 +76,11 @@ it("preserves recovered diagnostics and file evidence through filesystem import"
|
||||
|
||||
const failures = [
|
||||
{ path: "src/fatal.js", parser: "babel", reason: "Unexpected token (2:6)" },
|
||||
{
|
||||
path: "src/recovered.d.cts",
|
||||
parser: "babel",
|
||||
reason: "Identifier 'duplicate' has already been declared. (2:4)",
|
||||
},
|
||||
{
|
||||
path: "src/recovered.js",
|
||||
parser: "babel",
|
||||
@@ -94,6 +109,20 @@ it("preserves recovered diagnostics and file evidence through filesystem import"
|
||||
),
|
||||
).toEqual(failures);
|
||||
expect(graph.relationships).toEqual([
|
||||
{
|
||||
from_path: "src/recovered.d.cts",
|
||||
to: "ambient-package",
|
||||
kind: "declares-module",
|
||||
resolution: "unknown",
|
||||
parse_state: "partial",
|
||||
},
|
||||
{
|
||||
from_path: "src/recovered.d.cts",
|
||||
to: "src/valid.js",
|
||||
kind: "requires",
|
||||
resolution: "internal",
|
||||
parse_state: "partial",
|
||||
},
|
||||
{
|
||||
from_path: "src/recovered.js",
|
||||
to: "<dynamic-import>",
|
||||
@@ -108,6 +137,13 @@ it("preserves recovered diagnostics and file evidence through filesystem import"
|
||||
resolution: "external",
|
||||
parse_state: "partial",
|
||||
},
|
||||
{
|
||||
from_path: "src/recovered.js",
|
||||
to: "src/lazy.js",
|
||||
kind: "imports",
|
||||
resolution: "internal",
|
||||
parse_state: "partial",
|
||||
},
|
||||
{
|
||||
from_path: "src/recovered.js",
|
||||
to: "src/valid.js",
|
||||
@@ -129,6 +165,13 @@ it("preserves recovered diagnostics and file evidence through filesystem import"
|
||||
resolution: "internal",
|
||||
parse_state: "partial",
|
||||
},
|
||||
{
|
||||
from_path: "src/valid.js",
|
||||
to: "node:fs",
|
||||
kind: "imports",
|
||||
resolution: "external",
|
||||
parse_state: "parsed",
|
||||
},
|
||||
{
|
||||
from_path: "src/valid.js",
|
||||
to: "node:path",
|
||||
|
||||
Reference in New Issue
Block a user