Merge remote-tracking branch 'origin/main' into codex/pr-1899-remove-duplicate-schema-test
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { ROLLDOWN_MODULE_INTEROP } from "../../../src/domain/javascript/javascriptModuleInterop.fixture.js";
|
||||
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
const INTRINSIC_MUTATIONS = [
|
||||
["poisoned.cjs", "({Object} = replacements);"],
|
||||
[
|
||||
"projected.cjs",
|
||||
'const {defineProperty:change} = Object; change(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"decorated.cjs",
|
||||
'@(() => Object) class metadata {}; Object.defineProperty(metadata,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"uncurried.cjs",
|
||||
'const change = Function.prototype.call.bind(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"generic-bind.cjs",
|
||||
'const change = Function.prototype.bind.call(Object.defineProperty,null); change(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"replaced-apply.cjs",
|
||||
'Reflect.apply = Object.defineProperty; Reflect.apply(Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"bound.cjs",
|
||||
'const change = Object.defineProperty.bind(null,Object,"create"); change({value:customCreate});',
|
||||
],
|
||||
["receiver.cjs", 'Reflect.set({},"create",customCreate,Object);'],
|
||||
[
|
||||
"deep-call.cjs",
|
||||
'Function.prototype.call.call.call(Object.defineProperty,null,Object,"create",{value:customCreate});',
|
||||
],
|
||||
[
|
||||
"deep-apply.cjs",
|
||||
'Function.prototype.apply.apply(Object.defineProperty,[null,[Object,"create",{value:customCreate}]]);',
|
||||
],
|
||||
] as const;
|
||||
|
||||
const writePoisonedModules = async (root: string): Promise<void> => {
|
||||
for (const [name, mutation] of INTRINSIC_MUTATIONS)
|
||||
await writeFile(
|
||||
join(root, name),
|
||||
`${mutation}
|
||||
${ROLLDOWN_MODULE_INTEROP}
|
||||
let poisoned = require("electron");
|
||||
poisoned = __toESM(poisoned, 1);
|
||||
new poisoned.BrowserWindow({});
|
||||
throw new Error("must not execute poisoned source");`,
|
||||
);
|
||||
};
|
||||
|
||||
cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
"retains converted Electron windows and preload evidence through %s",
|
||||
async (surface, { cli }) => {
|
||||
const root = await createTestTempDirectory("rea-electron-interop-");
|
||||
await writeFile(
|
||||
join(root, "package.json"),
|
||||
JSON.stringify({ main: "main.cjs" }),
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "preload.js"),
|
||||
'throw new Error("must stay inert");',
|
||||
);
|
||||
await writePoisonedModules(root);
|
||||
const source = `const metadata = {};
|
||||
Object.defineProperty(metadata,"x",{value:1});
|
||||
const decorateMetadata = Object.defineProperty.bind(null,metadata,"bound");
|
||||
decorateMetadata({value:1});
|
||||
const decorateViaCall = Function.prototype.call.bind(Object.defineProperty);
|
||||
decorateViaCall(null,metadata,"uncurried",{value:1});
|
||||
const localFunction = () => {};
|
||||
Object.defineProperty(localFunction,"x",{value:1});
|
||||
const localClass = class {};
|
||||
Object.defineProperty(localClass,"x",{value:1});
|
||||
const localRegExp = /local/;
|
||||
Object.defineProperty(localRegExp,"x",{value:1});
|
||||
Object.defineProperty(hoistedFunction,"x",{value:1});
|
||||
function hoistedFunction() {}
|
||||
const captured = Object.defineProperty;
|
||||
Object.defineProperty = custom;
|
||||
${ROLLDOWN_MODULE_INTEROP.replace("__defProp = Object.defineProperty", "__defProp = captured")}
|
||||
let electron = require("electron");
|
||||
electron = __toESM(electron, 1);
|
||||
new electron.BrowserWindow({webPreferences:{preload:"./preload.js"}});
|
||||
new electron.BrowserWindow({webPreferences:{preload:runtimePath}});
|
||||
var direct;
|
||||
var direct = require("electron");
|
||||
var direct;
|
||||
new direct.BrowserWindow({});
|
||||
const fresh = __toESM(require("electron"), 1);
|
||||
new fresh.BrowserWindow({});
|
||||
const {BrowserWindow: ProjectedWindow} = __toESM(require("electron"));
|
||||
new ProjectedWindow({});
|
||||
const nonNode = __toESM(require("electron"), 0);
|
||||
new nonNode.BrowserWindow({});
|
||||
function identity(mod) {return mod;}
|
||||
const passthrough = identity(require("electron"));
|
||||
new passthrough.BrowserWindow({});
|
||||
const __importStar = () => ({BrowserWindow:FakeWindow});
|
||||
const fake = __importStar(require("electron"));
|
||||
new fake.BrowserWindow({});
|
||||
function decoy(electron) {new electron.BrowserWindow({});}
|
||||
require("./poisoned.cjs");
|
||||
require("./projected.cjs");
|
||||
require("./decorated.cjs");
|
||||
require("./bound.cjs");
|
||||
require("./uncurried.cjs");
|
||||
require("./generic-bind.cjs");
|
||||
require("./replaced-apply.cjs");
|
||||
require("./receiver.cjs");
|
||||
require("./deep-call.cjs");
|
||||
require("./deep-apply.cjs");
|
||||
throw new Error("must not execute main");
|
||||
`;
|
||||
await writeFile(join(root, "main.cjs"), source);
|
||||
let document: unknown;
|
||||
if (surface === "CLI") {
|
||||
const response = await cli.run({
|
||||
arguments: ["analyze-javascript-application", root, "--json"],
|
||||
});
|
||||
expect(response.exitCode, response.stderr).toBe(0);
|
||||
document = response.json;
|
||||
} else {
|
||||
const { call } = await connectLocalToolsMcp();
|
||||
const response = await call("analyze_javascript_application", {
|
||||
input_path: root,
|
||||
});
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
document = response.structuredContent;
|
||||
}
|
||||
const result = z
|
||||
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
|
||||
.parse(document).normalized_result;
|
||||
expect(result.summary).toMatchObject({
|
||||
browser_windows: 7,
|
||||
preload_entrypoints: 1,
|
||||
});
|
||||
expect(result.statistics.parse_failures).toBe(0);
|
||||
expect(result.statistics.parsed_javascript_files).toBe(12);
|
||||
const windows = result.graph.nodes.filter(
|
||||
({ kind }) => kind === "browser-window",
|
||||
);
|
||||
expect(windows).toHaveLength(7);
|
||||
const expectedLines = source
|
||||
.split("\n")
|
||||
.flatMap((line, index) =>
|
||||
/^\s*new (?:(?:electron|direct|fresh|passthrough|nonNode)\.BrowserWindow|ProjectedWindow)\(/u.test(
|
||||
line,
|
||||
)
|
||||
? [index + 1]
|
||||
: [],
|
||||
);
|
||||
const observedLines = windows.flatMap((window) => {
|
||||
const location = window.observations[0]?.evidence.location;
|
||||
return location?.available && location.value.kind === "source-range"
|
||||
? [location.value.start.line]
|
||||
: [];
|
||||
});
|
||||
expect(observedLines.toSorted()).toEqual(expectedLines.toSorted());
|
||||
for (const window of windows) {
|
||||
expect(window.observations[0]?.evidence.location).toMatchObject({
|
||||
available: true,
|
||||
value: { kind: "source-range", source: "main.cjs" },
|
||||
});
|
||||
}
|
||||
expect(
|
||||
windows.flatMap((window) =>
|
||||
window.observations.map(({ properties }) => properties.web_preferences),
|
||||
),
|
||||
).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
name: "preload",
|
||||
value: {
|
||||
status: "dynamic",
|
||||
value: null,
|
||||
expression: "runtimePath",
|
||||
},
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,132 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
cliTest.skipIf(process.versions.bun !== undefined).for([
|
||||
{ laterSources: 1, heapMb: 640, methodsCount: 400, retainGraph: true },
|
||||
{ laterSources: 10, heapMb: 640, methodsCount: 400, retainGraph: true },
|
||||
// Even an otherwise empty parent cannot admit this graph after reserving
|
||||
// transient decoding and the next checkpoint, independent of GC timing.
|
||||
{ laterSources: 1, heapMb: 448, methodsCount: 600, retainGraph: false },
|
||||
])(
|
||||
"preserves evidence with $laterSources later checkpoints and a $heapMb MiB parent heap",
|
||||
{ timeout: 90_000 },
|
||||
async ({ laterSources, heapMb, methodsCount, retainGraph }, { cli }) => {
|
||||
const root = await createTestTempDirectory("rea-js-checkpoint-reserve-");
|
||||
const source = Array.from(
|
||||
{ length: methodsCount },
|
||||
(_, index) =>
|
||||
`export function method_${String(index)}(input) { const value = input + ${String(index)}; const pair = { value }; return pair.value; }`,
|
||||
).join("\n");
|
||||
const files: readonly (readonly [string, string])[] = [
|
||||
["a-large.mjs", source],
|
||||
...Array.from(
|
||||
{ length: laterSources },
|
||||
(_, index) =>
|
||||
[
|
||||
`z-tiny-${String(index)}.mjs`,
|
||||
`export const tiny${String(index)} = 1;\n`,
|
||||
] as const,
|
||||
),
|
||||
];
|
||||
for (const [name, text] of files) await writeFile(join(root, name), text);
|
||||
const response = await cli.run({
|
||||
arguments: ["analyze", root, "--format", "json"],
|
||||
environment: {
|
||||
NODE_OPTIONS: `--max-old-space-size=${String(heapMb)} --max-semi-space-size=8`,
|
||||
},
|
||||
timeoutMs: 60_000,
|
||||
});
|
||||
expect(response.exitCode).toBe(0);
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse(
|
||||
parseEvidence(response.json).normalized_result,
|
||||
);
|
||||
expect(result.statistics.parsed_javascript_files).toBe(laterSources + 1);
|
||||
expect(result.statistics.parse_failures).toBe(0);
|
||||
const failures = result.graph.nodes.flatMap(({ observations }) =>
|
||||
observations.flatMap(({ properties }) =>
|
||||
properties.analysis_failure === undefined
|
||||
? []
|
||||
: [properties.analysis_failure],
|
||||
),
|
||||
);
|
||||
const methods = result.semantic_graph.nodes.filter(
|
||||
({ kind, identity }) =>
|
||||
kind === "function" && identity.module_path === "a-large.mjs",
|
||||
);
|
||||
if (retainGraph)
|
||||
expect(methods.map(({ label }) => label).sort()).toEqual(
|
||||
Array.from(
|
||||
{ length: methodsCount },
|
||||
(_, index) => `method_${String(index)}`,
|
||||
).sort(),
|
||||
);
|
||||
else {
|
||||
expect(methods).toHaveLength(0);
|
||||
expect([
|
||||
result.graph.coverage.status,
|
||||
result.semantic_graph.coverage.status,
|
||||
]).toContain("partial");
|
||||
}
|
||||
expect(
|
||||
result.semantic_graph.nodes.some(
|
||||
({ identity, label }) =>
|
||||
identity.module_path === `z-tiny-${String(laterSources - 1)}.mjs` &&
|
||||
label === `tiny${String(laterSources - 1)}`,
|
||||
),
|
||||
).toBe(true);
|
||||
for (const [name, text] of files) {
|
||||
const digest = createHash("sha256").update(text).digest("hex");
|
||||
const node = result.graph.nodes.find(
|
||||
({ kind, identity }) =>
|
||||
kind === "javascript-asset" &&
|
||||
identity.strategy === "content-digest" &&
|
||||
identity.sha256 === digest,
|
||||
);
|
||||
expect(node?.observations).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
path: name,
|
||||
parse_status: "complete",
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
);
|
||||
if (retainGraph) expect(failures).toEqual([]);
|
||||
expect(await readFile(join(root, name), "utf8")).toBe(text);
|
||||
if (!retainGraph && name === "a-large.mjs") {
|
||||
const failure = z
|
||||
.object({
|
||||
code: z.literal("resource_constraint"),
|
||||
remediation: z.object({ action: z.string() }),
|
||||
details: z.object({
|
||||
reported_limits: z.object({
|
||||
parent_available_result_budget_bytes: z.number(),
|
||||
module_retention_estimate_bytes: z.number(),
|
||||
graph_retention_estimate_bytes: z.number(),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.parse(failures[0]);
|
||||
const limits = failure.details.reported_limits;
|
||||
expect(
|
||||
limits.module_retention_estimate_bytes +
|
||||
limits.graph_retention_estimate_bytes,
|
||||
).toBeGreaterThan(limits.parent_available_result_budget_bytes);
|
||||
expect(failure.remediation.action).toContain("parent result budget");
|
||||
expect(failure.remediation.action).toContain(
|
||||
"retained static and module facts",
|
||||
);
|
||||
}
|
||||
}
|
||||
expect(response.stderr).not.toMatch(/FATAL ERROR:.*heap/iu);
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,282 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join, relative } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { connectLocalToolsMcp } from "../../fixtures/localToolsMcp.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
const literalAliases = ["#/x", "#x%2Fy", "#x%2Ey", "#x\\y", "#x\0y"];
|
||||
const fallbackAliases = {
|
||||
"#tab-escape": ["./.\t./outside.cjs", "./config.cjs"],
|
||||
"#newline-escape": ["./.%\n2e/outside.cjs", "./config.cjs"],
|
||||
"#normalized-url": "./con\tfig.cjs",
|
||||
"#trimmed-url": "./config.cjs \t",
|
||||
"#url-suffix": "./config.cjs?selected=one#fragment",
|
||||
"#inactive-array": {
|
||||
node: [{ browser: "./browser.cjs" }],
|
||||
default: "./config.cjs",
|
||||
},
|
||||
"#nested-inactive-array": {
|
||||
node: [[{ browser: "./browser.cjs" }]],
|
||||
default: "./config.cjs",
|
||||
},
|
||||
"#parent": ["../outside.cjs", "./config.cjs"],
|
||||
"#absolute": { node: [["/outside.cjs"], "./config.cjs"] },
|
||||
"#url": {
|
||||
import: ["https://example.invalid/outside.cjs", "./config.cjs"],
|
||||
require: ["file:///outside.cjs", "./config.cjs"],
|
||||
},
|
||||
};
|
||||
const resolvedAliases = [...literalAliases, ...Object.keys(fallbackAliases)];
|
||||
const refusedAliases = {
|
||||
"#empty": {
|
||||
target: [],
|
||||
status: "external",
|
||||
limitation: "an empty imports target array",
|
||||
},
|
||||
"#empty-active": {
|
||||
target: { node: [] },
|
||||
status: "external",
|
||||
limitation: "an empty imports target array",
|
||||
},
|
||||
"#null-last": {
|
||||
target: [[], null],
|
||||
status: "external",
|
||||
limitation: "an explicit null imports target",
|
||||
},
|
||||
"#empty-last": {
|
||||
target: [null, []],
|
||||
status: "external",
|
||||
limitation: "an empty imports target array",
|
||||
},
|
||||
"#inactive": {
|
||||
target: [{ browser: "./browser.cjs" }],
|
||||
status: "external",
|
||||
limitation: "it declares browser.",
|
||||
},
|
||||
"#nested-inactive": {
|
||||
status: "external",
|
||||
target: [
|
||||
[{ browser: "./browser.cjs" }, { "rea-inactive": "./inactive.cjs" }],
|
||||
],
|
||||
limitation: "it declares browser, rea-inactive.",
|
||||
},
|
||||
"#escape": {
|
||||
target: "./.\t./outside.cjs",
|
||||
status: "rejected",
|
||||
limitation: "escapes the package root",
|
||||
},
|
||||
"#encoded-separator": {
|
||||
target: ["./con%2ffig.cjs", "./config.cjs"],
|
||||
status: "rejected",
|
||||
limitation: "separator bytes",
|
||||
},
|
||||
"#missing-url": {
|
||||
target: ["./miss\ting.cjs", "./config.cjs"],
|
||||
status: "not-found",
|
||||
limitation: JSON.stringify("./miss\ting.cjs"),
|
||||
},
|
||||
};
|
||||
const allAliases = [...resolvedAliases, ...Object.keys(refusedAliases)];
|
||||
|
||||
const createPackageImportAliasFixture = async () => {
|
||||
const root = await createTestTempDirectory("rea-package-import-aliases-");
|
||||
const mainSource = [
|
||||
'const config = require("#config");',
|
||||
'const nested = require("./node_modules/fixture/index.cjs");',
|
||||
'const missing = require("#missing");',
|
||||
...allAliases.map((specifier) => `require(${JSON.stringify(specifier)});`),
|
||||
].join("\n");
|
||||
const moduleSource = allAliases
|
||||
.map((specifier) => `import ${JSON.stringify(specifier)};`)
|
||||
.join("\n");
|
||||
const nestedSource = [
|
||||
'const config = require("#config");',
|
||||
"module.exports = config;",
|
||||
].join("\n");
|
||||
const files = {
|
||||
"package.json": JSON.stringify({
|
||||
name: "app",
|
||||
imports: {
|
||||
"#config": "./config.cjs",
|
||||
...Object.fromEntries(
|
||||
literalAliases.map((specifier) => [specifier, "./config.cjs"]),
|
||||
),
|
||||
...fallbackAliases,
|
||||
...Object.fromEntries(
|
||||
Object.entries(refusedAliases).map(([specifier, { target }]) => [
|
||||
specifier,
|
||||
target,
|
||||
]),
|
||||
),
|
||||
},
|
||||
}),
|
||||
"main.cjs": mainSource,
|
||||
"main.mjs": moduleSource,
|
||||
"config.cjs": "module.exports = 'app-config';",
|
||||
"node_modules/fixture/package.json": JSON.stringify({
|
||||
name: "fixture",
|
||||
imports: { "#config": "./local.cjs" },
|
||||
}),
|
||||
"node_modules/fixture/index.cjs": nestedSource,
|
||||
"node_modules/fixture/local.cjs": "module.exports = 'fixture-config';",
|
||||
};
|
||||
await Promise.all(
|
||||
Object.entries(files).map(async ([path, content]) => {
|
||||
const absolute = join(root, path);
|
||||
await mkdir(dirname(absolute), { recursive: true });
|
||||
await writeFile(absolute, content);
|
||||
}),
|
||||
);
|
||||
return { root, mainSource, moduleSource, nestedSource };
|
||||
};
|
||||
|
||||
cliTest.for(["CLI", "stdio MCP"] as const)(
|
||||
"resolves exact package import aliases with package scope through %s",
|
||||
async (surface, { cli }) => {
|
||||
const { root, mainSource, moduleSource, nestedSource } =
|
||||
await createPackageImportAliasFixture();
|
||||
const nativeRequire = createRequire(join(root, "main.cjs"));
|
||||
expect(
|
||||
relative(root, nativeRequire.resolve("#config")).replaceAll("\\", "/"),
|
||||
).toBe("config.cjs");
|
||||
expect(
|
||||
relative(
|
||||
root,
|
||||
createRequire(join(root, "node_modules/fixture/index.cjs")).resolve(
|
||||
"#config",
|
||||
),
|
||||
).replaceAll("\\", "/"),
|
||||
).toBe("node_modules/fixture/local.cjs");
|
||||
expect(() => nativeRequire.resolve("#missing")).toThrow(
|
||||
expect.objectContaining({ code: "ERR_PACKAGE_IMPORT_NOT_DEFINED" }),
|
||||
);
|
||||
|
||||
let document: unknown;
|
||||
if (surface === "CLI") {
|
||||
const response = await cli.run({
|
||||
arguments: ["analyze-javascript-application", root, "--format", "json"],
|
||||
environment: { REA_LOG_LEVEL: "silent" },
|
||||
});
|
||||
expect(response.exitCode, response.stderr).toBe(0);
|
||||
document = response.json;
|
||||
} else {
|
||||
const { call } = await connectLocalToolsMcp();
|
||||
const response = await call("analyze_javascript_application", {
|
||||
input_path: root,
|
||||
format: "directory",
|
||||
});
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
document = response.structuredContent;
|
||||
}
|
||||
const { graph } = z
|
||||
.object({ normalized_result: javascriptApplicationAnalysisResultSchema })
|
||||
.parse(document).normalized_result;
|
||||
for (const specifier of resolvedAliases)
|
||||
for (const [moduleKind, sourcePath, source] of [
|
||||
["require", "main.cjs", mainSource],
|
||||
["import", "main.mjs", moduleSource],
|
||||
] as const)
|
||||
expect(graph.edges).toContainEqual(
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
module_link_kind: moduleKind,
|
||||
specifier,
|
||||
resolved_path: "config.cjs",
|
||||
resolution_status: "resolved",
|
||||
}),
|
||||
evidence: sourceEvidence(sourcePath, source),
|
||||
}),
|
||||
);
|
||||
const imports = graph.edges.filter(
|
||||
({ properties }) => properties.module_link_kind === "require",
|
||||
);
|
||||
for (const [specifier, { status, limitation }] of Object.entries(
|
||||
refusedAliases,
|
||||
))
|
||||
for (const [moduleKind, sourcePath, source] of [
|
||||
["require", "main.cjs", mainSource],
|
||||
["import", "main.mjs", moduleSource],
|
||||
] as const)
|
||||
expect(graph.edges).toContainEqual(
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
module_link_kind: moduleKind,
|
||||
specifier,
|
||||
resolved_path: null,
|
||||
resolution_status: status,
|
||||
}),
|
||||
evidence: sourceEvidence(sourcePath, source, limitation),
|
||||
}),
|
||||
);
|
||||
expect(imports).toContainEqual(
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
specifier: "#config",
|
||||
resolved_path: "config.cjs",
|
||||
resolution_status: "resolved",
|
||||
}),
|
||||
evidence: sourceEvidence("main.cjs", mainSource),
|
||||
}),
|
||||
);
|
||||
expect(imports).toContainEqual(
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
specifier: "#config",
|
||||
resolved_path: "node_modules/fixture/local.cjs",
|
||||
resolution_status: "resolved",
|
||||
}),
|
||||
evidence: sourceEvidence(
|
||||
"node_modules/fixture/index.cjs",
|
||||
nestedSource,
|
||||
),
|
||||
}),
|
||||
);
|
||||
expect(imports).toContainEqual(
|
||||
expect.objectContaining({
|
||||
properties: expect.objectContaining({
|
||||
specifier: "#missing",
|
||||
resolved_path: null,
|
||||
resolution_status: "external",
|
||||
}),
|
||||
evidence: expect.objectContaining({
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringContaining("does not define package import alias"),
|
||||
]),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
const sourceEvidence = (
|
||||
sourcePath: string,
|
||||
source: string,
|
||||
limitation?: string,
|
||||
): unknown =>
|
||||
expect.objectContaining({
|
||||
artifact: expect.objectContaining({
|
||||
available: true,
|
||||
sha256: createHash("sha256").update(source).digest("hex"),
|
||||
}),
|
||||
location: expect.objectContaining({
|
||||
available: true,
|
||||
value: expect.objectContaining({
|
||||
kind: "source-range",
|
||||
source: sourcePath,
|
||||
}),
|
||||
}),
|
||||
...(limitation === undefined
|
||||
? {}
|
||||
: {
|
||||
limitations: expect.arrayContaining([
|
||||
expect.stringContaining(limitation),
|
||||
]),
|
||||
}),
|
||||
});
|
||||
@@ -7,6 +7,72 @@ import { buildManagedPeFixture } from "../../src/dotnet/ManagedPe.fixture.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"managed CLI retains metadata and CIL after repeated local constructor owner lookups",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-managed-row-lookup-");
|
||||
const path = join(root, "local-attributes.dll");
|
||||
await writeFile(
|
||||
path,
|
||||
buildManagedPeFixture({
|
||||
additionalEmptyTypes: 512,
|
||||
customAttributeRowCount: 512,
|
||||
customAttributeTypeRaw: (1 << 3) | 2,
|
||||
typeName: "LookupAttribute",
|
||||
extendsRaw: 0,
|
||||
methodName: ".ctor",
|
||||
methodFlags: 0x1886,
|
||||
methodSignature: Buffer.from([0x20, 0x01, 0x01, 0x0e]),
|
||||
ilBody: Buffer.from([0x06, 0x2a]),
|
||||
}),
|
||||
);
|
||||
const artifact = await cli.run({
|
||||
arguments: ["inspect-managed-artifact", path, "--json"],
|
||||
});
|
||||
expect(artifact.exitCode).toBe(0);
|
||||
expect(artifact.json).toMatchObject({
|
||||
normalized_result: {
|
||||
coverage: { state: "complete", issues: [] },
|
||||
attributes: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
type_name: "Fixture.LookupAttribute",
|
||||
constructor_token: "0x06000001",
|
||||
}),
|
||||
]),
|
||||
},
|
||||
});
|
||||
expect(artifact.json).toHaveProperty(
|
||||
"normalized_result.attributes.length",
|
||||
512,
|
||||
);
|
||||
const members = await cli.run({
|
||||
arguments: ["inspect-managed-members", path, "--json"],
|
||||
});
|
||||
expect(members.exitCode).toBe(0);
|
||||
expect(members.json).toMatchObject({
|
||||
normalized_result: {
|
||||
coverage: { state: "complete", issues: [] },
|
||||
types: expect.arrayContaining([
|
||||
expect.objectContaining({ full_name: "Fixture.Empty0" }),
|
||||
expect.objectContaining({ full_name: "Fixture.Empty511" }),
|
||||
expect.objectContaining({ full_name: "Fixture.LookupAttribute" }),
|
||||
]),
|
||||
methods: [
|
||||
expect.objectContaining({
|
||||
name: ".ctor",
|
||||
declaring_type: "Fixture.LookupAttribute",
|
||||
body: expect.objectContaining({
|
||||
status: "present",
|
||||
instruction_count: 1,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(members.json).toHaveProperty("normalized_result.types.length", 513);
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"managed CLI separates .NET Standard API targets from runtime evidence",
|
||||
async ({ cli }) => {
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { buildManagedMemberPointerFixture } from "../../src/dotnet/ManagedPe.fixture.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"CLI and stdio MCP retain physical member identities through reordered pointers",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-managed-member-pointers-");
|
||||
const path = join(root, "reordered.dll");
|
||||
const bytes = buildManagedMemberPointerFixture();
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
await writeFile(path, bytes);
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [resolve("scripts/rea.mjs"), "mcp"],
|
||||
cwd: process.cwd(),
|
||||
env: { PATH: process.env.PATH ?? "", REA_LOG_LEVEL: "silent" },
|
||||
stderr: "pipe",
|
||||
});
|
||||
transport.stderr?.on("data", () => undefined);
|
||||
const client = new Client({ name: "managed-pointer-parity", version: "1" });
|
||||
try {
|
||||
await client.connect(transport);
|
||||
for (const name of [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_members",
|
||||
] as const) {
|
||||
const cliResult = await cli.run({
|
||||
arguments: [name.replaceAll("_", "-"), path, "--json"],
|
||||
});
|
||||
expect(cliResult.exitCode, cliResult.stderr).toBe(0);
|
||||
const cliEvidence = parseEvidence(cliResult.json);
|
||||
const response = await client.callTool({ name, arguments: { path } });
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
const mcpEvidence = parseEvidence(response.structuredContent);
|
||||
expect(mcpEvidence.normalized_result).toEqual(
|
||||
cliEvidence.normalized_result,
|
||||
);
|
||||
expect(mcpEvidence.subject?.digest.sha256).toBe(sha256);
|
||||
expect(cliEvidence.subject?.digest.sha256).toBe(sha256);
|
||||
expect(mcpEvidence.normalized_result).toMatchObject({
|
||||
coverage: { state: "complete", issues: [] },
|
||||
});
|
||||
if (name === "inspect_managed_artifact") {
|
||||
expect(mcpEvidence.normalized_result).toMatchObject({
|
||||
attributes: [
|
||||
expect.objectContaining({
|
||||
constructor_token: "0x06000001",
|
||||
type_name: "Fixture.B",
|
||||
}),
|
||||
],
|
||||
});
|
||||
} else {
|
||||
expect(mcpEvidence.normalized_result).toMatchObject({
|
||||
fields: [
|
||||
expect.objectContaining({
|
||||
token: "0x04000001",
|
||||
declaring_type: "Fixture.B",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
token: "0x04000002",
|
||||
declaring_type: "Fixture.A",
|
||||
}),
|
||||
],
|
||||
methods: [
|
||||
expect.objectContaining({
|
||||
token: "0x06000001",
|
||||
declaring_type: "Fixture.B",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
token: "0x06000002",
|
||||
declaring_type: "Fixture.A",
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
await client.close();
|
||||
} finally {
|
||||
await transport.close();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,84 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { parseEvidence } from "../../src/domain/evidence.js";
|
||||
import { buildManagedPeFixture } from "../../src/dotnet/ManagedPe.fixture.js";
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"CLI and stdio MCP inspect CLR ExtraData metadata without shifting table identities",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-managed-extra-data-");
|
||||
const path = join(root, "extra-data.dll");
|
||||
const bytes = buildManagedPeFixture({ metadataExtraData: 0x1234_5678 });
|
||||
const sha256 = createHash("sha256").update(bytes).digest("hex");
|
||||
await writeFile(path, bytes);
|
||||
const transport = new StdioClientTransport({
|
||||
command: process.execPath,
|
||||
args: [resolve("scripts/rea.mjs"), "mcp"],
|
||||
cwd: process.cwd(),
|
||||
env: { PATH: process.env.PATH ?? "", REA_LOG_LEVEL: "silent" },
|
||||
stderr: "pipe",
|
||||
});
|
||||
transport.stderr?.on("data", () => undefined);
|
||||
const client = new Client({
|
||||
name: "managed-extra-data-parity",
|
||||
version: "1",
|
||||
});
|
||||
try {
|
||||
await client.connect(transport);
|
||||
for (const name of [
|
||||
"inspect_managed_artifact",
|
||||
"inspect_managed_members",
|
||||
] as const) {
|
||||
const cliResult = await cli.run({
|
||||
arguments: [name.replaceAll("_", "-"), path, "--json"],
|
||||
});
|
||||
expect(cliResult.exitCode, cliResult.stderr).toBe(0);
|
||||
const cliEvidence = parseEvidence(cliResult.json);
|
||||
const response = await client.callTool({ name, arguments: { path } });
|
||||
expect(response.isError, JSON.stringify(response)).not.toBe(true);
|
||||
const mcpEvidence = parseEvidence(response.structuredContent);
|
||||
expect(mcpEvidence.normalized_result).toEqual(
|
||||
cliEvidence.normalized_result,
|
||||
);
|
||||
expect(mcpEvidence.subject?.digest.sha256).toBe(sha256);
|
||||
expect(cliEvidence.subject?.digest.sha256).toBe(sha256);
|
||||
expect(mcpEvidence.normalized_result).toMatchObject({
|
||||
module: {
|
||||
name: "Fixture.dll",
|
||||
mvid: "00112233-4455-6677-8899-aabbccddeeff",
|
||||
},
|
||||
coverage: { state: "complete", issues: [] },
|
||||
});
|
||||
if (name === "inspect_managed_artifact") {
|
||||
expect(mcpEvidence.normalized_result).toMatchObject({
|
||||
assembly: { name: "Fixture.Managed" },
|
||||
});
|
||||
} else {
|
||||
expect(mcpEvidence.normalized_result).toMatchObject({
|
||||
types: [expect.objectContaining({ full_name: "Fixture.Program" })],
|
||||
methods: [
|
||||
expect.objectContaining({
|
||||
token: "0x06000001",
|
||||
name: "Main",
|
||||
declaring_type: "Fixture.Program",
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
await client.close();
|
||||
} finally {
|
||||
await transport.close();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,156 @@
|
||||
import { access, readFile, readdir, writeFile } from "node:fs/promises";
|
||||
import { join, relative, resolve } from "node:path";
|
||||
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
cliTest(
|
||||
"skill-only setup verifies its selected client copy on install, rerun and repair",
|
||||
async ({ cli }) => {
|
||||
const directory = await createTestTempDirectory("rea-selected-skill-");
|
||||
const selected = join(
|
||||
directory,
|
||||
".claude/skills/reverse-engineer-anything",
|
||||
);
|
||||
const shared = join(directory, ".agents/skills/reverse-engineer-anything");
|
||||
const run = (args: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: [...args, "--json"],
|
||||
cwd: directory,
|
||||
environment: { USERPROFILE: directory },
|
||||
});
|
||||
const preview = await run([
|
||||
"setup",
|
||||
"--skill-client",
|
||||
"claude_code",
|
||||
"--dry-run",
|
||||
]);
|
||||
expect(preview.exitCode, preview.stdout).toBe(0);
|
||||
expect(preview.json).toMatchObject({
|
||||
status: "planned",
|
||||
doctor: {
|
||||
scope: {
|
||||
clients: [],
|
||||
skill: true,
|
||||
skill_clients: ["claude_code"],
|
||||
},
|
||||
},
|
||||
});
|
||||
const registered = await run([
|
||||
"setup",
|
||||
"--client",
|
||||
"claude_code",
|
||||
"--skill=false",
|
||||
"--yes",
|
||||
]);
|
||||
expect(registered.exitCode, registered.stderr).toBe(0);
|
||||
const configuration = join(directory, ".claude.json");
|
||||
const before = await readFile(configuration, "utf8");
|
||||
const args = ["setup", "--skill-client", "claude_code", "--yes"];
|
||||
const installed = await run(args);
|
||||
expect(installed.exitCode, installed.stdout).toBe(0);
|
||||
expect(installed.json).toMatchObject({
|
||||
status: "ready",
|
||||
appliedActions: ["installed_skill"],
|
||||
doctor: {
|
||||
healthy: true,
|
||||
scope: { clients: [], skill: true, skill_clients: ["claude_code"] },
|
||||
identity: { skill: { state: "aligned" } },
|
||||
},
|
||||
});
|
||||
const bundle = resolve("skills/reverse-engineer-anything");
|
||||
const assertAligned = async () => {
|
||||
for (const entry of await readdir(bundle, {
|
||||
recursive: true,
|
||||
withFileTypes: true,
|
||||
})) {
|
||||
if (!entry.isFile()) continue;
|
||||
const path = relative(bundle, join(entry.parentPath, entry.name));
|
||||
expect(await readFile(join(selected, path))).toEqual(
|
||||
await readFile(join(bundle, path)),
|
||||
);
|
||||
}
|
||||
};
|
||||
await assertAligned();
|
||||
const repeated = await run(args);
|
||||
expect(repeated.exitCode, repeated.stdout).toBe(0);
|
||||
expect(repeated.json).toMatchObject({
|
||||
status: "ready",
|
||||
appliedActions: [],
|
||||
});
|
||||
|
||||
await writeFile(
|
||||
join(selected, "references/native-and-artifacts.md"),
|
||||
"damaged selected copy\n",
|
||||
);
|
||||
const damaged = await run(["doctor", "--client", "claude_code", "--skill"]);
|
||||
expect(damaged.json).toMatchObject({
|
||||
healthy: false,
|
||||
identity: { skill: { state: "stale" } },
|
||||
});
|
||||
const repaired = await run(args);
|
||||
expect(repaired.exitCode, repaired.stdout).toBe(0);
|
||||
expect(repaired.json).toMatchObject({
|
||||
status: "ready",
|
||||
appliedActions: ["installed_skill"],
|
||||
});
|
||||
await assertAligned();
|
||||
await expect(access(shared)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
expect(await readFile(configuration, "utf8")).toBe(before);
|
||||
|
||||
const sharedControl = await run([
|
||||
"setup",
|
||||
"--skill-client",
|
||||
"shared",
|
||||
"--yes",
|
||||
]);
|
||||
expect(sharedControl.exitCode, sharedControl.stdout).toBe(0);
|
||||
expect(sharedControl.json).toMatchObject({ status: "ready" });
|
||||
await access(join(shared, "SKILL.md"));
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"setup keeps registration and skill readiness selections independent",
|
||||
async ({ cli }) => {
|
||||
const directory = await createTestTempDirectory("rea-independent-skill-");
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"setup",
|
||||
"--client",
|
||||
"codex",
|
||||
"--skill-client",
|
||||
"claude_code",
|
||||
"--yes",
|
||||
"--json",
|
||||
],
|
||||
cwd: directory,
|
||||
environment: { USERPROFILE: directory },
|
||||
});
|
||||
expect(result.exitCode, result.stdout).toBe(0);
|
||||
expect(result.json).toMatchObject({
|
||||
status: "ready",
|
||||
doctor: {
|
||||
healthy: true,
|
||||
scope: {
|
||||
clients: ["codex"],
|
||||
skill_clients: ["claude_code"],
|
||||
skill: true,
|
||||
},
|
||||
identity: { skill: { state: "aligned" } },
|
||||
},
|
||||
});
|
||||
await access(join(directory, ".codex/config.toml"));
|
||||
await access(
|
||||
join(directory, ".claude/skills/reverse-engineer-anything/SKILL.md"),
|
||||
);
|
||||
await expect(access(join(directory, ".claude.json"))).rejects.toMatchObject(
|
||||
{ code: "ENOENT" },
|
||||
);
|
||||
await expect(
|
||||
access(join(directory, ".agents/skills/reverse-engineer-anything")),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user