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:
@@ -84,6 +84,11 @@ describe.skipIf(process.platform !== "darwin")(
|
||||
"<key>Blob</key><data>AAEC</data>",
|
||||
"<key>Built</key><date>2020-01-01T00:00:00Z</date>",
|
||||
"<key>Ratio</key><real>nan</real>",
|
||||
"<key>Nested</key><array><dict>",
|
||||
"<key>Ratio</key><real>0.5</real>",
|
||||
"<key>Unbounded</key><real>-infinity</real>",
|
||||
"<key></key><string>empty key</string>",
|
||||
"</dict></array>",
|
||||
"</dict></plist>",
|
||||
].join(""),
|
||||
);
|
||||
@@ -113,6 +118,13 @@ describe.skipIf(process.platform !== "darwin")(
|
||||
iso8601: "2020-01-01T00:00:00.000Z",
|
||||
},
|
||||
Ratio: { $plist_type: "real", value: null },
|
||||
Nested: [
|
||||
{
|
||||
Ratio: 0.5,
|
||||
Unbounded: { $plist_type: "real", value: null },
|
||||
"": "empty key",
|
||||
},
|
||||
],
|
||||
},
|
||||
bundle: { identifier: "com.example.types", executable: "App" },
|
||||
provenance: [
|
||||
@@ -122,7 +134,7 @@ describe.skipIf(process.platform !== "darwin")(
|
||||
],
|
||||
limitations: [
|
||||
expect.stringContaining("XML conversion"),
|
||||
expect.stringContaining("1 non-finite real"),
|
||||
expect.stringContaining("2 non-finite real"),
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -20,37 +20,69 @@ import { observed as ok } from "../../fixtures/analysisExecution.js";
|
||||
|
||||
afterEach(closeEnhancedToolResources);
|
||||
|
||||
describe("enhanced MCP tools", () => {
|
||||
it("discovers every Objective-C class from one complete inventory", async () => {
|
||||
const client = await connect({
|
||||
execute: (name) => {
|
||||
expect(name).toBe("list_names");
|
||||
return Promise.resolve(
|
||||
ok([
|
||||
// Apple clang modern Objective-C ABI `nm` output: the first row
|
||||
// is a class definition; the remaining rows are method metadata,
|
||||
// class_ro_t, and a class reference.
|
||||
{ address: "0x70", value: "_OBJC_CLASS_$_ProbeClass" },
|
||||
{ address: "0x1a8", value: "__OBJC_$_CLASS_METHODS_ProbeClass" },
|
||||
{ address: "0x230", value: "__OBJC_CLASS_RO_$_ProbeClass" },
|
||||
{ address: "0x450", value: "_OBJC_CLASSLIST_REFERENCES_$_" },
|
||||
{
|
||||
address: "0x298",
|
||||
value: "__OBJC_$_CATEGORY_CLASS_METHODS_ProbeClass_$_Category",
|
||||
},
|
||||
]),
|
||||
);
|
||||
},
|
||||
});
|
||||
const result = jsonResult(
|
||||
await client.callTool({ name: "get_objc_classes", arguments: {} }),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
count: 1,
|
||||
classes: [{ address: "0x70", name: "_OBJC_CLASS_$_ProbeClass" }],
|
||||
});
|
||||
it("discovers declarations without counting duplicates or compiler bookkeeping", async () => {
|
||||
const client = await connect({
|
||||
execute: (name) => {
|
||||
expect(name).toBe("list_names");
|
||||
return Promise.resolve(
|
||||
ok([
|
||||
{ address: "0x1", value: "_OBJC_CLASS_$_First" },
|
||||
{ address: "0x2", value: "_OBJC_CLASS_$_Last" },
|
||||
{ address: "0x3", value: "_OBJC_CLASS_$_First" },
|
||||
{ address: "0x4", value: "__OBJC_CLASS_RO_$_First" },
|
||||
{ address: "0x5", value: "_OBJC_CLASSLIST_REFERENCES_$_" },
|
||||
{ address: "0x6", value: "l_OBJC_CLASS_NAME_" },
|
||||
{ address: "0x7", value: "_OBJC_IVAR_$_First.value" },
|
||||
{ address: "0x8", value: "_OBJC_METACLASS_$_First" },
|
||||
{ address: "0x9", value: "_OBJC_PROP_$_First.value" },
|
||||
{ address: "0xa", value: "__OBJC_PROTOCOL_$_Delegate" },
|
||||
{ address: "0xb", value: "__OBJC_PROTOCOL_$_Delegate" },
|
||||
{ address: "0xc", value: "__OBJC_PROTOCOL_REFERENCE_$_Delegate" },
|
||||
{ address: "0xd", value: "_$s4main7ScoringMp" },
|
||||
{ address: "0xe", value: "_$s4main7ScoringTL" },
|
||||
{ address: "0xf", value: "_$s4main7ScoringP5scoreSiyFTq" },
|
||||
{ address: "0x10", value: "l_OBJC_CLASS_Legacy" },
|
||||
{ address: "0x11", value: "l_OBJC_CLASS_NAME_.1" },
|
||||
]),
|
||||
);
|
||||
},
|
||||
});
|
||||
const result = jsonResult(
|
||||
await client.callTool({ name: "get_objc_classes", arguments: {} }),
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
count: 3,
|
||||
classes: [
|
||||
{ address: "0x1", name: "_OBJC_CLASS_$_First" },
|
||||
{ address: "0x2", name: "_OBJC_CLASS_$_Last" },
|
||||
{ address: "0x10", name: "l_OBJC_CLASS_Legacy" },
|
||||
],
|
||||
});
|
||||
expect(
|
||||
jsonResult(
|
||||
await client.callTool({
|
||||
name: "get_objc_classes",
|
||||
arguments: { pattern: "First" },
|
||||
}),
|
||||
),
|
||||
).toMatchObject({
|
||||
count: 1,
|
||||
classes: [{ address: "0x1", name: "_OBJC_CLASS_$_First" }],
|
||||
});
|
||||
expect(
|
||||
jsonResult(
|
||||
await client.callTool({ name: "get_objc_protocols", arguments: {} }),
|
||||
),
|
||||
).toMatchObject({
|
||||
count: 2,
|
||||
protocols: [
|
||||
{ address: "0xa", name: "__OBJC_PROTOCOL_$_Delegate" },
|
||||
{ address: "0xd", name: "_$s4main7ScoringMp" },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
describe("enhanced MCP tools", () => {
|
||||
it("returns the complete overview inline with exhaustive totals", async () => {
|
||||
const client = await connect({
|
||||
execute: (name) => {
|
||||
|
||||
@@ -36,7 +36,18 @@ describe("Swift classification through MCP", () => {
|
||||
arguments: test.arguments,
|
||||
});
|
||||
expect(result.isError).not.toBe(true);
|
||||
expect(jsonResult(result)).toMatchObject({ total: test.total });
|
||||
const inventory = jsonResult(result);
|
||||
expect(inventory).toMatchObject({ total: test.total });
|
||||
if (test.arguments.pattern === undefined)
|
||||
expect(inventory).toMatchObject({
|
||||
categories: {
|
||||
structs: {
|
||||
items: expect.not.arrayContaining([
|
||||
expect.objectContaining({ address: "0x100000c0c" }),
|
||||
]),
|
||||
},
|
||||
},
|
||||
});
|
||||
if (test.arguments.pattern === undefined)
|
||||
expect(jsonResult(result)).toMatchObject({
|
||||
unclassified: [
|
||||
|
||||
@@ -16,10 +16,14 @@ describe("Ghidra MCP native API evidence", () => {
|
||||
).structuredContent,
|
||||
);
|
||||
expect(inspection.normalized_result).toMatchObject({
|
||||
procedure: { address: "0x401000", name: "fixture_main" },
|
||||
boundary: {
|
||||
available: true,
|
||||
return_type: { data_type: "int", confidence: "medium" },
|
||||
jump_tables: [
|
||||
{
|
||||
dispatch_address: "0x401010",
|
||||
data_sources: [{ address: "0x403000" }],
|
||||
mappings: [{ case_value: 0, target_address: "0x401020" }],
|
||||
default_targets: [
|
||||
{ target_address: "0x401030", confidence: "high" },
|
||||
@@ -27,6 +31,7 @@ describe("Ghidra MCP native API evidence", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
unsupported_branches: [],
|
||||
residual_unknowns: [],
|
||||
});
|
||||
expect(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
@@ -385,13 +386,30 @@ const verifyImport = async (
|
||||
operation: "import_managed_reconstruction",
|
||||
provider: { id: "rea-dotnet-workflows" },
|
||||
confidence: "inferred",
|
||||
authority: "analyst-inference",
|
||||
normalized_result: {
|
||||
phase: "reconstruction-import",
|
||||
executed: false,
|
||||
decompiler: { name: "ilspycmd", version: "9.1.0.7988", family: "ilspy" },
|
||||
summary: { imported_methods: 1, decompiled_csharp_methods: 1 },
|
||||
methods: [
|
||||
{
|
||||
token: method.token,
|
||||
validation: { canonical_observation: false },
|
||||
signature_sha256: method.signature.raw_sha256,
|
||||
normalized_il_sha256: method.body.normalized_il_sha256,
|
||||
reconstruction: {
|
||||
kind: "decompiled-csharp",
|
||||
language: "csharp",
|
||||
text_sha256: createHash("sha256")
|
||||
.update("internal static void Main() { }")
|
||||
.digest("hex"),
|
||||
},
|
||||
validation: {
|
||||
matched_static_member: true,
|
||||
exact_build_required: true,
|
||||
canonical_observation: false,
|
||||
confidence_floor: "inference",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import Foundation
|
||||
|
||||
// Encode the root under a key that matches the UID marker spelling.
|
||||
// Encode roots under keys that match both binary and XML UID marker spellings.
|
||||
let archiver = NSKeyedArchiver(requiringSecureCoding: false)
|
||||
archiver.encode("payload" as NSString, forKey: "UID")
|
||||
archiver.encode("payload" as NSString, forKey: "CF$UID")
|
||||
archiver.finishEncoding()
|
||||
try archiver.encodedData.write(to: URL(fileURLWithPath: CommandLine.arguments[1]))
|
||||
|
||||
@@ -42,6 +42,11 @@ export const typeScriptDialectCases = [
|
||||
kind: "static-import",
|
||||
source: 'const element = <section />;\nimport "./dep.js";',
|
||||
},
|
||||
{
|
||||
path: "component.d.tsx",
|
||||
kind: "static-import",
|
||||
source: 'const element = <section />;\nimport "./dep.js";',
|
||||
},
|
||||
{
|
||||
path: "component.jsx",
|
||||
kind: "static-import",
|
||||
|
||||
@@ -102,6 +102,8 @@ describe("OMP integration maintenance", () => {
|
||||
});
|
||||
|
||||
it("preserves Grok Build disabled_mcp_servers during maintenance planning", async () => {
|
||||
// Strict identity: a user-disabled integration must never be selected
|
||||
// for maintenance, even with a healthy owned entry underneath.
|
||||
const registration = `[mcp_servers.rea]\ncommand = ${JSON.stringify(process.execPath)}\nargs = [${JSON.stringify(entryPoint)}, "mcp"]\nstartup_timeout_sec = 30\n`;
|
||||
const configPath = await writeClient(
|
||||
"grok_build",
|
||||
|
||||
Reference in New Issue
Block a user