mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 06:25:44 +00:00
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
import { execFile } from "node:child_process";
|
|
import { promisify } from "node:util";
|
|
import { access, mkdir, truncate, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES = 1024 * 1024;
|
|
|
|
cliTest.for(["pipe", "capacity"] as const)(
|
|
"doctor reports selected properties %s without launching Java",
|
|
async (kind, { cli, skip }) => {
|
|
if (kind === "pipe" && process.platform === "win32") {
|
|
skip();
|
|
return;
|
|
}
|
|
const root = await createTestTempDirectory("rea-doctor-properties-");
|
|
const install = join(root, "ghidra");
|
|
const path = join(install, "Ghidra/application.properties");
|
|
const javaHome = join(root, "java-home");
|
|
const java = join(javaHome, "bin", "java");
|
|
if (process.platform !== "win32") {
|
|
await mkdir(join(javaHome, "bin"), { recursive: true });
|
|
await writeFile(
|
|
java,
|
|
'#!/bin/sh\nprintf "launched\\n" > "$0.was-run"\n',
|
|
{
|
|
mode: 0o700,
|
|
},
|
|
);
|
|
}
|
|
await mkdir(join(install, "Ghidra"), { recursive: true });
|
|
if (kind === "pipe") await promisify(execFile)("mkfifo", [path]);
|
|
else {
|
|
await writeFile(path, "application.version=12.1.4\n");
|
|
await truncate(path, MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES + 1);
|
|
}
|
|
const result = await cli.run({
|
|
arguments: ["doctor", "--provider", "ghidra", "--json"],
|
|
environment: {
|
|
GHIDRA_INSTALL_DIR: install,
|
|
JAVA_HOME: javaHome,
|
|
REA_LOG_LEVEL: "silent",
|
|
},
|
|
});
|
|
expect(result.exitCode, `${result.stdout}\n${result.stderr}`).toBe(1);
|
|
expect(result.signal).toBeNull();
|
|
if (process.platform !== "win32")
|
|
await expect(access(`${java}.was-run`)).rejects.toMatchObject({
|
|
code: "ENOENT",
|
|
});
|
|
expect(result.json).toMatchObject({
|
|
code: kind === "pipe" ? "execution_failure" : "resource_constraint",
|
|
details: {
|
|
operation: "doctor",
|
|
diagnostics: { path, stage: "installation_properties" },
|
|
},
|
|
});
|
|
if (kind === "capacity") {
|
|
expect(result.json).toMatchObject({
|
|
retryable: false,
|
|
details: {
|
|
reported_limits: {
|
|
maximum_bytes: MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES,
|
|
observed_bytes: String(
|
|
MAX_GHIDRA_INSTALLATION_PROPERTIES_BYTES + 1,
|
|
),
|
|
},
|
|
},
|
|
remediation: {
|
|
action: expect.stringContaining("installation-properties"),
|
|
},
|
|
});
|
|
expect(JSON.stringify(result.json)).toContain("no runtime override");
|
|
expect(JSON.stringify(result.json)).not.toContain(
|
|
"Retry with a sufficient file-size allowance",
|
|
);
|
|
}
|
|
},
|
|
);
|