mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
test: assert structured recovery facts instead of recovery wording in tests/ (#12723)
Drop recovery-sentence locks when a structured field or the owning formatter already carries the fact, and own this batch's per-test temporary directories through createTestTempDirectory. Keep setting names, caller data, and prose that has no structured carrier. Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
1 parent
847c2d5253
commit
bb8e6833eb
19 files changed
+339
-430
No files matched your search
@@ -72,6 +72,11 @@ cliTest(
|
||||
resource: "capacity",
|
||||
reason: parsed.error.failure.detail,
|
||||
reported_limits: { max_signing_block_pairs: 4096 },
|
||||
refusal: {
|
||||
kind: "fixed_ceiling",
|
||||
operation: "inspect_apk_signature",
|
||||
allowance_kind: "count",
|
||||
},
|
||||
},
|
||||
};
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
@@ -82,10 +87,6 @@ cliTest(
|
||||
const error = analysisErrorProjectionSchema.parse(reply.json);
|
||||
expect(error).toMatchObject(expected);
|
||||
expect(error.remediation.action).toContain("4096");
|
||||
expect(error.remediation.action).toContain("no runtime override");
|
||||
expect(error.remediation.action).toContain(
|
||||
"Waiting for an active analysis to finish does not raise it",
|
||||
);
|
||||
}
|
||||
const malformedExpected = {
|
||||
code: "invalid_request",
|
||||
|
||||
@@ -807,9 +807,11 @@ cliTest(
|
||||
resource: "capacity",
|
||||
reason: parserReason,
|
||||
reported_limits: { max_v1_signature_entries: 4096 },
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining("no runtime override"),
|
||||
refusal: {
|
||||
kind: "fixed_ceiling",
|
||||
operation: "inspect_apk_signature",
|
||||
allowance_kind: "count",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -599,6 +599,11 @@ cliTest.for([
|
||||
details: {
|
||||
operation: "inspect_pe_certificates",
|
||||
reported_limits: limits,
|
||||
refusal: {
|
||||
kind: "fixed_ceiling",
|
||||
allowance_kind: "parser",
|
||||
limit: Object.values(limits)[0],
|
||||
},
|
||||
},
|
||||
});
|
||||
const { message: reason, remediation } = result.json as {
|
||||
@@ -607,8 +612,6 @@ cliTest.for([
|
||||
};
|
||||
expect(reason).toContain(message);
|
||||
expect(remediation.action).toContain(String(Object.values(limits)[0]));
|
||||
expect(remediation.action).toContain("no runtime override");
|
||||
expect(remediation.action).toMatch(/unchanged request.*fails/iu);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -704,14 +704,12 @@ it("applies caller-selected discovery_timeout_ms to browser-socket discovery", a
|
||||
expect(projected.message).toContain(
|
||||
`${String(discoveryTimeoutMs)} ms discovery_timeout_ms`,
|
||||
);
|
||||
expect(projected.remediation?.action).toContain(
|
||||
`Increase discovery_timeout_ms above ${String(discoveryTimeoutMs)}`,
|
||||
);
|
||||
expect(projected.remediation?.action).not.toContain("--");
|
||||
expect(projected.details?.limit).toMatchObject({
|
||||
control_kind: "parameter",
|
||||
parameter: "discovery_timeout_ms",
|
||||
effective_value: discoveryTimeoutMs,
|
||||
applies_at: "next_call",
|
||||
});
|
||||
await waitFor(() => expect(browser.activeConnectionCount()).toBe(0));
|
||||
} finally {
|
||||
|
||||
@@ -6,15 +6,12 @@ import {
|
||||
access,
|
||||
chmod,
|
||||
mkdir,
|
||||
mkdtemp,
|
||||
readFile,
|
||||
rm,
|
||||
stat,
|
||||
symlink,
|
||||
truncate,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { expect, it, onTestFinished, vi } from "vitest";
|
||||
import { phaseGate } from "../../support/lifecycleHarness.js";
|
||||
@@ -38,8 +35,7 @@ import { waitFor } from "../../support/testWait.js";
|
||||
const linux = it.skipIf(process.platform !== "linux");
|
||||
|
||||
linux("refuses a directory configured as the mitmdump executable", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-mitmdump-command-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-mitmdump-command-");
|
||||
const command = join(root, "mitmdump");
|
||||
await mkdir(command);
|
||||
|
||||
@@ -55,8 +51,7 @@ linux("refuses a directory configured as the mitmdump executable", async () => {
|
||||
});
|
||||
|
||||
linux("allows a symlink to a regular mitmdump executable", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-mitmdump-command-symlink-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-mitmdump-command-symlink-");
|
||||
const command = join(root, "mitmdump");
|
||||
const target = join(root, "mitmdump-bin");
|
||||
await writeFile(target, "#!/bin/sh\n", { mode: 0o700 });
|
||||
@@ -71,8 +66,7 @@ linux("allows a symlink to a regular mitmdump executable", async () => {
|
||||
});
|
||||
|
||||
it("keeps the admitted decoder environment across adapter preparation and refreshes it for the next call", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-capture-environment-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-capture-environment-");
|
||||
const path = join(root, "capture.har");
|
||||
const observedPath = join(root, "observed.json");
|
||||
const text = JSON.stringify(historicalHar());
|
||||
@@ -133,8 +127,7 @@ it("keeps the admitted decoder environment across adapter preparation and refres
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"binds independently selected mitmproxy configuration before runtime preparation",
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-mitmproxy-environment-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-mitmproxy-environment-");
|
||||
const capturePath = join(root, "capture.mitm");
|
||||
const observedPath = join(root, "observed.json");
|
||||
await writeFile(capturePath, "inert selected capture");
|
||||
@@ -240,8 +233,7 @@ const expectOwnedDecoderPrimary = (
|
||||
it.each(["cancelled", "process"] as const)(
|
||||
"retains an unresolved decoder and its root across concurrent inspection and shutdown (%s)",
|
||||
async (outcome) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-capture-owned-cleanup-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-capture-owned-cleanup-");
|
||||
const capturePath = join(root, "capture.har");
|
||||
const markerPath = join(root, "started.json");
|
||||
const finishPath = join(root, "finish");
|
||||
@@ -386,8 +378,7 @@ it.each(["cancelled", "process"] as const)(
|
||||
);
|
||||
|
||||
it("applies a non-default capture deadline and releases its runtime", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-capture-deadline-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-capture-deadline-");
|
||||
const path = join(root, "capture.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
let runtimePath: string | undefined;
|
||||
@@ -430,8 +421,7 @@ it("applies a non-default capture deadline and releases its runtime", async () =
|
||||
it.each([true, false])(
|
||||
"binds decoder replies to the complete selected provider identity (matching name: %s)",
|
||||
async (matching) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-capture-identity-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-capture-identity-");
|
||||
const path = join(root, "capture.har");
|
||||
const text = JSON.stringify(historicalHar());
|
||||
await writeFile(path, text);
|
||||
@@ -466,8 +456,7 @@ it.each([true, false])(
|
||||
);
|
||||
|
||||
it("classifies an oversized selected capture before creating an owned decoder", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-limit-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-limit-");
|
||||
const path = join(root, "input.har");
|
||||
await writeFile(path, "");
|
||||
await truncate(path, WEB_NETWORK_CAPTURE_LIMITS.inputBytes + 1);
|
||||
@@ -508,8 +497,7 @@ it("classifies an oversized selected capture before creating an owned decoder",
|
||||
});
|
||||
|
||||
it("retains a failed capture reader and retries it before a fresh load", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-capture-reader-close-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-capture-reader-close-");
|
||||
const path = join(root, "input.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
const originalClose = OwnedFileHandle.prototype.close;
|
||||
@@ -569,8 +557,7 @@ it("retains a failed capture reader and retries it before a fresh load", async (
|
||||
});
|
||||
|
||||
it("does not misclassify decoder filesystem failures as missing selected input", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-command-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-command-");
|
||||
const path = join(root, "input.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
const decoder = new HistoricalCaptureDecoder(
|
||||
@@ -609,8 +596,7 @@ it("does not misclassify decoder filesystem failures as missing selected input",
|
||||
it.each(["missing-capture", "missing-reply", "failed-command"])(
|
||||
"redacts declared paths and diagnostics while preserving the %s failure",
|
||||
async (mode) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-sensitive-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-sensitive-");
|
||||
const path = join(root, "explicit-private-value.har");
|
||||
if (mode !== "missing-capture")
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
@@ -658,8 +644,7 @@ it.each(["missing-capture", "missing-reply", "failed-command"])(
|
||||
);
|
||||
|
||||
it("reports an absent owned reply as output failure and removes its private snapshot root", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-decoder-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-decoder-");
|
||||
const path = join(root, "input.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
let privatePath: string | undefined;
|
||||
@@ -694,8 +679,7 @@ it("reports an absent owned reply as output failure and removes its private snap
|
||||
});
|
||||
|
||||
it("cancels after snapshot acquisition before launch and removes private input declarations", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-cancel-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-cancel-");
|
||||
const path = join(root, "input.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
let privatePath: string | undefined;
|
||||
@@ -733,8 +717,7 @@ it("cancels after snapshot acquisition before launch and removes private input d
|
||||
});
|
||||
|
||||
it("preserves the exact cancellation reason observed during final runtime close", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-final-cancel-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-final-cancel-");
|
||||
const path = join(root, "input.har");
|
||||
const text = JSON.stringify(historicalHar());
|
||||
await writeFile(path, text);
|
||||
@@ -788,8 +771,7 @@ it("preserves the exact cancellation reason observed during final runtime close"
|
||||
});
|
||||
|
||||
it("retains completed capture facts and binds final root cleanup to its retry lease", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-report-cleanup-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-report-cleanup-");
|
||||
const path = join(root, "input.har");
|
||||
const text = JSON.stringify(historicalHar());
|
||||
await writeFile(path, text);
|
||||
@@ -852,8 +834,7 @@ it("retains completed capture facts and binds final root cleanup to its retry le
|
||||
});
|
||||
|
||||
it("keeps late cancellation primary when runtime close also fails, then clears on retry", async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-cancel-cleanup-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-cancel-cleanup-");
|
||||
const path = join(root, "input.har");
|
||||
const text = JSON.stringify(historicalHar());
|
||||
await writeFile(path, text);
|
||||
@@ -933,8 +914,7 @@ it.each([
|
||||
])(
|
||||
"preserves $reason decoder failures through the public error boundary",
|
||||
async ({ reason, tag }) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-reply-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-reply-");
|
||||
const path = join(root, "input.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
let privatePath: string | undefined;
|
||||
@@ -1011,17 +991,18 @@ it.each([
|
||||
String(WEB_NETWORK_CAPTURE_LIMITS.outputBytes),
|
||||
),
|
||||
details: {
|
||||
operation: "inspect_web_network_capture",
|
||||
diagnostics: {
|
||||
maximum_reply_bytes: WEB_NETWORK_CAPTURE_LIMITS.outputBytes,
|
||||
budget: {
|
||||
parameter: "max_reply_bytes",
|
||||
effective_value: WEB_NETWORK_CAPTURE_LIMITS.outputBytes,
|
||||
applies_at: "next_operation",
|
||||
update_mode: "parameter",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).toContain(
|
||||
`Increase max_reply_bytes above ${String(WEB_NETWORK_CAPTURE_LIMITS.outputBytes)}`,
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"next inspect_web_network_capture call",
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"do not recreate a completed report from a refused decode",
|
||||
);
|
||||
@@ -1052,8 +1033,7 @@ it.each([
|
||||
it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
|
||||
"reports a real filesystem permission denial separately from missing capture input",
|
||||
async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-denied-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-denied-");
|
||||
const path = join(root, "unreadable.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()), { mode: 0o000 });
|
||||
const decoder = new HistoricalCaptureDecoder(
|
||||
@@ -1095,8 +1075,7 @@ it.skipIf(process.platform === "win32" || process.getuid?.() === 0)(
|
||||
it.each(["format", "process"])(
|
||||
"preserves the structured %s failure when runtime cleanup fails",
|
||||
async (kind) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-historical-cleanup-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-historical-cleanup-");
|
||||
const path = join(root, "capture-private.har");
|
||||
await writeFile(path, JSON.stringify(historicalHar()));
|
||||
const decoder = new HistoricalCaptureDecoder(
|
||||
@@ -1202,8 +1181,7 @@ it.each([
|
||||
])(
|
||||
"retains validated reply completion through descriptor cancellation %j",
|
||||
async ({ closeFails, reply }) => {
|
||||
const root = await mkdtemp(join(tmpdir(), "rea-reply-finalization-"));
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }));
|
||||
const root = await createTestTempDirectory("rea-reply-finalization-");
|
||||
const path = join(root, "input.har");
|
||||
const text = JSON.stringify(historicalHar());
|
||||
await writeFile(path, text);
|
||||
|
||||
@@ -1102,7 +1102,6 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)(
|
||||
const projected = projectAnalysisError(result.error);
|
||||
expect(projected.code).toBe("resource_constraint");
|
||||
expect(projected.retryable).toBe(false);
|
||||
expect(projected.remediation.action).toContain("APK snapshot allowance");
|
||||
expect(projected.details?.refusal).toMatchObject({
|
||||
kind: "fixed_ceiling",
|
||||
allowance_kind: "input",
|
||||
|
||||
@@ -254,9 +254,6 @@ describe("raw-binary load rejection diagnostics", () => {
|
||||
constraint: "load_selection_rejected",
|
||||
related_parameters: ["format", "architecture", "entry_point"],
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringMatching(/format.*architecture.*entry_point/i),
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).not.toContain("--target-format");
|
||||
});
|
||||
|
||||
@@ -49,8 +49,9 @@ describe("firmware request validation projection", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining("Correct the listed fields"),
|
||||
recovery: {
|
||||
kind: "inspect_input_contract",
|
||||
operation: "extract_firmware",
|
||||
},
|
||||
});
|
||||
expect(execute).not.toHaveBeenCalled();
|
||||
|
||||
@@ -9,6 +9,7 @@ import { createServer } from "../../../src/server/createServer.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { nugetNupkgFixture } from "../../../src/nuget/NugetNupkg.fixture.js";
|
||||
import { ZIP_ZSTANDARD_WINDOW_CEILING } from "../../../src/resources/ZipArtifactReader.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { mcpTest, type TestMcp } from "../../support/mcp/mcpFixture.js";
|
||||
|
||||
@@ -111,14 +112,14 @@ mcpTest(
|
||||
expect(error).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable: false,
|
||||
});
|
||||
expect(error.remediation.action).toContain(
|
||||
"Recompress the member with a window of at most 128 MiB",
|
||||
);
|
||||
expect(error.details?.refusal).toMatchObject({
|
||||
kind: "fixed_ceiling",
|
||||
limit: 128 * 1024 * 1024,
|
||||
unit: "bytes",
|
||||
details: {
|
||||
refusal: {
|
||||
kind: "fixed_ceiling",
|
||||
limit: ZIP_ZSTANDARD_WINDOW_CEILING.limit,
|
||||
unit: ZIP_ZSTANDARD_WINDOW_CEILING.unit,
|
||||
narrowing: ZIP_ZSTANDARD_WINDOW_CEILING.narrowing,
|
||||
},
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
enumeration.mockRestore();
|
||||
|
||||
@@ -111,6 +111,5 @@ it("refuses a wxapkg member table above its fixed allowance with a typed refusal
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(error.remediation.action).toContain("The allowance is 16777216 bytes");
|
||||
await call("close_binary", {});
|
||||
});
|
||||
@@ -722,9 +722,6 @@ it("exposes overload candidates and executes only an explicitly selected ambiguo
|
||||
// A schema-valid ambiguous selector names its candidates, not the schema.
|
||||
const ambiguousProjection = projectAnalysisError(ambiguous.error);
|
||||
expect(ambiguousProjection.recovery).toBeUndefined();
|
||||
expect(ambiguousProjection.remediation.action).toMatch(
|
||||
/^Set overload_index to exactly one of the \d+ candidates/u,
|
||||
);
|
||||
expect(ambiguousProjection.details?.refusal).toMatchObject({
|
||||
kind: "ambiguous_selector",
|
||||
operation: "inspect_android_method",
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { spawn } from "node:child_process";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { once } from "node:events";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { connect } from "node:net";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { spawn as spawnPty } from "@lydell/node-pty";
|
||||
|
||||
import { expect, it, onTestFinished, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
OwnedDebuggerCleanupError,
|
||||
retainedDebuggerProcessIds,
|
||||
@@ -1172,8 +1172,8 @@ it("disposes supervision when the debugger exits after SIGKILL", async () => {
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"retains the debugger owner while an unknown descendant holds output pipes open",
|
||||
async () => {
|
||||
const releaseDirectory = await mkdtemp(
|
||||
join(tmpdir(), "rea-debugger-output-writer-"),
|
||||
const releaseDirectory = await createTestTempDirectory(
|
||||
"rea-debugger-output-writer-",
|
||||
);
|
||||
const releaseFile = join(releaseDirectory, "release-writer");
|
||||
const writerSource = `const{watch}=require("node:fs");const watcher=watch(${JSON.stringify(releaseDirectory)},(_event,name)=>{if(name==="release-writer"){watcher.close();process.exit(0)}});process.stdout.write("writer-ready\\n");`;
|
||||
@@ -1247,7 +1247,6 @@ it.skipIf(process.platform === "win32")(
|
||||
probeExit,
|
||||
new Promise<void>((resolve) => setTimeout(resolve, 3_000)),
|
||||
]);
|
||||
await rm(releaseDirectory, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { regexMatchingDeadlineContinuingRecovery } from "../../../src/config/regexMatchingDeadline.js";
|
||||
import {
|
||||
DEFAULT_REGEX_MATCHING_DEADLINE_MS,
|
||||
@@ -147,83 +147,72 @@ it("leaves a heap percentage unestablished without reading host memory", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not report the 128 MiB request for NODE_OPTIONS supplied by an env file", () => {
|
||||
const directory = mkdtempSync(join(tmpdir(), "rea-regex-env-file-"));
|
||||
it("does not report the 128 MiB request for NODE_OPTIONS supplied by an env file", async () => {
|
||||
const directory = await createTestTempDirectory("rea-regex-env-file-");
|
||||
const file = join(directory, "heap.env");
|
||||
writeFileSync(file, "NODE_OPTIONS=--max-old-space-size=256\n");
|
||||
try {
|
||||
const fromFile = probeWorkerHeap([`--env-file=${file}`], undefined);
|
||||
const ifExists = probeWorkerHeap(
|
||||
[`--env-file-if-exists=${file}`],
|
||||
undefined,
|
||||
);
|
||||
const small = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
const large = probeWorkerHeap(["--max-old-space-size=256"], undefined);
|
||||
expect(fromFile.resourceOld).toBe(128);
|
||||
expect(ifExists.resourceOld).toBe(128);
|
||||
expect(small.resourceOld).toBe(128);
|
||||
expect(large.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(fromFile.heap, large.heap)).toBeLessThan(0.05);
|
||||
expect(relativeHeapGap(ifExists.heap, large.heap)).toBeLessThan(0.05);
|
||||
expect(fromFile.heap).toBeGreaterThan(small.heap);
|
||||
expect(ifExists.heap).toBeGreaterThan(small.heap);
|
||||
for (const execArgv of [
|
||||
[`--env-file=${file}`],
|
||||
[`--env-file-if-exists=${file}`],
|
||||
[`--env-file=${file}`, "--max-old-space-size=64"],
|
||||
])
|
||||
expect(resolveRegexWorkerHeap(execArgv, undefined)).toEqual({
|
||||
kind: "unknown",
|
||||
});
|
||||
expect(
|
||||
resolveRegexWorkerHeap([`--env-file=${file}`], "--max-old-space-size=64"),
|
||||
).toEqual({ kind: "effective", mib: 64, overridden: true });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
const fromFile = probeWorkerHeap([`--env-file=${file}`], undefined);
|
||||
const ifExists = probeWorkerHeap([`--env-file-if-exists=${file}`], undefined);
|
||||
const small = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
const large = probeWorkerHeap(["--max-old-space-size=256"], undefined);
|
||||
expect(fromFile.resourceOld).toBe(128);
|
||||
expect(ifExists.resourceOld).toBe(128);
|
||||
expect(small.resourceOld).toBe(128);
|
||||
expect(large.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(fromFile.heap, large.heap)).toBeLessThan(0.05);
|
||||
expect(relativeHeapGap(ifExists.heap, large.heap)).toBeLessThan(0.05);
|
||||
expect(fromFile.heap).toBeGreaterThan(small.heap);
|
||||
expect(ifExists.heap).toBeGreaterThan(small.heap);
|
||||
for (const execArgv of [
|
||||
[`--env-file=${file}`],
|
||||
[`--env-file-if-exists=${file}`],
|
||||
[`--env-file=${file}`, "--max-old-space-size=64"],
|
||||
])
|
||||
expect(resolveRegexWorkerHeap(execArgv, undefined)).toEqual({
|
||||
kind: "unknown",
|
||||
});
|
||||
expect(
|
||||
resolveRegexWorkerHeap([`--env-file=${file}`], "--max-old-space-size=64"),
|
||||
).toEqual({ kind: "effective", mib: 64, overridden: true });
|
||||
});
|
||||
|
||||
it("does not report the 128 MiB request for a heap percentage in a Node config file", () => {
|
||||
const directory = mkdtempSync(join(tmpdir(), "rea-regex-config-file-"));
|
||||
it("does not report the 128 MiB request for a heap percentage in a Node config file", async () => {
|
||||
const directory = await createTestTempDirectory("rea-regex-config-file-");
|
||||
const file = join(directory, "heap.config.json");
|
||||
const config = '{"nodeOptions":{"max-old-space-size-percentage":"1"}}\n';
|
||||
writeFileSync(file, config);
|
||||
writeFileSync(join(directory, "node.config.json"), config);
|
||||
try {
|
||||
const fromFile = probeWorkerHeap(
|
||||
[`--experimental-config-file=${file}`],
|
||||
undefined,
|
||||
);
|
||||
const withAbsolute = probeWorkerHeap(
|
||||
[`--experimental-config-file=${file}`, "--max-old-space-size=256"],
|
||||
undefined,
|
||||
);
|
||||
const fromDefault = probeWorkerHeap(
|
||||
["--experimental-default-config-file"],
|
||||
undefined,
|
||||
directory,
|
||||
);
|
||||
expect(fromFile.resourceOld).toBe(128);
|
||||
expect(withAbsolute.resourceOld).toBe(128);
|
||||
expect(fromDefault.resourceOld).toBe(128);
|
||||
for (const execArgv of [
|
||||
[`--experimental-config-file=${file}`],
|
||||
["--experimental-config-file", file],
|
||||
[`--experimental-config-file=${file}`, "--max-old-space-size=64"],
|
||||
["--experimental-default-config-file"],
|
||||
])
|
||||
expect(resolveRegexWorkerHeap(execArgv, undefined)).toEqual({
|
||||
kind: "unknown",
|
||||
});
|
||||
expect(
|
||||
resolveRegexWorkerHeap(
|
||||
["--experimental-config-file=node.config.json"],
|
||||
"--max-old-space-size=64",
|
||||
),
|
||||
).toEqual({ kind: "unknown" });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
const fromFile = probeWorkerHeap(
|
||||
[`--experimental-config-file=${file}`],
|
||||
undefined,
|
||||
);
|
||||
const withAbsolute = probeWorkerHeap(
|
||||
[`--experimental-config-file=${file}`, "--max-old-space-size=256"],
|
||||
undefined,
|
||||
);
|
||||
const fromDefault = probeWorkerHeap(
|
||||
["--experimental-default-config-file"],
|
||||
undefined,
|
||||
directory,
|
||||
);
|
||||
expect(fromFile.resourceOld).toBe(128);
|
||||
expect(withAbsolute.resourceOld).toBe(128);
|
||||
expect(fromDefault.resourceOld).toBe(128);
|
||||
for (const execArgv of [
|
||||
[`--experimental-config-file=${file}`],
|
||||
["--experimental-config-file", file],
|
||||
[`--experimental-config-file=${file}`, "--max-old-space-size=64"],
|
||||
["--experimental-default-config-file"],
|
||||
])
|
||||
expect(resolveRegexWorkerHeap(execArgv, undefined)).toEqual({
|
||||
kind: "unknown",
|
||||
});
|
||||
expect(
|
||||
resolveRegexWorkerHeap(
|
||||
["--experimental-config-file=node.config.json"],
|
||||
"--max-old-space-size=64",
|
||||
),
|
||||
).toEqual({ kind: "unknown" });
|
||||
});
|
||||
|
||||
it("does not report the 128 MiB request when --max-heap-size lowers the worker heap", () => {
|
||||
@@ -325,97 +314,85 @@ worker.once("error", (error) => {
|
||||
};
|
||||
};
|
||||
|
||||
it("does not report the 128 MiB request after a preload clears process.execArgv", () => {
|
||||
it("does not report the 128 MiB request after a preload clears process.execArgv", async () => {
|
||||
if (assertUnrecoverableOffLinux()) return;
|
||||
const directory = mkdtempSync(join(tmpdir(), "rea-regex-exec-argv-"));
|
||||
try {
|
||||
const reported = spawnCommandLineReport(
|
||||
directory,
|
||||
["--max-old-space-size=64"],
|
||||
"process.execArgv.length = 0;\n",
|
||||
);
|
||||
const preload = join(directory, "preload.cjs");
|
||||
const pinned = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
const larger = probeWorkerHeap(["--max-old-space-size=256"], undefined);
|
||||
expect(reported.execLen).toBe(0);
|
||||
expect(reported.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(reported.heap, pinned.heap)).toBeLessThan(0.05);
|
||||
expect(reported.heap).toBeLessThan(larger.heap);
|
||||
const recovered = execArgvFromCommandLine(
|
||||
Buffer.from(reported.cmdline, "base64"),
|
||||
);
|
||||
expect(recovered).toEqual({
|
||||
const directory = await createTestTempDirectory("rea-regex-exec-argv-");
|
||||
const reported = spawnCommandLineReport(
|
||||
directory,
|
||||
["--max-old-space-size=64"],
|
||||
"process.execArgv.length = 0;\n",
|
||||
);
|
||||
const preload = join(directory, "preload.cjs");
|
||||
const pinned = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
const larger = probeWorkerHeap(["--max-old-space-size=256"], undefined);
|
||||
expect(reported.execLen).toBe(0);
|
||||
expect(reported.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(reported.heap, pinned.heap)).toBeLessThan(0.05);
|
||||
expect(reported.heap).toBeLessThan(larger.heap);
|
||||
const recovered = execArgvFromCommandLine(
|
||||
Buffer.from(reported.cmdline, "base64"),
|
||||
);
|
||||
expect(recovered).toEqual({
|
||||
kind: "recovered",
|
||||
value: ["--max-old-space-size=64", `--require=${preload}`],
|
||||
});
|
||||
expect(
|
||||
resolveLaunchRegexWorkerHeap(recovered, {
|
||||
kind: "recovered",
|
||||
value: ["--max-old-space-size=64", `--require=${preload}`],
|
||||
});
|
||||
expect(
|
||||
resolveLaunchRegexWorkerHeap(recovered, {
|
||||
kind: "recovered",
|
||||
value: undefined,
|
||||
}),
|
||||
).toEqual({ kind: "effective", mib: 64, overridden: true });
|
||||
expect(resolveRegexWorkerHeap([], undefined)).toEqual({
|
||||
kind: "effective",
|
||||
mib: 128,
|
||||
overridden: false,
|
||||
});
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
value: undefined,
|
||||
}),
|
||||
).toEqual({ kind: "effective", mib: 64, overridden: true });
|
||||
expect(resolveRegexWorkerHeap([], undefined)).toEqual({
|
||||
kind: "effective",
|
||||
mib: 128,
|
||||
overridden: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("leaves the heap unknown when a preload title overwrites the command line", () => {
|
||||
it("leaves the heap unknown when a preload title overwrites the command line", async () => {
|
||||
if (assertUnrecoverableOffLinux()) return;
|
||||
const directory = mkdtempSync(join(tmpdir(), "rea-regex-title-"));
|
||||
try {
|
||||
const reported = spawnCommandLineReport(
|
||||
directory,
|
||||
["--max-old-space-size=64"],
|
||||
'process.title = "rea";\n',
|
||||
);
|
||||
const pinned = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
expect(reported.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(reported.heap, pinned.heap)).toBeLessThan(0.05);
|
||||
const recovered = execArgvFromCommandLine(
|
||||
Buffer.from(reported.cmdline, "base64"),
|
||||
);
|
||||
expect(recovered).toEqual({ kind: "unrecoverable" });
|
||||
expect(
|
||||
resolveLaunchRegexWorkerHeap(recovered, {
|
||||
kind: "recovered",
|
||||
value: undefined,
|
||||
}),
|
||||
).toEqual({ kind: "unknown" });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
const directory = await createTestTempDirectory("rea-regex-title-");
|
||||
const reported = spawnCommandLineReport(
|
||||
directory,
|
||||
["--max-old-space-size=64"],
|
||||
'process.title = "rea";\n',
|
||||
);
|
||||
const pinned = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
expect(reported.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(reported.heap, pinned.heap)).toBeLessThan(0.05);
|
||||
const recovered = execArgvFromCommandLine(
|
||||
Buffer.from(reported.cmdline, "base64"),
|
||||
);
|
||||
expect(recovered).toEqual({ kind: "unrecoverable" });
|
||||
expect(
|
||||
resolveLaunchRegexWorkerHeap(recovered, {
|
||||
kind: "recovered",
|
||||
value: undefined,
|
||||
}),
|
||||
).toEqual({ kind: "unknown" });
|
||||
});
|
||||
|
||||
it("leaves the heap unknown when --title overwrites the command line", () => {
|
||||
it("leaves the heap unknown when --title overwrites the command line", async () => {
|
||||
if (assertUnrecoverableOffLinux()) return;
|
||||
const directory = mkdtempSync(join(tmpdir(), "rea-regex-title-flag-"));
|
||||
try {
|
||||
const reported = spawnCommandLineReport(
|
||||
directory,
|
||||
["--title=rea", "--max-old-space-size=64"],
|
||||
undefined,
|
||||
);
|
||||
const pinned = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
expect(reported.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(reported.heap, pinned.heap)).toBeLessThan(0.05);
|
||||
const recovered = execArgvFromCommandLine(
|
||||
Buffer.from(reported.cmdline, "base64"),
|
||||
);
|
||||
expect(recovered).toEqual({ kind: "unrecoverable" });
|
||||
expect(
|
||||
resolveLaunchRegexWorkerHeap(recovered, {
|
||||
kind: "recovered",
|
||||
value: undefined,
|
||||
}),
|
||||
).toEqual({ kind: "unknown" });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
const directory = await createTestTempDirectory("rea-regex-title-flag-");
|
||||
const reported = spawnCommandLineReport(
|
||||
directory,
|
||||
["--title=rea", "--max-old-space-size=64"],
|
||||
undefined,
|
||||
);
|
||||
const pinned = probeWorkerHeap(["--max-old-space-size=64"], undefined);
|
||||
expect(reported.resourceOld).toBe(128);
|
||||
expect(relativeHeapGap(reported.heap, pinned.heap)).toBeLessThan(0.05);
|
||||
const recovered = execArgvFromCommandLine(
|
||||
Buffer.from(reported.cmdline, "base64"),
|
||||
);
|
||||
expect(recovered).toEqual({ kind: "unrecoverable" });
|
||||
expect(
|
||||
resolveLaunchRegexWorkerHeap(recovered, {
|
||||
kind: "recovered",
|
||||
value: undefined,
|
||||
}),
|
||||
).toEqual({ kind: "unknown" });
|
||||
});
|
||||
|
||||
it("arms the worker timer with an overridden matching deadline", async () => {
|
||||
@@ -489,8 +466,8 @@ it("stops a slow match at the configured deadline and names the setting", async
|
||||
});
|
||||
});
|
||||
|
||||
it("matches a trivial pattern in a real worker at the heap floor", () => {
|
||||
const directory = mkdtempSync(join(tmpdir(), "rea-regex-heap-floor-"));
|
||||
it("matches a trivial pattern in a real worker at the heap floor", async () => {
|
||||
const directory = await createTestTempDirectory("rea-regex-heap-floor-");
|
||||
const probe = join(directory, "probe.mjs");
|
||||
const repository = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
const tsxApi = pathToFileURL(
|
||||
@@ -523,17 +500,13 @@ if (!result.ok) process.exitCode = 1;
|
||||
);
|
||||
const env = { ...process.env };
|
||||
delete env.NODE_OPTIONS;
|
||||
try {
|
||||
const result = spawnSync(process.execPath, [probe], {
|
||||
env,
|
||||
encoding: "utf8",
|
||||
timeout: 30_000,
|
||||
});
|
||||
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
||||
expect(JSON.parse(result.stdout)).toEqual({ ok: true, indices: [0] });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
const result = spawnSync(process.execPath, [probe], {
|
||||
env,
|
||||
encoding: "utf8",
|
||||
timeout: 30_000,
|
||||
});
|
||||
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
||||
expect(JSON.parse(result.stdout)).toEqual({ ok: true, indices: [0] });
|
||||
});
|
||||
|
||||
it("preserves Unicode matching order and refuses a pre-cancelled match", async () => {
|
||||
|
||||
@@ -5,7 +5,10 @@ import { AnalysisResourceConstraintError } from "../../../src/domain/analysisErr
|
||||
import type { AnalysisError } from "../../../src/domain/analysisErrorBase.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { redactExplicitFailure } from "../../../src/domain/explicitSensitiveFailure.js";
|
||||
import { fixedAllowanceOptions } from "../../../src/domain/fixedAllowanceRemediation.js";
|
||||
import {
|
||||
fixedAllowanceOptions,
|
||||
fixedAllowanceRemediation,
|
||||
} from "../../../src/domain/fixedAllowanceRemediation.js";
|
||||
import { analysisClientFailureForOperation } from "../../../src/providers/AnalysisClientFailure.js";
|
||||
|
||||
const refusal = () =>
|
||||
@@ -50,8 +53,9 @@ it.each([
|
||||
remediation: { action: expect.stringContaining(allowance) },
|
||||
details: { reported_limits: { maximum_decoded_bytes: 64 } },
|
||||
});
|
||||
expect(projected.remediation.action).toMatch(/host memory do not raise/iu);
|
||||
expect(projected.remediation.action).toMatch(/unchanged request.*fails/iu);
|
||||
expect(projected.remediation.action).toBe(
|
||||
fixedAllowanceRemediation(allowance, "parser"),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -316,11 +316,6 @@ it("reports missing and ambiguous xref names within Kuna's inventory", async ()
|
||||
expect(ambiguousProjection).toMatchObject({
|
||||
code: "invalid_request",
|
||||
message: expect.stringMatching(/puts.*2 Kuna entries/iu),
|
||||
remediation: {
|
||||
action: expect.stringMatching(
|
||||
/address.*exactly one of the 2 candidates.*retry xrefs/iu,
|
||||
),
|
||||
},
|
||||
details: {
|
||||
refusal: {
|
||||
kind: "ambiguous_selector",
|
||||
|
||||
@@ -46,11 +46,6 @@ it.each([1, 129])(
|
||||
retryable: false,
|
||||
message: expect.stringMatching(/PyInstaller.*PYZ.*128.file.*budget/iu),
|
||||
details: { boundary: "capacity" },
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"capacity reported in details.detail",
|
||||
),
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).not.toContain(
|
||||
"Narrow the requested path",
|
||||
|
||||
@@ -96,8 +96,16 @@ it("does not recommend a timer above the supported maximum", () => {
|
||||
sqliteDatabaseDialect("/selected.db", "worker", undefined, 2_147_483_647),
|
||||
),
|
||||
);
|
||||
expect(failure.details).toMatchObject({ timeout_ms: 2_147_483_647 });
|
||||
expect(failure.remediation.action).toContain("no higher worker deadline");
|
||||
expect(failure.details).toMatchObject({
|
||||
timeout_ms: 2_147_483_647,
|
||||
limit: {
|
||||
control_kind: "parameter",
|
||||
parameter: "worker_timeout_ms",
|
||||
effective_value: 2_147_483_647,
|
||||
maximum: 2_147_483_647,
|
||||
applies_at: "next_call",
|
||||
},
|
||||
});
|
||||
expect(failure.remediation.action).not.toContain("Increase");
|
||||
});
|
||||
|
||||
@@ -116,12 +124,17 @@ it("reports exceeded diagnostic capture as a fixed resource constraint", () => {
|
||||
reported_limits: {
|
||||
diagnostic_capture_bytes: SQLITE_DATABASE_LIMITS.diagnosticBytes,
|
||||
},
|
||||
refusal: {
|
||||
kind: "fixed_ceiling",
|
||||
allowance_kind: "capture",
|
||||
limit: SQLITE_DATABASE_LIMITS.diagnosticBytes,
|
||||
unit: "bytes",
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).toContain(
|
||||
String(SQLITE_DATABASE_LIMITS.diagnosticBytes),
|
||||
);
|
||||
expect(projected.remediation.action).toContain("no runtime override");
|
||||
expect(projected.remediation.action).toContain(
|
||||
"worker_timeout_ms does not raise it",
|
||||
);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { spawnFailure } from "../support/process/spawnFailure.js";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { expect, it, vi } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
||||
import { ReverseEngineeringService } from "../../src/application/reverse/ReverseEngineeringService.js";
|
||||
import { analysisErrorProjectionSchema } from "../../src/domain/analysisErrorProjectionSchema.js";
|
||||
import { projectAnalysisError } from "../../src/domain/analysisErrorProjection.js";
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "../support/reverseEngineeringCompositionFixtures.js";
|
||||
|
||||
it("uses provider profiles supplied through the application port", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-port-"));
|
||||
const directory = await createTestTempDirectory("rea-reverse-port-");
|
||||
const path = join(directory, "fixture.bin");
|
||||
await writeFile(path, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
|
||||
const run = vi.fn<typeof runOwnedCommand>(async () =>
|
||||
@@ -49,24 +49,20 @@ it("uses provider profiles supplied through the application port", async () => {
|
||||
runOwned: run,
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "file_headers",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
const spawn = run.mock.calls[0]?.[0];
|
||||
expect(spawn?.command).toBe("injected-objdump");
|
||||
expect(spawn?.arguments).toEqual(["--injected", path]);
|
||||
expect(spawn?.env?.INJECTED_PROFILE).toBe("yes");
|
||||
if (result.ok) expect(result.value.provider.id).toBe("test.objdump");
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "file_headers",
|
||||
});
|
||||
expect(result.ok).toBe(true);
|
||||
const spawn = run.mock.calls[0]?.[0];
|
||||
expect(spawn?.command).toBe("injected-objdump");
|
||||
expect(spawn?.arguments).toEqual(["--injected", path]);
|
||||
expect(spawn?.env?.INJECTED_PROFILE).toBe("yes");
|
||||
if (result.ok) expect(result.value.provider.id).toBe("test.objdump");
|
||||
});
|
||||
|
||||
it("does not reintroduce ambient variables absent from the captured provider environment", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "rea-reverse-env-"));
|
||||
const directory = await createTestTempDirectory("rea-reverse-env-");
|
||||
const path = join(directory, "fixture.bin");
|
||||
const variable = "REA_TEST_LATE_PROVIDER_ENV";
|
||||
const previous = process.env[variable];
|
||||
@@ -110,13 +106,12 @@ it("does not reintroduce ambient variables absent from the captured provider env
|
||||
} finally {
|
||||
if (previous === undefined) delete process.env[variable];
|
||||
else process.env[variable] = previous;
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("projects missing and non-file objdump targets with actionable path reasons", async () => {
|
||||
const directory = await mkdtemp(
|
||||
join(tmpdir(), "rea-reverse-invalid-target-"),
|
||||
const directory = await createTestTempDirectory(
|
||||
"rea-reverse-invalid-target-",
|
||||
);
|
||||
const missing = join(directory, "missing.bin");
|
||||
const run = vi.fn(async () => ownedOutput());
|
||||
@@ -144,49 +139,46 @@ it("projects missing and non-file objdump targets with actionable path reasons",
|
||||
runOwned: run,
|
||||
});
|
||||
|
||||
try {
|
||||
for (const [path, reason] of [
|
||||
[missing, "not found"],
|
||||
[directory, "not a regular file"],
|
||||
] as const) {
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (result.ok) throw new Error("Expected target validation failure");
|
||||
const projection = projectAnalysisError(result.error);
|
||||
expect(analysisErrorProjectionSchema.safeParse(projection).success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(projection).toMatchObject({
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
retryable: false,
|
||||
message: expect.stringContaining(path),
|
||||
remediation: {
|
||||
action: expect.stringContaining("Correct the listed fields"),
|
||||
},
|
||||
details: {
|
||||
operation: "inspect_with_objdump",
|
||||
issues: [
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining(reason),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
for (const [path, reason] of [
|
||||
[missing, "not found"],
|
||||
[directory, "not a regular file"],
|
||||
] as const) {
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (result.ok) throw new Error("Expected target validation failure");
|
||||
const projection = projectAnalysisError(result.error);
|
||||
expect(analysisErrorProjectionSchema.safeParse(projection).success).toBe(
|
||||
true,
|
||||
);
|
||||
expect(projection).toMatchObject({
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
retryable: false,
|
||||
message: expect.stringContaining(path),
|
||||
recovery: {
|
||||
kind: "inspect_input_contract",
|
||||
operation: "inspect_with_objdump",
|
||||
},
|
||||
details: {
|
||||
operation: "inspect_with_objdump",
|
||||
issues: [
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining(reason),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps target preflight I/O failures out of invalid-input classification", async () => {
|
||||
const directory = await mkdtemp(
|
||||
join(tmpdir(), "rea-reverse-target-io-failure-"),
|
||||
const directory = await createTestTempDirectory(
|
||||
"rea-reverse-target-io-failure-",
|
||||
);
|
||||
const path = join(directory, "fixture.bin");
|
||||
await writeFile(path, Buffer.from([0x7f, 0x45, 0x4c, 0x46]));
|
||||
@@ -222,32 +214,28 @@ it("keeps target preflight I/O failures out of invalid-input classification", as
|
||||
runOwned: run,
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (result.ok) throw new Error("Expected target preflight I/O failure");
|
||||
expect(result.error).toMatchObject({
|
||||
_tag: "ProviderAdapterError",
|
||||
cause: ioFailure,
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (result.ok) throw new Error("Expected target preflight I/O failure");
|
||||
expect(result.error).toMatchObject({
|
||||
_tag: "ProviderAdapterError",
|
||||
cause: ioFailure,
|
||||
diagnostics: { phase: "target_preflight", system_code: "EIO" },
|
||||
});
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "execution_failure",
|
||||
category: "execution_failure",
|
||||
retryable: false,
|
||||
details: {
|
||||
provider_id: "test.objdump",
|
||||
operation: "inspect_with_objdump",
|
||||
diagnostics: { phase: "target_preflight", system_code: "EIO" },
|
||||
});
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "execution_failure",
|
||||
category: "execution_failure",
|
||||
retryable: false,
|
||||
details: {
|
||||
provider_id: "test.objdump",
|
||||
operation: "inspect_with_objdump",
|
||||
diagnostics: { phase: "target_preflight", system_code: "EIO" },
|
||||
},
|
||||
});
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
expect(stat).toHaveBeenCalledOnce();
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
},
|
||||
});
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
expect(stat).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -256,8 +244,8 @@ it.each([
|
||||
])(
|
||||
"classifies selected target $code as correctable input",
|
||||
async ({ code, reason }) => {
|
||||
const directory = await mkdtemp(
|
||||
join(tmpdir(), "rea-reverse-target-path-error-"),
|
||||
const directory = await createTestTempDirectory(
|
||||
"rea-reverse-target-path-error-",
|
||||
);
|
||||
const path = join(directory, "fixture.bin");
|
||||
const pathFailure = Object.assign(new Error(`stat failed: ${code}`), {
|
||||
@@ -292,37 +280,33 @@ it.each([
|
||||
runOwned: run,
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (result.ok) throw new Error(`Expected ${code} target path failure`);
|
||||
expect(result.error).toMatchObject({
|
||||
_tag: "AnalysisInputError",
|
||||
cause: pathFailure,
|
||||
});
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
retryable: false,
|
||||
message: expect.stringContaining(path),
|
||||
details: {
|
||||
operation: "inspect_with_objdump",
|
||||
issues: [
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining(reason),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
expect(stat).toHaveBeenCalledOnce();
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true });
|
||||
}
|
||||
const result = await service.inspectWithObjdump({
|
||||
path,
|
||||
operation: "symbols",
|
||||
});
|
||||
if (result.ok) throw new Error(`Expected ${code} target path failure`);
|
||||
expect(result.error).toMatchObject({
|
||||
_tag: "AnalysisInputError",
|
||||
cause: pathFailure,
|
||||
});
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
category: "invalid_input",
|
||||
retryable: false,
|
||||
message: expect.stringContaining(path),
|
||||
details: {
|
||||
operation: "inspect_with_objdump",
|
||||
issues: [
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_value",
|
||||
message: expect.stringContaining(reason),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(run).not.toHaveBeenCalled();
|
||||
expect(stat).toHaveBeenCalledOnce();
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -125,9 +125,7 @@ it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)(
|
||||
},
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
),
|
||||
action: expect.stringContaining("REA_OBJDUMP_COMMAND"),
|
||||
},
|
||||
});
|
||||
expect(projected.message).toContain(code);
|
||||
@@ -180,9 +178,7 @@ it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)(
|
||||
},
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"REA_RIZIN_COMMAND does not need to change",
|
||||
),
|
||||
action: expect.stringContaining("REA_RIZIN_COMMAND"),
|
||||
},
|
||||
});
|
||||
expect(projected.message).toContain(code);
|
||||
@@ -225,9 +221,7 @@ it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)(
|
||||
},
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
),
|
||||
action: expect.stringContaining("REA_OBJDUMP_COMMAND"),
|
||||
},
|
||||
});
|
||||
expect(projected.message).toContain(code);
|
||||
@@ -272,9 +266,7 @@ it.each(["EAGAIN", "EMFILE", "ENFILE", "ENOMEM"] as const)(
|
||||
},
|
||||
},
|
||||
remediation: {
|
||||
action: expect.stringContaining(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
),
|
||||
action: expect.stringContaining("REA_OBJDUMP_COMMAND"),
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -370,9 +362,7 @@ it("preserves Darwin process ownership inspection preparation error without blam
|
||||
expect(projected.remediation.action).toContain(
|
||||
DARWIN_PROCESS_OWNERSHIP_REMEDIATION,
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_OBJDUMP_COMMAND");
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toEqual({});
|
||||
} finally {
|
||||
@@ -416,9 +406,7 @@ it("preserves Darwin process ownership inspection error with cleanup state witho
|
||||
expect(projected.remediation.action).toContain(
|
||||
DARWIN_PROCESS_OWNERSHIP_REMEDIATION,
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_RIZIN_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_RIZIN_COMMAND");
|
||||
expect(result.error.cleanupIncomplete).toBe(true);
|
||||
expect(result.error.cleanup).toEqual(cleanupError.cleanup);
|
||||
}
|
||||
@@ -603,9 +591,7 @@ it("uses platform-aware recovery without /proc when Darwin baseline capture reje
|
||||
),
|
||||
);
|
||||
expect(projected.remediation.action).not.toContain("/proc");
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_OBJDUMP_COMMAND");
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toEqual({});
|
||||
} finally {
|
||||
@@ -657,9 +643,7 @@ it("preserves Darwin baseline_unavailable admission failure without blaming conf
|
||||
processOwnershipAdmissionRecovery("baseline_unavailable", "darwin"),
|
||||
);
|
||||
expect(projected.remediation.action).not.toContain("/proc");
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_OBJDUMP_COMMAND");
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toEqual({});
|
||||
} finally {
|
||||
@@ -692,9 +676,7 @@ it("preserves provider-launch ENOENT when configured command path contains ps su
|
||||
system_code: "ENOENT",
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).toContain(
|
||||
"Set REA_OBJDUMP_COMMAND to an installed executable GNU objdump command",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_OBJDUMP_COMMAND");
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toMatchObject({
|
||||
inspect_with_objdump: {
|
||||
@@ -748,9 +730,7 @@ it.each(["identity_snapshot_unavailable", "baseline_unavailable"] as const)(
|
||||
expect(projected.remediation.action).toContain(
|
||||
processOwnershipAdmissionRecovery(code, process.platform),
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_OBJDUMP_COMMAND");
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toEqual({});
|
||||
} finally {
|
||||
@@ -798,9 +778,7 @@ it("preserves host process ownership admission failure in baseline capture witho
|
||||
process.platform,
|
||||
),
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_RIZIN_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_RIZIN_COMMAND");
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toEqual({});
|
||||
} finally {
|
||||
@@ -1249,9 +1227,7 @@ it("preserves provider-launch ENOENT for a real execute_rizin_command target and
|
||||
system_code: "ENOENT",
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).toContain(
|
||||
"Set REA_RIZIN_COMMAND to an installed executable Rizin command",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_RIZIN_COMMAND");
|
||||
}
|
||||
expect(service.observedLaunchFailures()).toMatchObject({
|
||||
execute_rizin_command: {
|
||||
@@ -1300,9 +1276,7 @@ it("keeps Windows native runner load and self-test failures out of command-launc
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_OBJDUMP_COMMAND");
|
||||
expect(projected.remediation.action).not.toContain(
|
||||
"Set REA_OBJDUMP_COMMAND",
|
||||
);
|
||||
@@ -1399,9 +1373,7 @@ it("keeps Windows process_spawn host-control rejections out of command-launch st
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_OBJDUMP_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_OBJDUMP_COMMAND");
|
||||
expect(projected.remediation.action).not.toContain(
|
||||
"Set REA_OBJDUMP_COMMAND",
|
||||
);
|
||||
@@ -1438,9 +1410,7 @@ it("keeps Windows process_spawn host-control rejections out of command-launch st
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(projected.remediation.action).toContain(
|
||||
"REA_RIZIN_COMMAND does not need to change",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("REA_RIZIN_COMMAND");
|
||||
expect(projected.remediation.action).not.toContain(
|
||||
"Set REA_RIZIN_COMMAND",
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user