mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
* fix(mcp): paginate tools/list under the FastMCP SSE limit Unsloth's FastMCP client rejects the single tools/list event because the full 241-tool catalog serializes to about 4.2 MB, over its 1 MiB SSE cap, so every refresh fails. The MCP SDK returns the whole catalog with no nextCursor, and the server never handled the cursor at all. Page oversized listings at the transport seam, per the MCP cursor contract: pages stay under 896 KiB, cursors are bound to the catalog snapshot, and catalogs that fit are returned in one response as before. * fix(mcp): track pending tools/list requests in one map pendingToolListCursors already held every tools/list id, including requests without a cursor. Membership, cancellation, and cleanup now use that map. Cursor rejection tests assert JSON-RPC -32602, then a cursorless listing returns the complete current catalog. * fix(mcp): count one schema discovery per tools/list pagination The paged tools/list turns one logical discovery into several wire requests, which broke the artifact verifier probe's per-request counting and its duplicate injection assumed the target tool on the first page. Count one discovery per listTools call and inject the duplicate only on the page carrying the tool. * fix(mcp): bind tools/list cursors to full tool definitions A cursor digest now covers each advertised tool, so a schema change invalidates it. One tool larger than REA_MCP_TOOLS_LIST_PAGE_BYTES fails with a resource_constraint error instead of a successful page. * test(doctor): keep the configuration table within its line limit The page-budget refusal stays covered by the setting parser tests. * fix(mcp): honor the tools/list page budget on the stdio path and register the setting Register REA_MCP_TOOLS_LIST_PAGE_BYTES in the numeric limit registry and the limit inventory so the numeric limit check passes. Carry the parsed page budget from AppConfig into DeferredEvidenceMcpServer so the default stdio startup path honors the setting instead of always using the 917504-byte default. Harden the page budget parser tests to surface the parse error instead of returning early on failure. * fix(mcp): return a fitting final tools/list page and use the parsed page budget verifiedPage returns the remaining tools as one final page without a cursor when they fit, instead of failing a resumed listing whose first tool plus a cursor exceeds the budget. parseConfig builds the page budget from parseEnvironment's admitted number instead of re-parsing the raw environment, and the now-unused resolveMcpToolsListPageBudget helper is removed. * fix(mcp): use shared isRecord in tools/list pagination Static checks flagged the local record predicate in toolListPagination.ts: import the shared isRecord from src/domain/isRecord.ts instead. The numeric-limit registry test still expected 15 entries after the REA_MCP_TOOLS_LIST_PAGE_BYTES entry was added; bump it to 16. * test(mcp): page tools/list fixtures under explicit small budgets The compact-only presentation strips field descriptions before advertising, so the 80-tool catalog fits one page and the oversized tool fits too. Set explicit small page budgets against the advertised size. The parseConfig success test now throws the typed error before reading the value, per the test guide. * test(config): throw typed parse errors in tools/list budget test Greptile P2 on #9142: the budget test checked the selected parse via an inline toMatchObject on the Result, hiding the typed error on failure. Bind both parse results and throw their errors before asserting values, per the repo test guide. * fix(mcp): format tools/list pagination test to repo style oxfmt --check flagged src/server/toolListPagination.test.ts (the cursor-identity expectation was written expanded; oxfmt collapses the two-element array onto one line). No behavior change. * style(mcp): oxfmt the page-budget assertion The Greptile P2 fix re-wrapped the expect call past oxfmt's width; run the pinned formatter so Static checks stays green. * fix(mcp): use the shared sha256Hex helper for the tools/list catalog digest The architecture guards forbid a second one-shot SHA-256 hex digest; use the shared helper from src/kernel/sha256Hex instead. * fix(mcp): build the tools/list page-budget refusal through the shared owner helper The architecture guard counts hand-built AnalysisResourceConstraintError constructions; toolsListPageBudgetError() held the only new copy. The refusal cause is a page budget, not a parse limit, so parseLimitConstraint does not fit. Add toolsListPageBudgetConstraint() beside it in parseFailureAnalysisError.ts and build the refusal from the page-budget facts there; the produced error is unchanged. Also give the pagination test SDK client the shared schema validator from createMcpSchemaValidation, released with the client. * fix(server): adapt instructions call to the predicate API Main changed serverInstructions to take an advertisesTool predicate instead of a tool-family set, and RecordedMcpCatalog gained required toolFamilies and promptRequirements fields. The merge head no longer typechecked, failing Build package, Documentation and Static checks. Adapt the call site to main's own adapter shape and add the two empty fixture fields. * fix(mcp): restore main's tool-family scope in deferred startup The merge dropped the family scoping main added to the deferred startup path. A scoped stdio start advertised every recorded tool and saved the full catalog identity, so attachRuntime rejected the selected identity on first use. Restore the toolFamilies option, scoped capabilities/instructions/identity, and the shared helper through runDeferred and the deferred constructor. * fix(mcp): share page limit facts and stream catalog sizing --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
686 lines
22 KiB
TypeScript
686 lines
22 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { launchAnalysisSetting } from "./config/analysisSettings.js";
|
|
import { runtimeAnalysisConfig } from "./config/runtimeAnalysisSettings.js";
|
|
import { runWithAnalysisOperationSnapshot } from "./domain/analysisOperationSnapshot.js";
|
|
import { DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS } from "./domain/analysisResourceLimits.js";
|
|
import { ConfigurationError } from "./domain/configurationErrors.js";
|
|
import {
|
|
inspectNativeAnalysisConfiguration,
|
|
parseConfig,
|
|
} from "./config/parseConfig.js";
|
|
import {
|
|
parseEnvironmentValues,
|
|
parseJebMcpTimeoutMs,
|
|
} from "./config/environment.js";
|
|
import { projectAnalysisError } from "./domain/analysisErrorProjection.js";
|
|
|
|
it("still rejects a NUL in an unresolved expression", () => {
|
|
const result = parseEnvironmentValues(
|
|
{ REA_GHIDRA_STARTUP_TIMEOUT_MS: "${TIMEOUT}\0private" },
|
|
new Set(["REA_GHIDRA_STARTUP_TIMEOUT_MS"]),
|
|
);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) expect(JSON.stringify(result.error)).not.toContain("private");
|
|
});
|
|
|
|
it("refuses an unsafe ASAR listing launch value at registration", () => {
|
|
const setting = "REA_ASAR_MAX_LISTING_BYTES";
|
|
const environment = { [setting]: "9007199254740992" };
|
|
expect(
|
|
launchAnalysisSetting("asar.max_listing_bytes", environment),
|
|
).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "ConfigurationError",
|
|
settings: [expect.objectContaining({ setting })],
|
|
},
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
"ghidra.value_flow_max_operations",
|
|
"REA_GHIDRA_VALUE_FLOW_MAX_OPERATIONS",
|
|
"0",
|
|
],
|
|
[
|
|
"ghidra.value_flow_max_inputs_per_operation",
|
|
"REA_GHIDRA_VALUE_FLOW_MAX_INPUTS_PER_OPERATION",
|
|
"2147483648",
|
|
],
|
|
["ghidra.value_flow_max_edges", "REA_GHIDRA_VALUE_FLOW_MAX_EDGES", "1.5"],
|
|
[
|
|
"ghidra.decompile_max_payload_mib",
|
|
"REA_GHIDRA_DECOMPILE_MAX_PAYLOAD_MIB",
|
|
"2048",
|
|
],
|
|
] as const)(
|
|
"defers invalid %s until the operation reads it",
|
|
(id, setting, value) => {
|
|
const parsed = parseConfig({ [setting]: value });
|
|
if (!parsed.ok) throw new Error("runtime seed rejected startup");
|
|
const boundary = launchAnalysisSetting(id, { [setting]: value });
|
|
if (boundary.ok) throw new Error("invalid runtime seed was admitted");
|
|
expect(boundary.error.settings).toContainEqual(
|
|
expect.objectContaining({ setting }),
|
|
);
|
|
const live = runtimeAnalysisConfig(parsed.value);
|
|
const read = (): unknown => {
|
|
if (id === "ghidra.value_flow_max_operations")
|
|
return live.ghidraValueFlowMaxOperations;
|
|
if (id === "ghidra.value_flow_max_inputs_per_operation")
|
|
return live.ghidraValueFlowMaxInputsPerOperation;
|
|
if (id === "ghidra.value_flow_max_edges")
|
|
return live.ghidraValueFlowMaxEdges;
|
|
return live.ghidraDecompileMaxPayloadMiB;
|
|
};
|
|
expect(read).toThrow(ConfigurationError);
|
|
},
|
|
);
|
|
|
|
it("keeps the caller's opt-in Ghidra checkpoint directory and leaves it disabled by default", () => {
|
|
const selected = parseConfig({
|
|
REA_GHIDRA_CHECKPOINT_DIR: "/tmp/checkpoints with spaces",
|
|
});
|
|
expect(selected.ok && selected.value.ghidraCheckpointDirectory).toBe(
|
|
"/tmp/checkpoints with spaces",
|
|
);
|
|
const defaults = parseConfig({});
|
|
expect(
|
|
defaults.ok && defaults.value.ghidraCheckpointDirectory,
|
|
).toBeUndefined();
|
|
expect(parseConfig({ REA_GHIDRA_CHECKPOINT_DIR: "relative" }).ok).toBe(false);
|
|
});
|
|
|
|
it.each([
|
|
["REA_GHIDRA_PROJECT_PATH", "/tmp/selected.gpr"],
|
|
["REA_GHIDRA_SEED_FILE", "/tmp/seeds.json"],
|
|
["REA_GHIDRA_LANGUAGE_ID", "x86:LE:64:default"],
|
|
["REA_GHIDRA_NATIVEAOT_JAR", "/tmp/extension.jar"],
|
|
["REA_GHIDRA_DISABLED_ANALYZERS", "Stack"],
|
|
])(
|
|
"refuses %s with checkpoints rather than silently dropping the selected input",
|
|
(setting, value) => {
|
|
const result = parseConfig({
|
|
REA_GHIDRA_CHECKPOINT_DIR: "/tmp/checkpoints",
|
|
[setting]: value,
|
|
});
|
|
if (result.ok) throw new Error("conflicting inputs accepted");
|
|
expect(result.error.message).toContain("checkpoints");
|
|
expect(result.error).toMatchObject({
|
|
settings: [expect.objectContaining({ setting })],
|
|
});
|
|
},
|
|
);
|
|
|
|
it("reports a configuration failure for a NUL in Hopper loader arguments", () => {
|
|
const result = parseConfig({
|
|
HOPPER_LOADER_ARGS_JSON: JSON.stringify(["--option", "value\0suffix"]),
|
|
});
|
|
if (result.ok)
|
|
throw new Error("NUL argv cannot be passed to a child process");
|
|
expect(result.error).toMatchObject({
|
|
settings: [{ setting: "HOPPER_LOADER_ARGS_JSON" }],
|
|
});
|
|
expect(result.error.message).toContain("NUL");
|
|
});
|
|
|
|
it.each([
|
|
["unknown value", { CALLER_SETTING: "private\0value" }],
|
|
["unknown name", { ["CALLER\0SETTING"]: "private value" }],
|
|
["known path", { HOPPER_TARGET_PATH: "private\0path" }],
|
|
] as const)(
|
|
"rejects a NUL in an environment %s without exposing its value",
|
|
(_name, environment) => {
|
|
for (const result of [
|
|
parseEnvironmentValues(environment),
|
|
parseConfig(environment),
|
|
]) {
|
|
if (result.ok) throw new Error("Expected invalid environment");
|
|
expect(result.error.settings).toHaveLength(1);
|
|
expect(result.error.settings[0]?.constraint).toContain("NUL");
|
|
expect(JSON.stringify(projectAnalysisError(result.error))).not.toContain(
|
|
"private",
|
|
);
|
|
}
|
|
},
|
|
);
|
|
|
|
it("accepts ordinary custom environment strings and omitted values", () => {
|
|
expect(
|
|
parseEnvironmentValues({
|
|
CALLER_SETTING: "\nvalue=one;二\t",
|
|
EMPTY_SETTING: "",
|
|
OMITTED_SETTING: undefined,
|
|
}).ok,
|
|
).toBe(true);
|
|
});
|
|
|
|
describe("runtime configuration", () => {
|
|
it("preserves a selected MCP input allowance for deferred startup and refuses disabling values", () => {
|
|
expect(parseConfig({ REA_MCP_MAX_INPUT_ELEMENTS: "8192" })).toMatchObject({
|
|
ok: true,
|
|
value: { mcpMaxInputElements: 8192 },
|
|
});
|
|
const invalid = parseConfig({ REA_MCP_MAX_INPUT_ELEMENTS: "Infinity" });
|
|
expect(invalid.ok).toBe(false);
|
|
if (invalid.ok)
|
|
throw new Error(
|
|
"Infinite MCP input allowance must not be accepted from the environment",
|
|
);
|
|
expect(invalid.error.settings).toEqual([
|
|
{
|
|
setting: "REA_MCP_MAX_INPUT_ELEMENTS",
|
|
constraint: expect.stringContaining("positive decimal safe integer"),
|
|
},
|
|
]);
|
|
});
|
|
it("preserves a selected tools/list page budget for deferred startup", () => {
|
|
const selected = parseConfig({ REA_MCP_TOOLS_LIST_PAGE_BYTES: "524288" });
|
|
if (!selected.ok) throw selected.error;
|
|
expect(selected.value.mcpToolsListPageBudget).toMatchObject({
|
|
setting: "REA_MCP_TOOLS_LIST_PAGE_BYTES",
|
|
bytes: 524288,
|
|
source: "setting",
|
|
});
|
|
const empty = parseConfig({});
|
|
if (!empty.ok) throw empty.error;
|
|
expect(empty.value.mcpToolsListPageBudget).toBeUndefined();
|
|
});
|
|
it("allows target-free startup and applies runtime defaults", () => {
|
|
const empty = parseConfig({});
|
|
expect(empty.ok).toBe(true);
|
|
if (empty.ok) {
|
|
expect(empty.value.hopperTargetPath).toBeUndefined();
|
|
expect(empty.value.analysisProvider).toBe("auto");
|
|
expect(empty.value.hopperStartupTimeoutMs).toBe(120_000);
|
|
expect(empty.value.hopperStartupTimeoutSource).toBe("default");
|
|
}
|
|
const hopperTimeout = parseConfig({
|
|
REA_HOPPER_STARTUP_TIMEOUT_MS: "45000",
|
|
});
|
|
expect(hopperTimeout).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
hopperStartupTimeoutMs: 45_000,
|
|
hopperStartupTimeoutSource: "setting",
|
|
},
|
|
});
|
|
const result = parseConfig({ HOPPER_TARGET_PATH: "/usr/bin/true" });
|
|
expect(result.ok).toBe(true);
|
|
if (result.ok) {
|
|
expect(result.value.hopperTargetKind).toBe("executable");
|
|
expect(result.value.hopperLoaderArgs).toEqual([]);
|
|
expect(result.value.logLevel).toBe("info");
|
|
expect(result.value.referenceSourcePolicy).toEqual({
|
|
secretPatterns: [],
|
|
});
|
|
}
|
|
});
|
|
|
|
it("parses one shared provider selector and rejects unstable IDs", () => {
|
|
expect(
|
|
parseConfig({
|
|
REA_ANALYSIS_PROVIDER: "ida",
|
|
REA_IDA_MCP_CONFIG: "/tmp/ida-mcp.json",
|
|
}),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: { analysisProvider: "ida", idaMcpConfigPath: "/tmp/ida-mcp.json" },
|
|
});
|
|
expect(parseConfig({ REA_IDA_MCP_CONFIG: "relative.json" }).ok).toBe(false);
|
|
expect(parseConfig({ REA_ANALYSIS_PROVIDER: "ghidra" })).toMatchObject({
|
|
ok: true,
|
|
value: { analysisProvider: "ghidra" },
|
|
});
|
|
expect(parseConfig({ REA_ANALYSIS_PROVIDER: "auto" })).toMatchObject({
|
|
ok: true,
|
|
value: { analysisProvider: "auto" },
|
|
});
|
|
for (const invalid of ["", "Auto", "ghidra_1", "ghidra "])
|
|
expect(parseConfig({ REA_ANALYSIS_PROVIDER: invalid }).ok).toBe(false);
|
|
});
|
|
|
|
it("parses absolute BYO Ghidra and optional Java paths", () => {
|
|
expect(
|
|
parseConfig({
|
|
GHIDRA_INSTALL_DIR: "/opt/ghidra_12.1.4_PUBLIC",
|
|
JAVA_HOME: "/usr/lib/jvm/jdk-21",
|
|
}),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
ghidraInstallDir: "/opt/ghidra_12.1.4_PUBLIC",
|
|
ghidraJavaHome: "/usr/lib/jvm/jdk-21",
|
|
},
|
|
});
|
|
expect(parseConfig({ GHIDRA_INSTALL_DIR: "relative/ghidra" }).ok).toBe(
|
|
false,
|
|
);
|
|
expect(parseConfig({ JAVA_HOME: "relative/jdk" }).ok).toBe(false);
|
|
});
|
|
|
|
it("parses an optional absolute BYO ilspycmd path", () => {
|
|
expect(
|
|
parseConfig({ REA_ILSPY_CMD_PATH: "/home/user/.dotnet/tools/ilspycmd" }),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
ilspyCmdPath: "/home/user/.dotnet/tools/ilspycmd",
|
|
},
|
|
});
|
|
expect(parseConfig({ REA_ILSPY_CMD_PATH: "relative/ilspycmd" }).ok).toBe(
|
|
false,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("native configuration diagnostics", () => {
|
|
it("reports invalid native launch seeds while ignoring the JEB-only timeout", () => {
|
|
expect(inspectNativeAnalysisConfiguration({})).toEqual({ issues: [] });
|
|
expect(
|
|
inspectNativeAnalysisConfiguration({ REA_JEB_MCP_TIMEOUT_MS: "abc" }),
|
|
).toEqual({ issues: [] });
|
|
expect(parseConfig({ REA_JEB_MCP_TIMEOUT_MS: "abc" }).ok).toBe(true);
|
|
const rejected = inspectNativeAnalysisConfiguration({
|
|
REA_ANALYSIS_PROVIDER: "Hopper",
|
|
REA_GHIDRA_STARTUP_TIMEOUT_MS: "abc",
|
|
});
|
|
expect(rejected.issues.map(({ setting }) => setting)).toEqual([
|
|
"REA_ANALYSIS_PROVIDER",
|
|
"REA_GHIDRA_STARTUP_TIMEOUT_MS",
|
|
]);
|
|
expect(
|
|
parseConfig({
|
|
REA_ANALYSIS_PROVIDER: "Hopper",
|
|
REA_GHIDRA_STARTUP_TIMEOUT_MS: "abc",
|
|
}).ok,
|
|
).toBe(false);
|
|
});
|
|
|
|
it("preserves the timeout's schema cause when aggregate admission stops at NUL", () => {
|
|
const inspected = inspectNativeAnalysisConfiguration({
|
|
CALLER_SETTING: "private\0value",
|
|
REA_HOPPER_STARTUP_TIMEOUT_MS: "0",
|
|
});
|
|
expect(inspected.issues).toEqual([
|
|
{
|
|
setting: "CALLER_SETTING",
|
|
constraint:
|
|
"Environment variable names and values must not contain NUL bytes",
|
|
},
|
|
{
|
|
setting: "REA_HOPPER_STARTUP_TIMEOUT_MS",
|
|
constraint: "Expected an integer from 1 to 2147483647 ms",
|
|
},
|
|
]);
|
|
const timeout = inspected.configuredHopperStartupTimeout;
|
|
if (timeout === undefined || timeout.ok)
|
|
throw new Error("Expected the configured timeout's independent refusal");
|
|
expect(timeout.error.cause).toMatchObject({
|
|
name: "ZodError",
|
|
issues: [{ message: "must be a positive decimal integer" }],
|
|
});
|
|
expect(timeout.error.settings).toEqual([
|
|
{
|
|
setting: "REA_HOPPER_STARTUP_TIMEOUT_MS",
|
|
constraint: "must be a positive decimal integer",
|
|
},
|
|
]);
|
|
});
|
|
});
|
|
|
|
describe("runtime target configuration", () => {
|
|
it("rejects invalid target kinds with actionable environment diagnostics", () => {
|
|
const result = parseConfig({ HOPPER_TARGET_KIND: "archive" });
|
|
if (result.ok) throw new Error("Expected invalid target kind");
|
|
expect(result.error.message).toContain("Invalid REA environment");
|
|
});
|
|
|
|
it("parses database kind and loader arguments", () => {
|
|
expect(
|
|
parseConfig({
|
|
HOPPER_LAUNCHER_PATH: "/custom/hopper",
|
|
REA_ANALYSIS_PROVIDER: "hopper",
|
|
HOPPER_TARGET_PATH: "/fixture/sample.hop",
|
|
HOPPER_TARGET_KIND: "database",
|
|
HOPPER_LOADER_ARGS_JSON: '["-l","FAT","--aarch64","-l","Mach-O"]',
|
|
}),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
hopperLauncherPath: "/custom/hopper",
|
|
analysisProvider: "hopper",
|
|
hopperTargetPath: "/fixture/sample.hop",
|
|
hopperTargetKind: "database",
|
|
hopperLoaderArgs: ["-l", "FAT", "--aarch64", "-l", "Mach-O"],
|
|
logLevel: "info",
|
|
referenceSourcePolicy: {
|
|
secretPatterns: [],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("runtime collection configuration", () => {
|
|
it("preserves empty loader arguments and rejects empty exclusion patterns", () => {
|
|
expect(
|
|
parseConfig({ HOPPER_LOADER_ARGS_JSON: '["", " ", "--option"]' }),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: { hopperLoaderArgs: ["", " ", "--option"] },
|
|
});
|
|
expect(parseConfig({ REA_REFERENCE_SECRET_PATTERNS_JSON: '[""]' }).ok).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it.each(["not-json", "{}", '"just a string"', '["ok",1]'])(
|
|
"rejects invalid loader args: %s",
|
|
(encoded) => {
|
|
const result = parseConfig({
|
|
HOPPER_TARGET_PATH: "/tmp/a",
|
|
HOPPER_LOADER_ARGS_JSON: encoded,
|
|
});
|
|
if (result.ok)
|
|
throw new Error("expected malformed loader arguments to fail");
|
|
expect(result.error.message).toContain(
|
|
encoded === "not-json" ? "valid JSON" : "array of strings",
|
|
);
|
|
},
|
|
);
|
|
|
|
it("parses supported log levels and rejects unknown levels", () => {
|
|
const configured = parseConfig({ REA_LOG_LEVEL: "debug" });
|
|
expect(configured.ok && configured.value.logLevel).toBe("debug");
|
|
expect(parseConfig({ REA_LOG_LEVEL: "verbose" }).ok).toBe(false);
|
|
});
|
|
|
|
it("parses reference source secret patterns", () => {
|
|
const result = parseConfig({
|
|
REA_REFERENCE_SECRET_PATTERNS_JSON: '["*.env", "*.pem", "secrets/"]',
|
|
});
|
|
expect(result.ok).toBe(true);
|
|
if (result.ok) {
|
|
expect(result.value.referenceSourcePolicy).toEqual({
|
|
secretPatterns: ["*.env", "*.pem", "secrets/"],
|
|
});
|
|
}
|
|
});
|
|
|
|
it.each(["not-json", "{}", '["*.ok", 1]'])(
|
|
"rejects invalid reference source secret patterns: %s",
|
|
(encoded) => {
|
|
expect(
|
|
parseConfig({ REA_REFERENCE_SECRET_PATTERNS_JSON: encoded }).ok,
|
|
).toBe(false);
|
|
},
|
|
);
|
|
});
|
|
|
|
const expectInvalidStartupSeed = (
|
|
setting: "REA_HOPPER_STARTUP_TIMEOUT_MS" | "REA_GHIDRA_STARTUP_TIMEOUT_MS",
|
|
id: "hopper.startup_timeout_ms" | "ghidra.startup_timeout_ms",
|
|
value: string,
|
|
read: (config: ReturnType<typeof runtimeAnalysisConfig>) => number,
|
|
): void => {
|
|
const result = parseConfig({ [setting]: value });
|
|
if (!result.ok) throw new Error("runtime seed rejected startup");
|
|
const live = runtimeAnalysisConfig(result.value);
|
|
expect(() => read(live)).toThrow(ConfigurationError);
|
|
const boundary = launchAnalysisSetting(id, { [setting]: value });
|
|
if (boundary.ok) throw new Error("invalid startup seed was admitted");
|
|
};
|
|
|
|
describe("configuration failure diagnostics", () => {
|
|
it.each(["1", "900000", "2147483647"])(
|
|
"accepts Hopper startup deadline %s without changing Ghidra's deadline",
|
|
(value) => {
|
|
expect(
|
|
parseConfig({ REA_HOPPER_STARTUP_TIMEOUT_MS: value }),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
hopperStartupTimeoutMs: Number(value),
|
|
ghidraStartupTimeoutMs: DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS,
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
it.each(["", "0", "-1", "1.5", "1e3", "invalid", "2147483648"])(
|
|
"defers a malformed Hopper startup deadline %j until the operation reads it",
|
|
(value) => {
|
|
expectInvalidStartupSeed(
|
|
"REA_HOPPER_STARTUP_TIMEOUT_MS",
|
|
"hopper.startup_timeout_ms",
|
|
value,
|
|
(live) => live.hopperStartupTimeoutMs,
|
|
);
|
|
const parsed = parseConfig({ REA_HOPPER_STARTUP_TIMEOUT_MS: value });
|
|
if (!parsed.ok) throw parsed.error;
|
|
const live = runtimeAnalysisConfig(parsed.value);
|
|
expect(
|
|
runWithAnalysisOperationSnapshot(
|
|
{
|
|
revision: 1,
|
|
overrides: { "hopper.startup_timeout_ms": 8000 },
|
|
},
|
|
() => live.hopperStartupTimeoutMs,
|
|
),
|
|
).toBe(8000);
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
"",
|
|
" ",
|
|
"0",
|
|
"-5",
|
|
"abc",
|
|
"1.5",
|
|
"1e3",
|
|
"0x100",
|
|
"2147483648",
|
|
"9007199254740991",
|
|
])(
|
|
"rejects malformed Ghidra startup deadline %j with its setting and constraint",
|
|
(value) => {
|
|
expectInvalidStartupSeed(
|
|
"REA_GHIDRA_STARTUP_TIMEOUT_MS",
|
|
"ghidra.startup_timeout_ms",
|
|
value,
|
|
(live) => live.ghidraStartupTimeoutMs,
|
|
);
|
|
},
|
|
);
|
|
|
|
it.each(["1", "90000", "2147483647"])(
|
|
"accepts Swift compile deadline %s without changing Hopper's deadline",
|
|
(value) => {
|
|
expect(
|
|
parseEnvironmentValues({ REA_SWIFTC_COMPILE_TIMEOUT_MS: value }),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: { REA_SWIFTC_COMPILE_TIMEOUT_MS: Number(value) },
|
|
});
|
|
expect(
|
|
parseConfig({ REA_SWIFTC_COMPILE_TIMEOUT_MS: value }),
|
|
).toMatchObject({
|
|
ok: true,
|
|
value: {
|
|
hopperStartupTimeoutMs: 120_000,
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
it.each(["", "0", "-1", "1.5", "1e3", "invalid", "2147483648"])(
|
|
"rejects malformed Swift compile deadline %j with its setting",
|
|
(value) => {
|
|
const result = parseConfig({ REA_SWIFTC_COMPILE_TIMEOUT_MS: value });
|
|
if (result.ok) throw new Error("Expected invalid Swift compile deadline");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
code: "configuration_invalid",
|
|
category: "invalid_input",
|
|
details: {
|
|
settings: [
|
|
{
|
|
setting: "REA_SWIFTC_COMPILE_TIMEOUT_MS",
|
|
constraint: expect.any(String),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
},
|
|
);
|
|
|
|
it.each([
|
|
["GHIDRA_INSTALL_DIR", "./fixture"],
|
|
["JAVA_HOME", "./jdk"],
|
|
["REA_GHIDRA_NATIVEAOT_JAR", "./missing.jar"],
|
|
])(
|
|
"names the rejected %s and its absolute-path constraint",
|
|
(setting, value) => {
|
|
const result = parseConfig({ [setting]: value });
|
|
expect(result.ok).toBe(false);
|
|
if (result.ok) return;
|
|
const projected = projectAnalysisError(result.error);
|
|
expect(projected).toMatchObject({
|
|
code: "configuration_invalid",
|
|
category: "invalid_input",
|
|
message: expect.stringContaining(setting),
|
|
remediation: { action: expect.stringContaining(setting) },
|
|
details: {
|
|
settings: [
|
|
{ setting, constraint: expect.stringMatching(/absolute/iu) },
|
|
],
|
|
},
|
|
});
|
|
expect(projected.message).toMatch(/absolute/iu);
|
|
expect(projected.remediation.action).toMatch(/correct/iu);
|
|
// The rejected value itself is not echoed.
|
|
expect(JSON.stringify(projected)).not.toContain(value);
|
|
},
|
|
);
|
|
|
|
it("names settings rejected by their own parsers", () => {
|
|
const result = parseConfig({ HOPPER_LOADER_ARGS_JSON: "not-json" });
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok)
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
details: {
|
|
settings: [
|
|
{
|
|
setting: "HOPPER_LOADER_ARGS_JSON",
|
|
constraint: "HOPPER_LOADER_ARGS_JSON must be valid JSON",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("JEB MCP timeout configuration", () => {
|
|
it("stays optional and validates the caller-selected environment value", () => {
|
|
expect(parseJebMcpTimeoutMs(undefined)).toEqual({
|
|
ok: true,
|
|
value: undefined,
|
|
});
|
|
expect(parseJebMcpTimeoutMs("900000")).toEqual({
|
|
ok: true,
|
|
value: 900_000,
|
|
});
|
|
expect(
|
|
parseEnvironmentValues({ REA_JEB_MCP_TIMEOUT_MS: "900000" }).ok,
|
|
).toBe(true);
|
|
});
|
|
|
|
it.each(["", "0", "-1", "1.5", "1e3", "invalid", "2147483648"])(
|
|
"rejects malformed timeout %j with its setting",
|
|
(value) => {
|
|
const result = parseJebMcpTimeoutMs(value);
|
|
if (result.ok) throw new Error("Expected invalid JEB MCP timeout");
|
|
expect(projectAnalysisError(result.error)).toMatchObject({
|
|
details: {
|
|
settings: [
|
|
{
|
|
setting: "REA_JEB_MCP_TIMEOUT_MS",
|
|
constraint: expect.any(String),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("Hopper launcher configuration", () => {
|
|
it("keeps an explicit launcher path unchanged", () => {
|
|
const configured = "/custom/../Hopper launcher";
|
|
const parsed = parseConfig({ HOPPER_LAUNCHER_PATH: configured });
|
|
expect(parsed).toMatchObject({
|
|
ok: true,
|
|
value: { hopperLauncherPath: configured },
|
|
});
|
|
});
|
|
|
|
it("leaves an unset launcher to the Hopper provider's discovery", () => {
|
|
const parsed = parseConfig({});
|
|
if (!parsed.ok) throw parsed.error;
|
|
expect(parsed.value.hopperLauncherPath).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
describe("Ghidra decompile limit configuration", () => {
|
|
it.each([
|
|
[undefined, undefined],
|
|
["1", 1],
|
|
["30", 30],
|
|
["86400", 86_400],
|
|
["86401", 86_401],
|
|
["2147483", 2_147_483],
|
|
] as const)(
|
|
"reads the Ghidra decompile limit %j as %j seconds",
|
|
(value, expected) => {
|
|
const result = parseConfig(
|
|
value === undefined
|
|
? {}
|
|
: { REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: value },
|
|
);
|
|
if (!result.ok) throw result.error;
|
|
expect(result.value.ghidraDecompileTimeoutSeconds).toBe(expected);
|
|
},
|
|
);
|
|
|
|
it.each(["", "0", "-1", "1.5", "30s", "2147484", "2147483647"])(
|
|
"rejects malformed Ghidra decompile limit %j with its setting",
|
|
(value) => {
|
|
const result = parseConfig({
|
|
REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: value,
|
|
});
|
|
if (!result.ok) throw new Error("runtime seed rejected startup");
|
|
const live = runtimeAnalysisConfig(result.value);
|
|
expect(() => live.ghidraDecompileTimeoutSeconds).toThrow(
|
|
ConfigurationError,
|
|
);
|
|
expect(
|
|
runWithAnalysisOperationSnapshot(
|
|
{
|
|
revision: 1,
|
|
overrides: { "ghidra.decompile_timeout_seconds": null },
|
|
},
|
|
() => live.ghidraDecompileTimeoutSeconds,
|
|
),
|
|
).toBeUndefined();
|
|
const boundary = launchAnalysisSetting(
|
|
"ghidra.decompile_timeout_seconds",
|
|
{ REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: value },
|
|
);
|
|
if (boundary.ok) throw new Error("invalid decompile limit was admitted");
|
|
},
|
|
);
|
|
});
|