Merge branch 'main' into agent/process-zombie-settlement
This commit is contained in:
@@ -57,7 +57,7 @@ jobs:
|
|||||||
npm install --global --prefix "${prefix}" "./${tarball}"
|
npm install --global --prefix "${prefix}" "./${tarball}"
|
||||||
echo "REA_VERIFY_SERVER_COMMAND=${prefix}/bin/rea" >> "${GITHUB_ENV}"
|
echo "REA_VERIFY_SERVER_COMMAND=${prefix}/bin/rea" >> "${GITHUB_ENV}"
|
||||||
echo 'REA_VERIFY_SERVER_ARGS_JSON=["mcp"]' >> "${GITHUB_ENV}"
|
echo 'REA_VERIFY_SERVER_ARGS_JSON=["mcp"]' >> "${GITHUB_ENV}"
|
||||||
- name: Verify two binaries through the in-process bridge
|
- name: Verify two binaries through an alternate launcher symlink
|
||||||
env:
|
env:
|
||||||
HOPPER_TARGET_PATH: ${{ inputs.first_target }}
|
HOPPER_TARGET_PATH: ${{ inputs.first_target }}
|
||||||
HOPPER_SECOND_TARGET_PATH: ${{ inputs.second_target }}
|
HOPPER_SECOND_TARGET_PATH: ${{ inputs.second_target }}
|
||||||
|
|||||||
+126
-97
@@ -170,72 +170,88 @@ try {
|
|||||||
throw new Error("packaged artifact inventory CLI failed");
|
throw new Error("packaged artifact inventory CLI failed");
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
await verifyPackagedInvestigation({ cli, workspace, evidenceRoot, artifactArchive, environment });
|
await verifyPackagedInvestigation({ cli, workspace, evidenceRoot, artifactArchive, environment });
|
||||||
const overview = json(
|
if (process.platform === "linux") {
|
||||||
await run(cli, ["analyze", process.execPath, "--json"], environment),
|
const unsupportedExecution = await runWithStatus(
|
||||||
);
|
cli,
|
||||||
if (
|
["analyze", process.execPath, "--json"],
|
||||||
overview.operation !== "binary_overview" ||
|
environment,
|
||||||
overview.normalized_result?.procedure_count < 1
|
|
||||||
)
|
|
||||||
throw new Error(
|
|
||||||
`packaged Hopper-backed analyze CLI failed: ${JSON.stringify(overview)}`,
|
|
||||||
);
|
);
|
||||||
const inspected = json(
|
const unsupported = json(unsupportedExecution.stdout);
|
||||||
await run(
|
if (
|
||||||
cli,
|
unsupportedExecution.status !== 1 ||
|
||||||
[
|
unsupported.details?.failure_code !== "unsupported_hopper_build"
|
||||||
"inspect",
|
)
|
||||||
process.execPath,
|
throw new Error(
|
||||||
"--detail",
|
`packaged Linux Hopper verification did not fail closed: ${JSON.stringify(unsupported)}`,
|
||||||
"detailed",
|
);
|
||||||
"--limit",
|
} else {
|
||||||
"1",
|
const overview = json(
|
||||||
"--json",
|
await run(cli, ["analyze", process.execPath, "--json"], environment),
|
||||||
],
|
|
||||||
environment,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
inspected.operation !== "binary_overview" ||
|
|
||||||
inspected.normalized_result?.detail !== "detailed"
|
|
||||||
)
|
|
||||||
throw new Error("packaged inspect CLI failed");
|
|
||||||
const functionResult = json(
|
|
||||||
await run(
|
|
||||||
cli,
|
|
||||||
["function", process.execPath, "0x1000", "--json"],
|
|
||||||
environment,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (
|
|
||||||
functionResult.operation !== "analyze_function" ||
|
|
||||||
functionResult.provider?.id !== "hopper" ||
|
|
||||||
functionResult.normalized_result?.procedure?.address !== "0x1000"
|
|
||||||
)
|
|
||||||
throw new Error(
|
|
||||||
`packaged function CLI failed: ${JSON.stringify(functionResult)}`,
|
|
||||||
);
|
);
|
||||||
const xrefs = json(
|
if (
|
||||||
await run(
|
overview.operation !== "binary_overview" ||
|
||||||
cli,
|
overview.normalized_result?.procedure_count < 1
|
||||||
["xrefs", process.execPath, "0x1000", "--json"],
|
)
|
||||||
environment,
|
throw new Error(
|
||||||
),
|
`packaged Hopper-backed analyze CLI failed: ${JSON.stringify(overview)}`,
|
||||||
);
|
);
|
||||||
if (
|
const inspected = json(
|
||||||
xrefs.operation !== "xrefs" ||
|
await run(
|
||||||
JSON.stringify(xrefs.normalized_result) !== JSON.stringify(["0x1000"])
|
cli,
|
||||||
)
|
[
|
||||||
throw new Error(`packaged xrefs CLI failed: ${JSON.stringify(xrefs)}`);
|
"inspect",
|
||||||
const trace = json(
|
process.execPath,
|
||||||
await run(
|
"--detail",
|
||||||
cli,
|
"detailed",
|
||||||
["trace", process.execPath, "fixture", "--json"],
|
"--limit",
|
||||||
environment,
|
"1",
|
||||||
),
|
"--json",
|
||||||
);
|
],
|
||||||
if (trace.operation !== "trace_feature")
|
environment,
|
||||||
throw new Error(`packaged trace CLI failed: ${JSON.stringify(trace)}`);
|
),
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
inspected.operation !== "binary_overview" ||
|
||||||
|
inspected.normalized_result?.detail !== "detailed"
|
||||||
|
)
|
||||||
|
throw new Error("packaged inspect CLI failed");
|
||||||
|
const functionResult = json(
|
||||||
|
await run(
|
||||||
|
cli,
|
||||||
|
["function", process.execPath, "0x1000", "--json"],
|
||||||
|
environment,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
functionResult.operation !== "analyze_function" ||
|
||||||
|
functionResult.provider?.id !== "hopper" ||
|
||||||
|
functionResult.normalized_result?.procedure?.address !== "0x1000"
|
||||||
|
)
|
||||||
|
throw new Error(
|
||||||
|
`packaged function CLI failed: ${JSON.stringify(functionResult)}`,
|
||||||
|
);
|
||||||
|
const xrefs = json(
|
||||||
|
await run(
|
||||||
|
cli,
|
||||||
|
["xrefs", process.execPath, "0x1000", "--json"],
|
||||||
|
environment,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
xrefs.operation !== "xrefs" ||
|
||||||
|
JSON.stringify(xrefs.normalized_result) !== JSON.stringify(["0x1000"])
|
||||||
|
)
|
||||||
|
throw new Error(`packaged xrefs CLI failed: ${JSON.stringify(xrefs)}`);
|
||||||
|
const trace = json(
|
||||||
|
await run(
|
||||||
|
cli,
|
||||||
|
["trace", process.execPath, "fixture", "--json"],
|
||||||
|
environment,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (trace.operation !== "trace_feature")
|
||||||
|
throw new Error(`packaged trace CLI failed: ${JSON.stringify(trace)}`);
|
||||||
|
}
|
||||||
const capabilities = json(
|
const capabilities = json(
|
||||||
await run(cli, ["capabilities", "--json"], environment),
|
await run(cli, ["capabilities", "--json"], environment),
|
||||||
);
|
);
|
||||||
@@ -247,20 +263,22 @@ try {
|
|||||||
providers.providers.some(({ id }) => typeof id !== "string")
|
providers.providers.some(({ id }) => typeof id !== "string")
|
||||||
)
|
)
|
||||||
throw new Error("packaged providers CLI failed");
|
throw new Error("packaged providers CLI failed");
|
||||||
const searchResult = json(
|
if (process.platform !== "linux") {
|
||||||
await run(
|
const searchResult = json(
|
||||||
cli,
|
await run(
|
||||||
["search", process.execPath, "fixture", "--json"],
|
cli,
|
||||||
environment,
|
["search", process.execPath, "fixture", "--json"],
|
||||||
),
|
environment,
|
||||||
);
|
),
|
||||||
if (
|
|
||||||
searchResult.operation !== "search_strings" ||
|
|
||||||
searchResult.normalized_result?.items?.length !== 1
|
|
||||||
)
|
|
||||||
throw new Error(
|
|
||||||
`packaged search CLI failed: ${JSON.stringify(searchResult)}`,
|
|
||||||
);
|
);
|
||||||
|
if (
|
||||||
|
searchResult.operation !== "search_strings" ||
|
||||||
|
searchResult.normalized_result?.items?.length !== 1
|
||||||
|
)
|
||||||
|
throw new Error(
|
||||||
|
`packaged search CLI failed: ${JSON.stringify(searchResult)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
const referenceImport = json(
|
const referenceImport = json(
|
||||||
await run(
|
await run(
|
||||||
cli,
|
cli,
|
||||||
@@ -478,30 +496,41 @@ try {
|
|||||||
);
|
);
|
||||||
if (opened.isError === true)
|
if (opened.isError === true)
|
||||||
throw new Error("packaged MCP could not open a binary");
|
throw new Error("packaged MCP could not open a binary");
|
||||||
await prompts.verifyPromptCompletion(client, mcpOptions, true);
|
await prompts.verifyPromptCompletion(
|
||||||
|
client,
|
||||||
|
mcpOptions,
|
||||||
|
process.platform !== "linux",
|
||||||
|
);
|
||||||
const current = await client.callTool(
|
const current = await client.callTool(
|
||||||
{ name: "current_document", arguments: {} },
|
{ name: "current_document", arguments: {} },
|
||||||
mcpOptions,
|
mcpOptions,
|
||||||
);
|
);
|
||||||
if (
|
if (process.platform === "linux") {
|
||||||
current.isError === true ||
|
if (
|
||||||
json(prompts.mcpText(current)).normalized_result !== "fixture"
|
current.isError !== true ||
|
||||||
)
|
!prompts
|
||||||
throw new Error("packaged MCP bridge call failed");
|
.mcpText(current)
|
||||||
const batch = await client.callTool(
|
.includes("not supported for unattended Linux analysis")
|
||||||
{ name: "batch_decompile", arguments: { addresses: ["0x1000"] } },
|
)
|
||||||
mcpOptions,
|
throw new Error("packaged Linux MCP did not reject an unpinned Hopper");
|
||||||
);
|
} else {
|
||||||
const batchResult = json(prompts.mcpText(batch)).normalized_result;
|
if (json(prompts.mcpText(current)).normalized_result !== "fixture")
|
||||||
if (
|
throw new Error("packaged MCP bridge call failed");
|
||||||
batch.isError === true ||
|
const batch = await client.callTool(
|
||||||
batchResult?.total !== 1 ||
|
{ name: "batch_decompile", arguments: { addresses: ["0x1000"] } },
|
||||||
batchResult?.succeeded !== 1 ||
|
mcpOptions,
|
||||||
batchResult?.failed !== 0 ||
|
);
|
||||||
batchResult?.items?.[0]?.status !== "ok" ||
|
const batchResult = json(prompts.mcpText(batch)).normalized_result;
|
||||||
batchResult?.items?.[0]?.pseudocode !== "return 0;"
|
if (
|
||||||
)
|
batch.isError === true ||
|
||||||
throw new Error("packaged MCP structured batch result failed");
|
batchResult?.total !== 1 ||
|
||||||
|
batchResult?.succeeded !== 1 ||
|
||||||
|
batchResult?.failed !== 0 ||
|
||||||
|
batchResult?.items?.[0]?.status !== "ok" ||
|
||||||
|
batchResult?.items?.[0]?.pseudocode !== "return 0;"
|
||||||
|
)
|
||||||
|
throw new Error("packaged MCP structured batch result failed");
|
||||||
|
}
|
||||||
const closed = await client.callTool(
|
const closed = await client.callTool(
|
||||||
{ name: "close_binary", arguments: {} },
|
{ name: "close_binary", arguments: {} },
|
||||||
mcpOptions,
|
mcpOptions,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { access } from "node:fs/promises";
|
import { access, mkdtemp, rm, symlink } from "node:fs/promises";
|
||||||
import { execFile } from "node:child_process";
|
import { execFile } from "node:child_process";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
import { promisify } from "node:util";
|
import { promisify } from "node:util";
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
@@ -14,5 +16,14 @@ await access("/usr/bin/python3");
|
|||||||
const linked = await execFileAsync("ldd", [launcher]);
|
const linked = await execFileAsync("ldd", [launcher]);
|
||||||
if (`${linked.stdout}\n${linked.stderr}`.includes("not found"))
|
if (`${linked.stdout}\n${linked.stderr}`.includes("not found"))
|
||||||
throw new Error("Hopper has unresolved shared-library dependencies");
|
throw new Error("Hopper has unresolved shared-library dependencies");
|
||||||
process.env.HOPPER_LAUNCHER_PATH = launcher;
|
const alternateDirectory = await mkdtemp(
|
||||||
await import("./verify-real-hopper.mjs");
|
join(tmpdir(), "rea-real-hopper-launcher-"),
|
||||||
|
);
|
||||||
|
const alternateLauncher = join(alternateDirectory, "Hopper-alternate");
|
||||||
|
try {
|
||||||
|
await symlink(launcher, alternateLauncher);
|
||||||
|
process.env.HOPPER_LAUNCHER_PATH = alternateLauncher;
|
||||||
|
await import("./verify-real-hopper.mjs");
|
||||||
|
} finally {
|
||||||
|
await rm(alternateDirectory, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,15 +40,25 @@ export interface BridgeLauncher {
|
|||||||
): Promise<Result<BridgeLaunch, HopperStartError | HopperCancelledError>>;
|
): Promise<Result<BridgeLaunch, HopperStartError | HopperCancelledError>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HopperApplicationLauncherOptions {
|
interface SharedHopperApplicationLauncherOptions {
|
||||||
readonly launcherPath: string;
|
readonly launcherPath: string;
|
||||||
readonly targetPath: string;
|
readonly targetPath: string;
|
||||||
readonly targetKind: "executable" | "database";
|
readonly targetKind: "executable" | "database";
|
||||||
readonly loaderArgs: readonly string[];
|
readonly loaderArgs: readonly string[];
|
||||||
readonly bridgeScriptPath: string;
|
readonly bridgeScriptPath: string;
|
||||||
readonly demoHelperPath?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Explicit launcher contract; the Linux adapter verifies its pinned Hopper build before execution. */
|
||||||
|
export type HopperApplicationLauncherOptions =
|
||||||
|
| (SharedHopperApplicationLauncherOptions & {
|
||||||
|
readonly launchMode: "native";
|
||||||
|
readonly demoHelperPath?: never;
|
||||||
|
})
|
||||||
|
| (SharedHopperApplicationLauncherOptions & {
|
||||||
|
readonly launchMode: "verified_linux_demo";
|
||||||
|
readonly demoHelperPath: string;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launches Hopper through its documented CLI and injects only REA's owned bridge.
|
* Launches Hopper through its documented CLI and injects only REA's owned bridge.
|
||||||
*
|
*
|
||||||
@@ -186,10 +196,13 @@ const linuxDemoLaunch = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const usesLinuxDemo = (options: HopperApplicationLauncherOptions): boolean =>
|
/** Select the version-pinned adapter from the caller's explicit launch mode. */
|
||||||
process.platform === "linux" &&
|
export const usesLinuxDemo = (
|
||||||
basename(options.launcherPath) === "Hopper" &&
|
options: HopperApplicationLauncherOptions,
|
||||||
options.demoHelperPath !== undefined;
|
): options is HopperApplicationLauncherOptions & {
|
||||||
|
readonly launchMode: "verified_linux_demo";
|
||||||
|
readonly demoHelperPath: string;
|
||||||
|
} => options.launchMode === "verified_linux_demo";
|
||||||
|
|
||||||
const spawnLauncher = async (
|
const spawnLauncher = async (
|
||||||
command: string,
|
command: string,
|
||||||
|
|||||||
@@ -114,9 +114,14 @@ export class HopperProvider implements AnalysisProvider {
|
|||||||
bridgeScriptPath: fileURLToPath(
|
bridgeScriptPath: fileURLToPath(
|
||||||
new URL("../../bridge/hopper_bridge.py", import.meta.url),
|
new URL("../../bridge/hopper_bridge.py", import.meta.url),
|
||||||
),
|
),
|
||||||
demoHelperPath: fileURLToPath(
|
...(process.platform === "linux"
|
||||||
new URL("../../scripts/hopper-demo-x11.py", import.meta.url),
|
? {
|
||||||
),
|
launchMode: "verified_linux_demo" as const,
|
||||||
|
demoHelperPath: fileURLToPath(
|
||||||
|
new URL("../../scripts/hopper-demo-x11.py", import.meta.url),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
: { launchMode: "native" as const }),
|
||||||
}),
|
}),
|
||||||
logger: this.logger.child({ layer: "bridge" }),
|
logger: this.logger.child({ layer: "bridge" }),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
import { execFile } from "node:child_process";
|
||||||
|
import { access, chmod, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||||
|
import { tmpdir } from "node:os";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { promisify } from "node:util";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
|
import {
|
||||||
|
type HopperApplicationLauncherOptions,
|
||||||
|
usesLinuxDemo,
|
||||||
|
} from "../src/hopper/BridgeLauncher.js";
|
||||||
|
|
||||||
|
const execFileAsync = promisify(execFile);
|
||||||
|
const demoHelperPath = fileURLToPath(
|
||||||
|
new URL("../scripts/hopper-demo-x11.py", import.meta.url),
|
||||||
|
);
|
||||||
|
|
||||||
|
const options = (launcherPath: string): HopperApplicationLauncherOptions => ({
|
||||||
|
launcherPath,
|
||||||
|
targetPath: "/target",
|
||||||
|
targetKind: "executable",
|
||||||
|
loaderArgs: [],
|
||||||
|
bridgeScriptPath: "/rea/hopper_bridge.py",
|
||||||
|
launchMode: "verified_linux_demo",
|
||||||
|
demoHelperPath: "/rea/hopper-demo-x11.py",
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Hopper bridge launcher selection", () => {
|
||||||
|
it.each([
|
||||||
|
"/opt/hopper/bin/Hopper",
|
||||||
|
"/usr/local/bin/hopper",
|
||||||
|
"/workspace/bin/hopper-wrapper",
|
||||||
|
])(
|
||||||
|
"routes launcher spelling %s through the explicitly selected pinned adapter",
|
||||||
|
(path) => {
|
||||||
|
expect(usesLinuxDemo(options(path))).toBe(true);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it("does not infer demo behavior from a native launcher's basename", () => {
|
||||||
|
expect(
|
||||||
|
usesLinuxDemo({
|
||||||
|
launcherPath: "/opt/hopper/bin/Hopper",
|
||||||
|
targetPath: "/target",
|
||||||
|
targetKind: "executable",
|
||||||
|
loaderArgs: [],
|
||||||
|
bridgeScriptPath: "/rea/hopper_bridge.py",
|
||||||
|
launchMode: "native",
|
||||||
|
}),
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects an unpinned wrapper before executing it", async () => {
|
||||||
|
const directory = await mkdtemp(join(tmpdir(), "rea-hopper-wrapper-"));
|
||||||
|
const wrapper = join(directory, "hopper-wrapper");
|
||||||
|
const marker = join(directory, "executed");
|
||||||
|
try {
|
||||||
|
await writeFile(wrapper, `#!/bin/sh\ntouch ${JSON.stringify(marker)}\n`);
|
||||||
|
await chmod(wrapper, 0o700);
|
||||||
|
await expect(
|
||||||
|
execFileAsync(
|
||||||
|
"python3",
|
||||||
|
[
|
||||||
|
demoHelperPath,
|
||||||
|
"--hopper",
|
||||||
|
wrapper,
|
||||||
|
"--socket",
|
||||||
|
join(directory, "bridge.sock"),
|
||||||
|
"--",
|
||||||
|
wrapper,
|
||||||
|
],
|
||||||
|
{ timeout: 3_000 },
|
||||||
|
),
|
||||||
|
).rejects.toMatchObject({
|
||||||
|
code: 72,
|
||||||
|
stderr: expect.stringContaining("unsupported Hopper binary"),
|
||||||
|
});
|
||||||
|
await expect(access(marker)).rejects.toMatchObject({ code: "ENOENT" });
|
||||||
|
} finally {
|
||||||
|
await rm(directory, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -37,7 +37,7 @@ describe("production stdio runtime", () => {
|
|||||||
name: "current_document",
|
name: "current_document",
|
||||||
arguments: {},
|
arguments: {},
|
||||||
});
|
});
|
||||||
expect(result.isError).not.toBe(true);
|
expect(result.isError === true).toBe(process.platform === "linux");
|
||||||
} finally {
|
} finally {
|
||||||
await client.close();
|
await client.close();
|
||||||
await transport.close();
|
await transport.close();
|
||||||
@@ -53,7 +53,7 @@ describe("production stdio runtime", () => {
|
|||||||
mode: "mcp",
|
mode: "mcp",
|
||||||
layer: "server",
|
layer: "server",
|
||||||
tool: "current_document",
|
tool: "current_document",
|
||||||
status: "ok",
|
status: process.platform === "linux" ? "error" : "ok",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(stderr).not.toContain("HOPPER_LOADER_ARGS_JSON");
|
expect(stderr).not.toContain("HOPPER_LOADER_ARGS_JSON");
|
||||||
|
|||||||
Reference in New Issue
Block a user