diff --git a/src/android/JadxOperationTimeout.test.ts b/src/android/JadxOperationTimeout.test.ts index 707cbd67b3..9a233b9cb6 100644 --- a/src/android/JadxOperationTimeout.test.ts +++ b/src/android/JadxOperationTimeout.test.ts @@ -23,9 +23,6 @@ it("names REA_JADX_OPERATION_TIMEOUT_MS when the operation deadline elapses", () ); expect(projected.remediation.action).toContain("update_analysis_settings"); expect(projected.remediation.action).toContain("jadx.operation_timeout_ms"); - expect(projected.remediation.action).toContain( - "next operation without restarting REA", - ); expect(projected.details).toMatchObject({ limit: { setting: "jadx.operation_timeout_ms", diff --git a/src/apkSignature/apkSignatureFailures.test.ts b/src/apkSignature/apkSignatureFailures.test.ts index bf81596ca6..f01fc36e36 100644 --- a/src/apkSignature/apkSignatureFailures.test.ts +++ b/src/apkSignature/apkSignatureFailures.test.ts @@ -50,8 +50,7 @@ it.each([ details: { reported_limits: { [key]: limit } }, }); expect(projected.remediation.action).toContain(String(limit)); - expect(projected.remediation.action).toContain("no runtime override"); - expect(projected.remediation.action).toMatch(/unchanged request.*fails/iu); + expect(projected.details?.refusal).toMatchObject({ kind: "fixed_ceiling" }); expect(projected.remediation.action).not.toContain( "Wait for an active analysis to complete", ); diff --git a/src/apktool/ApktoolDecodeTimeout.test.ts b/src/apktool/ApktoolDecodeTimeout.test.ts index ed0d7d1dd1..6459bb1bd1 100644 --- a/src/apktool/ApktoolDecodeTimeout.test.ts +++ b/src/apktool/ApktoolDecodeTimeout.test.ts @@ -1,7 +1,7 @@ import { MAX_NODE_TIMER_DELAY_MS } from "../domain/analysisResourceLimits.js"; -import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; -import { tmpdir } from "node:os"; +import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; +import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js"; import { afterEach, expect, it, vi } from "vitest"; import { ApktoolResourceAnalysisService } from "../application/apktool/ApktoolResourceAnalysisService.js"; @@ -100,7 +100,7 @@ const decode = async ( ); it("applies the omitted 600000 ms decode deadline and a selected value on the next decode", async () => { - const root = await mkdtemp(join(tmpdir(), "rea-apktool-deadline-")); + const root = await createTestTempDirectory("rea-apktool-deadline-"); const path = join(root, "probe.apk"); await writeFile(path, "apk-bytes"); installLauncher(); @@ -139,7 +139,9 @@ it("applies the omitted 600000 ms decode deadline and a selected value on the ne expect(projected.remediation.action).toContain( String(MAX_NODE_TIMER_DELAY_MS), ); - expect(projected.remediation.action).toContain("600000"); + expect(projected.remediation.action).toContain( + String(DEFAULT_APKTOOL_DECODE_TIMEOUT_MS), + ); expect(projected.remediation.action).toContain("next decode"); expect(projected.remediation.action).toContain("no runtime override"); expect(decodeTimeouts).toEqual([DEFAULT_APKTOOL_DECODE_TIMEOUT_MS, 200]); @@ -158,11 +160,12 @@ it("applies the omitted 600000 ms decode deadline and a selected value on the ne const maximum = await decode(provider, path, MAX_NODE_TIMER_DELAY_MS); if (maximum.ok) throw new Error("Expected the maximum decode deadline"); - expect(projectAnalysisError(maximum.error).remediation.action).toContain( - "do not increase it further", - ); + expect(projectAnalysisError(maximum.error).details?.limit).toMatchObject({ + parameter: "decode_timeout_ms", + effective_value: MAX_NODE_TIMER_DELAY_MS, + maximum: MAX_NODE_TIMER_DELAY_MS, + }); } finally { await provider.close(); - await rm(root, { recursive: true, force: true }); } }); diff --git a/src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts b/src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts index 7741f0c25a..1992ab5203 100644 --- a/src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts +++ b/src/application/javascript/JavaScriptSemanticGraphBuilder.test.ts @@ -1100,11 +1100,14 @@ it("attributes an adopted file to the ceiling that bounded its offer", () => { let step = steps.next(); while (!step.done) step = steps.next(); projection.adoptFileProjection(step.value); - const limitation = projection - .finish(SHA256, semanticApplication) - .limitations.join("\n"); - expect(limitation).toContain("max_semantic_nodes_per_file is 3"); - expect(limitation).not.toContain("max_semantic_nodes is 10"); + const finished = projection.finish(SHA256, semanticApplication); + expect(finished.coverage.controls).toEqual([ + expect.objectContaining({ + parameter: "max_semantic_nodes_per_file", + effective_value: 3, + applies_at: "next_call", + }), + ]); }); it("reports truncation only when a file exceeds its exact node budget", () => { diff --git a/src/browser/history/HistoricalCaptureBudgets.test.ts b/src/browser/history/HistoricalCaptureBudgets.test.ts index eefc37d004..aca4e46ab1 100644 --- a/src/browser/history/HistoricalCaptureBudgets.test.ts +++ b/src/browser/history/HistoricalCaptureBudgets.test.ts @@ -188,8 +188,13 @@ it("reserves reply and Evidence nesting before accepting a deep capture policy", throw new Error("Capture exceeded its selected nesting allowance"); expect(projectAnalysisError(exhausted.error)).toMatchObject({ details: { - diagnostics: { budget: { effective_value: 996, maximum: 996 } }, + diagnostics: { + budget: { + parameter: "max_nesting_depth", + effective_value: 996, + maximum: 996, + }, + }, }, - remediation: { action: expect.stringContaining("at its maximum") }, }); }); diff --git a/src/config/captureDecoderHeap.test.ts b/src/config/captureDecoderHeap.test.ts index 33f23e80a2..780c81b296 100644 --- a/src/config/captureDecoderHeap.test.ts +++ b/src/config/captureDecoderHeap.test.ts @@ -1,6 +1,6 @@ -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 { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js"; import { expect, it, vi } from "vitest"; @@ -23,7 +23,10 @@ import { parseCaptureDecoderHeap, resolveCaptureDecoderHeap, } from "./captureDecoderHeap.js"; -import { MAXIMUM_CAPTURE_DECODER_OLD_GENERATION_MIB } from "../domain/analysisResourceLimits.js"; +import { + CAPTURE_DECODER_SEMI_SPACE_MIB, + MAXIMUM_CAPTURE_DECODER_OLD_GENERATION_MIB, +} from "../domain/analysisResourceLimits.js"; const configured = (oldGenerationMiB: number) => ({ oldGenerationMiB, source: "setting" }) as const; @@ -105,13 +108,10 @@ it("uses a valid REA_CAPTURE_DECODER_OLD_GENERATION_MIB override", async () => { code: "resource_constraint", details: { resource: "memory" }, }); - expect(projected.remediation.action).toMatch( - /REA_CAPTURE_DECODER_OLD_GENERATION_MIB.*256 MiB.*source setting/iu, + expect(projected.remediation.action).toContain( + "REA_CAPTURE_DECODER_OLD_GENERATION_MIB", ); expect(projected.remediation.action).toContain("--max-old-space-size=256"); - expect(projected.remediation.action).toMatch( - /floor 8 MiB.*maximum 16384 MiB/iu, - ); expect(projected.remediation.action).toContain("update_analysis_settings"); expect(projected.remediation.action).toContain("launch seed"); expect(projected.remediation.action).toContain( @@ -136,6 +136,8 @@ it("uses a valid REA_CAPTURE_DECODER_OLD_GENERATION_MIB override", async () => { agent_editable: true, update_mode: "runtime", pending_restart: false, + minimum: CAPTURE_DECODER_SEMI_SPACE_MIB, + maximum: MAXIMUM_CAPTURE_DECODER_OLD_GENERATION_MIB, }, reported_limits: { old_generation_heap_mib: 256, @@ -164,7 +166,7 @@ it("reports the heap the selected adapter launches when decoder environment diff const other = new NodeCaptureAdapter("saz", { REA_CAPTURE_DECODER_OLD_GENERATION_MIB: "512", }); - const root = await mkdtemp(join(tmpdir(), "rea-capture-heap-report-")); + const root = await createTestTempDirectory("rea-capture-heap-report-"); const capturePath = join(root, "input.har"); const text = JSON.stringify(historicalHar()); await writeFile(capturePath, text); @@ -198,8 +200,8 @@ it("reports the heap the selected adapter launches when decoder environment diff if (exhausted.ok) throw new Error("Heap exhaustion must fail inspection"); const projected = projectAnalysisError(exhausted.error); expect(projected.code).toBe("resource_constraint"); - expect(projected.remediation.action).toMatch( - /REA_CAPTURE_DECODER_OLD_GENERATION_MIB.*256 MiB.*source setting/iu, + expect(projected.remediation.action).toContain( + "REA_CAPTURE_DECODER_OLD_GENERATION_MIB", ); expect(projected.remediation.action).toContain("--max-old-space-size=256"); if (process.versions.bun === undefined) @@ -216,7 +218,6 @@ it("reports the heap the selected adapter launches when decoder environment diff }); } finally { await decoder.close(); - await rm(root, { recursive: true, force: true }); } }); diff --git a/src/domain/analysisErrorProjection.test.ts b/src/domain/analysisErrorProjection.test.ts index 3752d853e3..a1f667cec7 100644 --- a/src/domain/analysisErrorProjection.test.ts +++ b/src/domain/analysisErrorProjection.test.ts @@ -363,9 +363,7 @@ it("projects a published file receipt alongside retained cleanup failure", () => code: "cleanup_incomplete", message: expect.stringMatching(/published.*staging cleanup.*incomplete/iu), remediation: { - action: expect.stringMatching( - /published.*details\.published_path.*cleanup/iu, - ), + action: expect.stringContaining("details.published_path"), }, details: { operation: "write", diff --git a/src/domain/analysisView/environmentCoverageView.test.ts b/src/domain/analysisView/environmentCoverageView.test.ts index 630b1f258d..1dc1cb042d 100644 --- a/src/domain/analysisView/environmentCoverageView.test.ts +++ b/src/domain/analysisView/environmentCoverageView.test.ts @@ -118,7 +118,7 @@ it("counts read tools by how they answer and lists writes as served or withheld tool: "put_folders_by_uid", effect: "update", reason: "contradicted", - hint: expect.stringMatching(/later read.*contradicted_by/iu), + hint: WITHHELD_WRITE_HINTS.contradicted, exemplar_ordinal: 4, contradicted_by: 9, }, @@ -191,9 +191,7 @@ it("does not claim reads are missing when a literal delete has no modelled targe expect.arrayContaining([ expect.objectContaining({ reason: "no-state-target", - hint: expect.stringContaining( - "could not be linked to a modelled state target", - ), + hint: WITHHELD_WRITE_HINTS["no-state-target"], }), ]), ); diff --git a/src/domain/javascript/javascriptAnalysisResourceControls.test.ts b/src/domain/javascript/javascriptAnalysisResourceControls.test.ts index a48e28cc8c..eabf133893 100644 --- a/src/domain/javascript/javascriptAnalysisResourceControls.test.ts +++ b/src/domain/javascript/javascriptAnalysisResourceControls.test.ts @@ -176,7 +176,6 @@ it("names the four semantic arguments on ceiling coverage", () => { expect(nodes.limitation).toContain(String(JAVASCRIPT_SEMANTIC_ITEM_MAXIMUM)); // The producer records controls by contract field; adapters name options. expect(nodes.limitation).not.toContain("--"); - expect(nodes.limitation).toContain("coverage.controls records them"); expect(nodes.controls).toEqual([ { control_kind: "parameter", @@ -194,33 +193,38 @@ it("names the four semantic arguments on ceiling coverage", () => { default_value: JAVASCRIPT_ANALYSIS_RESOURCE_DEFAULTS.semanticNodesPerFile, }), ]); - expect(nodes.limitation).toContain( - "Set max_semantic_nodes and max_semantic_nodes_per_file", - ); expect(nodes.limitation).toContain("Raising them does not raise"); - expect(nodes.limitation).toContain("next analysis"); expect(unknowns.controls.map(({ parameter }) => parameter)).toEqual([ "max_semantic_unknowns", "max_semantic_unknowns_per_file", ]); expect(unknowns.limitation).toContain("max_semantic_nodes"); - expect(perFileOnly.limitation).toContain("max_semantic_nodes_per_file is 30"); - expect(perFileOnly.limitation).toContain( - "Set max_semantic_nodes_per_file on the next", - ); - expect(perFileOnly.controls.map(({ parameter }) => parameter)).toEqual([ - "max_semantic_nodes_per_file", + expect(perFileOnly.controls).toEqual([ + { + control_kind: "parameter", + parameter: "max_semantic_nodes_per_file", + effective_value: 30, + unit: "count", + minimum: 1, + maximum: JAVASCRIPT_SEMANTIC_ITEM_MAXIMUM, + default_value: JAVASCRIPT_ANALYSIS_RESOURCE_DEFAULTS.semanticNodesPerFile, + applies_at: "next_call", + }, ]); - expect(perFileOnly.limitation).toContain("coverage.controls records it"); expect(perFileOnly.limitation).toContain("Raising it does not raise"); expect(perFileOnly.limitation).not.toContain("max_semantic_nodes is 50"); - expect(totalOnly.limitation).toContain("max_semantic_unknowns is 3"); - expect(totalOnly.limitation).toContain( - "Set max_semantic_unknowns on the next", - ); - expect(totalOnly.controls.map(({ parameter }) => parameter)).toEqual([ - "max_semantic_unknowns", + expect(totalOnly.controls).toEqual([ + { + control_kind: "parameter", + parameter: "max_semantic_unknowns", + effective_value: 3, + unit: "count", + minimum: 1, + maximum: JAVASCRIPT_SEMANTIC_ITEM_MAXIMUM, + default_value: JAVASCRIPT_ANALYSIS_RESOURCE_DEFAULTS.semanticUnknowns, + applies_at: "next_call", + }, ]); expect(totalOnly.limitation).not.toContain( "max_semantic_unknowns_per_file is 2", @@ -232,7 +236,13 @@ it("names the four semantic arguments on ceiling coverage", () => { 30, { total: true, perFile: false }, ); - expect(capped.limitation).toContain("Do not increase it further"); + expect(capped.controls).toEqual([ + expect.objectContaining({ + parameter: "max_semantic_nodes", + effective_value: JAVASCRIPT_SEMANTIC_ITEM_MAXIMUM, + maximum: JAVASCRIPT_SEMANTIC_ITEM_MAXIMUM, + }), + ]); expect(capped.limitation).not.toContain("max_semantic_nodes_per_file is 30"); expect(() => javaScriptSemanticCeilingCoverage("nodes", 50, 30, { diff --git a/src/electron/ElectronFuseProvider.test.ts b/src/electron/ElectronFuseProvider.test.ts index f80a765297..13b60d1883 100644 --- a/src/electron/ElectronFuseProvider.test.ts +++ b/src/electron/ElectronFuseProvider.test.ts @@ -903,9 +903,6 @@ it("rejects a sparse artifact over 1 GiB before scanning", async () => { unit: "bytes", }, }, - remediation: { - action: expect.stringContaining("does not admit this input"), - }, }); } }); diff --git a/src/evm/EvmoleFailures.test.ts b/src/evm/EvmoleFailures.test.ts index 525824462d..2af99d2aa4 100644 --- a/src/evm/EvmoleFailures.test.ts +++ b/src/evm/EvmoleFailures.test.ts @@ -120,12 +120,12 @@ it("names timeout_ms, the omitted default, and the caps it does not raise", () = parameter: "timeout_ms", effective_value: 45_000, default_value: DEFAULT_EVM_TIMEOUT_MS, + applies_at: "next_call", }); expect(projected.remediation.action).toContain( String(MAX_NODE_TIMER_DELAY_MS), ); expect(projected.remediation.action).toContain("does not raise"); - expect(projected.remediation.action).toContain("no server restart"); }); it("names the selected CPU budget separately from tighter inherited limits", () => { diff --git a/src/ghidra/GhidraProvider.behavior.test.ts b/src/ghidra/GhidraProvider.behavior.test.ts index 787b1cb32f..186118a85c 100644 --- a/src/ghidra/GhidraProvider.behavior.test.ts +++ b/src/ghidra/GhidraProvider.behavior.test.ts @@ -52,8 +52,9 @@ import { createHash } from "node:crypto"; import { execFile } from "node:child_process"; // Fake-backed provider coverage; real Ghidra verification lives in // `npm run verify:ghidra` and its focused variants. -import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; -import { tmpdir } from "node:os"; +import { mkdir, readFile, writeFile } from "node:fs/promises"; +import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js"; +import { DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS } from "../domain/analysisResourceLimits.js"; import { join } from "node:path"; import { fileURLToPath } from "node:url"; import { promisify } from "node:util"; @@ -192,8 +193,8 @@ const createElfClient = async (ghidra: GhidraProvider) => { it.each(["mixed-inspection", "held-inspection", "ordinary-launch"] as const)( "preserves public %s failure through a real client", async (kind) => { - const root = await mkdtemp( - join(tmpdir(), "rea-ghidra-inspection-projection-"), + const root = await createTestTempDirectory( + "rea-ghidra-inspection-projection-", ); const path = join(root, "inert.elf"); const bytes = elf(2, 1, 62); @@ -311,7 +312,6 @@ it.each(["mixed-inspection", "held-inspection", "ordinary-launch"] as const)( } finally { held?.allow(); await client.close(); - await rm(root, { recursive: true, force: true }); } }, ); @@ -828,10 +828,9 @@ describe("Ghidra platform support", () => { ] as const)( "records explicit Windows $architecture processor selection without claiming loader selection", async ({ architecture, languageId }) => { - const directory = await mkdtemp( - join(tmpdir(), "rea-arm-profile-language-"), + const directory = await createTestTempDirectory( + "rea-arm-profile-language-", ); - onTestFinished(() => rm(directory, { recursive: true, force: true })); const languages = join( directory, "Ghidra/Processors/fixture/data/languages", @@ -1317,7 +1316,7 @@ describe("Ghidra startup configuration", () => { it("carries supplied startup settings through configuration, the provider, the timer and timeout diagnostics", async () => { const target = executableTarget("elf", "x86_64"); for (const [raw, expected] of [ - [undefined, 330_000], + [undefined, DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS], ["900000", 900_000], ["1260000", 1_260_000], ["2147483647", 2_147_483_647], @@ -1380,8 +1379,7 @@ describe("Ghidra startup configuration", () => { }); it("reobserves value-flow budgets on the same session while ordinary address lookups stay cached", async () => { - const root = await mkdtemp(join(tmpdir(), "rea-ghidra-flow-budgets-")); - onTestFinished(() => rm(root, { recursive: true, force: true })); + const root = await createTestTempDirectory("rea-ghidra-flow-budgets-"); const path = join(root, "fixture.elf"); await writeFile(path, elf(2, 1, 62)); const parsed = parseConfig({ GHIDRA_INSTALL_DIR: INSTALL }); @@ -1824,7 +1822,7 @@ describe("Ghidra procedure lookup projection", () => { ); it("offers an explicit fresh import when the missing procedure came from a selected project", async () => { - const root = await mkdtemp(join(tmpdir(), "rea-missing-procedure-")); + const root = await createTestTempDirectory("rea-missing-procedure-"); await mkdir(join(root, "selected.rep")); await writeFile(join(root, "selected.gpr"), "marker"); const message = "Unknown Ghidra procedure name or address: missing"; @@ -1883,7 +1881,6 @@ describe("Ghidra procedure lookup projection", () => { } } finally { await ghidra.closeOwnedResources(); - await rm(root, { recursive: true, force: true }); } }); }); @@ -2246,17 +2243,11 @@ describe("Ghidra decompile deadline for a finished invocation", () => { REA_GHIDRA_DECOMPILE_TIMEOUT_SECONDS: String(seconds), }; if (source === "owned-checkpoint") { - const root = await mkdtemp(join(tmpdir(), "rea-deadline-checkpoint-")); - onTestFinished(async () => { - await rm(root, { recursive: true, force: true }); - }); + const root = await createTestTempDirectory("rea-deadline-checkpoint-"); environment.REA_GHIDRA_CHECKPOINT_DIR = root; } if (source === "existing-project") { - const root = await mkdtemp(join(tmpdir(), "rea-deadline-project-")); - onTestFinished(async () => { - await rm(root, { recursive: true, force: true }); - }); + const root = await createTestTempDirectory("rea-deadline-project-"); await mkdir(join(root, "saved.rep")); await writeFile(join(root, "saved.gpr"), "marker"); environment.REA_GHIDRA_PROJECT_PATH = join(root, "saved.gpr"); @@ -2726,8 +2717,7 @@ it("compares measured COM import evidence against the loader committed at admiss const { bytes, sha256 } = fixtureDosComLoaderLoadImage(); const { observation } = fixtureDosComLoadImage(bytes); observation.source_files[0]!.name = "fixture.bin"; - const root = await mkdtemp(join(tmpdir(), "rea-ghidra-com-selection-")); - onTestFinished(() => rm(root, { recursive: true, force: true })); + const root = await createTestTempDirectory("rea-ghidra-com-selection-"); const path = join(root, "fixture.com"); await writeFile(path, bytes); const ghidra = provider(installationHost(), () => ({ @@ -4468,98 +4458,94 @@ describe("Ghidra extension failures", () => { it.each(["unsupported", "failed", "malformed"] as const)( "preserves %s recovery diagnostics and closes without restarting", async (status) => { - const directory = await mkdtemp( - join(tmpdir(), "rea-provider-extension-"), + const directory = await createTestTempDirectory( + "rea-provider-extension-", ); - try { - const jar = join(directory, "addon.jar"); - await writeFile(jar, Buffer.from([0x50, 0x4b, 3, 4])); - const config = parseConfig({ - GHIDRA_INSTALL_DIR: INSTALL, - REA_GHIDRA_NATIVEAOT_JAR: jar, - }); - if (!config.ok) throw config.error; - let starts = 0, - calls = 0, - closes = 0; - const ghidra = new GhidraProvider( - config.value, - silentLogger, - {}, - installationHost(), - () => ({ - start: () => { - starts++; - return Promise.resolve( - ok({ - ...sessionInfo(), - analysis_extensions: [ - { + const jar = join(directory, "addon.jar"); + await writeFile(jar, Buffer.from([0x50, 0x4b, 3, 4])); + const config = parseConfig({ + GHIDRA_INSTALL_DIR: INSTALL, + REA_GHIDRA_NATIVEAOT_JAR: jar, + }); + if (!config.ok) throw config.error; + let starts = 0, + calls = 0, + closes = 0; + const ghidra = new GhidraProvider( + config.value, + silentLogger, + {}, + installationHost(), + () => ({ + start: () => { + starts++; + return Promise.resolve( + ok({ + ...sessionInfo(), + analysis_extensions: [ + { + id: "nativeaot", + sha256: + status === "malformed" + ? "0".repeat(64) + : createHash("sha256") + .update(Buffer.from([0x50, 0x4b, 3, 4])) + .digest("hex"), + status: status === "malformed" ? "failed" : status, + reason: + "directory-discovery: Unsupported layout at 0x401000", + result: { id: "nativeaot", - sha256: - status === "malformed" - ? "0".repeat(64) - : createHash("sha256") - .update(Buffer.from([0x50, 0x4b, 3, 4])) - .digest("hex"), + integration_api: 1, + source_revision: + "effeb734fc570c32650f88b159608979dc7b423e", + source_revision_authority: "build-reported-unattested", status: status === "malformed" ? "failed" : status, reason: "directory-discovery: Unsupported layout at 0x401000", - result: { - id: "nativeaot", - integration_api: 1, - source_revision: - "effeb734fc570c32650f88b159608979dc7b423e", - source_revision_authority: "build-reported-unattested", - status: status === "malformed" ? "failed" : status, - reason: - "directory-discovery: Unsupported layout at 0x401000", - method_tables: 0, - diagnostics: ["exact producer diagnostic"], - }, + method_tables: 0, + diagnostics: ["exact producer diagnostic"], }, - ], - }), - ); - }, - callTool: () => { - calls++; - return Promise.resolve(ok(null)); - }, - close: () => { - closes++; - return Promise.resolve(ok(null)); - }, - }), + }, + ], + }), + ); + }, + callTool: () => { + calls++; + return Promise.resolve(ok(null)); + }, + close: () => { + closes++; + return Promise.resolve(ok(null)); + }, + }), + ); + const target = executableTarget("elf", "x86_64"); + const resolved = await ghidra.resolveAnalysisProfile(target); + if (!resolved.ok || resolved.value.profile === null) + throw new Error("expected extension profile"); + const client = ghidra.createClient(target, resolved.value.profile); + const failed = await client.execute("health", {}); + expect(failed.ok).toBe(false); + if (!failed.ok) { + expect(failed.error._tag).toBe( + status === "unsupported" + ? "AnalysisCapabilityUnavailableError" + : "ProviderAdapterError", + ); + expect(JSON.stringify(failed.error)).toContain( + status === "malformed" + ? "identity mismatch" + : "Unsupported layout at 0x401000", ); - const target = executableTarget("elf", "x86_64"); - const resolved = await ghidra.resolveAnalysisProfile(target); - if (!resolved.ok || resolved.value.profile === null) - throw new Error("expected extension profile"); - const client = ghidra.createClient(target, resolved.value.profile); - const failed = await client.execute("health", {}); - expect(failed.ok).toBe(false); - if (!failed.ok) { - expect(failed.error._tag).toBe( - status === "unsupported" - ? "AnalysisCapabilityUnavailableError" - : "ProviderAdapterError", - ); - expect(JSON.stringify(failed.error)).toContain( - status === "malformed" - ? "identity mismatch" - : "Unsupported layout at 0x401000", - ); - } - expect(await client.execute("list_procedures", {})).toEqual(failed); - expect({ starts, calls, closes }).toEqual({ - starts: 1, - calls: 0, - closes: 1, - }); - } finally { - await rm(directory, { recursive: true, force: true }); } + expect(await client.execute("list_procedures", {})).toEqual(failed); + expect({ starts, calls, closes }).toEqual({ + starts: 1, + calls: 0, + closes: 1, + }); }, ); }); @@ -4740,23 +4726,20 @@ describe("Ghidra deadline guidance", () => { "REA_GHIDRA_DISABLED_ANALYZERS", ); expect(projected.remediation.action).toContain("REA_GHIDRA_PROJECT_PATH"); - expect(projected.remediation.action).toContain("without restarting REA"); expect(projected.remediation.action).toContain("Export useful Evidence"); expect(projected.details).toMatchObject({ limit: { setting: "ghidra.startup_timeout_ms", effective_value: 250, applies_at: "next_startup", + update_mode: "runtime", }, }); expect(projected.remediation.action).not.toContain("rea doctor"); }); it("describes an existing-project startup timeout without import or analyzer advice", async () => { - const root = await mkdtemp(join(tmpdir(), "rea-timeout-project-")); - onTestFinished(async () => { - await rm(root, { recursive: true, force: true }); - }); + const root = await createTestTempDirectory("rea-timeout-project-"); await mkdir(join(root, "large.rep")); await writeFile(join(root, "large.gpr"), "marker"); const projected = await ghidraTimedOut( @@ -4896,10 +4879,7 @@ describe("Ghidra startup deadline for a finished invocation", () => { async (existingProject) => { const environment: Record = {}; if (existingProject) { - const root = await mkdtemp(join(tmpdir(), "rea-timeout-project-")); - onTestFinished(async () => { - await rm(root, { recursive: true, force: true }); - }); + const root = await createTestTempDirectory("rea-timeout-project-"); await mkdir(join(root, "large.rep")); await writeFile(join(root, "large.gpr"), "marker"); environment.REA_GHIDRA_PROJECT_PATH = join(root, "large.gpr"); @@ -5006,10 +4986,7 @@ describe("Ghidra startup deadline for a finished invocation", () => { }); it("identifies checkpoint recovery for a timed-out startup", async () => { - const root = await mkdtemp(join(tmpdir(), "rea-startup-checkpoint-")); - onTestFinished(async () => { - await rm(root, { recursive: true, force: true }); - }); + const root = await createTestTempDirectory("rea-startup-checkpoint-"); for (const lifetime of ["invocation", "continuing"] as const) { const projected = await ghidraTimedOut( "start", @@ -5036,10 +5013,7 @@ const startFailure = async ( environment: Readonly> = {}, stderr = "", ) => { - const root = await mkdtemp(join(tmpdir(), "rea-missing-program-")); - onTestFinished(async () => { - await rm(root, { recursive: true, force: true }); - }); + const root = await createTestTempDirectory("rea-missing-program-"); await mkdir(join(root, "selected.rep")); await writeFile(join(root, "selected.gpr"), "marker"); const failure = new GhidraSessionError( @@ -5201,10 +5175,7 @@ describe("Ghidra missing project program", () => { describe("Ghidra changed project", () => { const launchFailure = async (cause: unknown, viaLauncher = true) => { - const root = await mkdtemp(join(tmpdir(), "rea-changed-project-")); - onTestFinished(async () => { - await rm(root, { recursive: true, force: true }); - }); + const root = await createTestTempDirectory("rea-changed-project-"); await mkdir(join(root, "selected.rep")); await writeFile(join(root, "selected.gpr"), "marker"); const failure = new GhidraSessionError( @@ -5301,7 +5272,7 @@ describe("Ghidra analysis seeds and configured language", () => { const seedSession = async ( report: (sha256: string) => GhidraSeedReport | undefined, ) => { - const directory = await mkdtemp(join(tmpdir(), "rea-provider-seeds-")); + const directory = await createTestTempDirectory("rea-provider-seeds-"); const seeds = join(directory, "seeds.tsv"); await writeFile(seeds, "0x401000\tfunction\tentry\n0x401010\tcode\n"); const config = parseConfig({ @@ -5347,7 +5318,6 @@ describe("Ghidra analysis seeds and configured language", () => { if (!resolved.ok || resolved.value.profile === null) throw new Error("expected seed profile"); return { - directory, counts, client: ghidra.createClient(target, resolved.value.profile), }; @@ -5367,21 +5337,17 @@ describe("Ghidra analysis seeds and configured language", () => { }); it("reports the verified seed outcome as a session limitation", async () => { - const { directory, client } = await seedSession(applied); - try { - const health = await client.execute("health", {}); - if (!health.ok) throw health.error; - expect(health.value.limitations).toEqual( - expect.arrayContaining([ - expect.stringContaining("caller assertions, not Ghidra discoveries"), - expect.stringContaining( - "1 functions created, 0 already present, 0 failed; 0 code seeds decoded, 1 failed", - ), - ]), - ); - } finally { - await rm(directory, { recursive: true, force: true }); - } + const { client } = await seedSession(applied); + const health = await client.execute("health", {}); + if (!health.ok) throw health.error; + expect(health.value.limitations).toEqual( + expect.arrayContaining([ + expect.stringContaining("caller assertions, not Ghidra discoveries"), + expect.stringContaining( + "1 functions created, 0 already present, 0 failed; 0 code seeds decoded, 1 failed", + ), + ]), + ); }); it.each([ @@ -5394,15 +5360,11 @@ describe("Ghidra analysis seeds and configured language", () => { }), ], ])("fails closed on %s before any analysis call", async (_label, report) => { - const { directory, counts, client } = await seedSession(report); - try { - const failed = await client.execute("list_procedures", {}); - expect(failed.ok).toBe(false); - if (!failed.ok) expect(failed.error._tag).toBe("ProviderAdapterError"); - expect(counts).toEqual({ starts: 1, calls: 0, closes: 1 }); - } finally { - await rm(directory, { recursive: true, force: true }); - } + const { counts, client } = await seedSession(report); + const failed = await client.execute("list_procedures", {}); + expect(failed.ok).toBe(false); + if (!failed.ok) expect(failed.error._tag).toBe("ProviderAdapterError"); + expect(counts).toEqual({ starts: 1, calls: 0, closes: 1 }); }); it("refuses a profile resolved without the configured seeds or language", async () => { @@ -7141,7 +7103,7 @@ it("reports an unsupported existing-project target as an invalid REA_GHIDRA_PROJ }); it("keeps saved project reports as shared historical Evidence without applying fresh overrides", async () => { - const root = await mkdtemp(join(tmpdir(), "rea-history-project-")); + const root = await createTestTempDirectory("rea-history-project-"); await mkdir(join(root, "history.rep")); await writeFile(join(root, "history.gpr"), "marker"); const prior = { @@ -7187,7 +7149,6 @@ it("keeps saved project reports as shared historical Evidence without applying f ); onTestFinished(async () => { await ghidra.closeOwnedResources(); - await rm(root, { recursive: true, force: true }); }); const target = executableTarget("elf", "x86_64"); const resolved = await ghidra.resolveAnalysisProfile(target); diff --git a/src/hopper/HopperErrorProjection.test.ts b/src/hopper/HopperErrorProjection.test.ts index 244f2e10f3..3e408f8e03 100644 --- a/src/hopper/HopperErrorProjection.test.ts +++ b/src/hopper/HopperErrorProjection.test.ts @@ -46,13 +46,11 @@ describe("analysis error projection: Hopper provider failures", () => { operation: "trace_feature", request_id: 42, provider_state: "busy", + retry_action: "wait", timeout_ms: 30_000, }, }); expect(projected.message).toContain("binary_session.analysis_activity"); - expect(projected.remediation.action).toContain( - "wait for the active Hopper request", - ); }); it("identifies the REA session that already owns a Hopper target", () => { @@ -65,9 +63,7 @@ describe("analysis error projection: Hopper provider failures", () => { category: "unavailable", message: expect.stringContaining("session-owner"), remediation: { - action: expect.stringContaining( - "Use the active REA session session-owner", - ), + action: expect.stringContaining("session-owner"), }, }); }); @@ -350,9 +346,11 @@ describe("analysis error projection: operational diagnostics", () => { expect(unreachable.message).toMatch( /unreachable.*process exit was not observed/iu, ); - expect(unreachable.remediation.action).toMatch( - /close_binary.*Evidence and Unknown history.*export_evidence_bundle/iu, + expect(unreachable.remediation.action).toContain("close_binary"); + expect(unreachable.remediation.action).toContain( + "Evidence and Unknown history", ); + expect(unreachable.remediation.action).toContain("export_evidence_bundle"); }); }); @@ -414,8 +412,16 @@ describe("analysis error projection: caller lifetime", () => { ), }, ); - expect(projectAnalysisError(error).remediation.action).toMatch( - /update_analysis_settings.*hopper\.startup_timeout_ms.*without restarting REA/u, + const continuing = projectAnalysisError(error); + expect(continuing.details?.limit).toMatchObject({ + setting: "hopper.startup_timeout_ms", + effective_value: 30_000, + applies_at: "next_startup", + update_mode: "runtime", + }); + expect(continuing.remediation.action).toContain("update_analysis_settings"); + expect(continuing.remediation.action).toContain( + "hopper.startup_timeout_ms", ); const invocation = projectAnalysisError(error, "invocation"); expect(invocation.remediation.action).toBe( diff --git a/src/java/MavenGradleMetadataParser.test.ts b/src/java/MavenGradleMetadataParser.test.ts index a2bc64448b..3d9760124f 100644 --- a/src/java/MavenGradleMetadataParser.test.ts +++ b/src/java/MavenGradleMetadataParser.test.ts @@ -848,8 +848,8 @@ it("reports the repeated variant-name refusal as a fixed report allowance", asyn expect(projectAnalysisError(result.error)).toMatchObject({ code: "resource_constraint", retryable: false, - remediation: { - action: expect.stringContaining("fixed report allowance"), + details: { + refusal: { kind: "fixed_ceiling", allowance_kind: "report" }, }, }); } finally { diff --git a/src/native/pwntools/PwntoolsFailures.test.ts b/src/native/pwntools/PwntoolsFailures.test.ts index 83bd3d4ac1..734dab809a 100644 --- a/src/native/pwntools/PwntoolsFailures.test.ts +++ b/src/native/pwntools/PwntoolsFailures.test.ts @@ -60,10 +60,8 @@ it("keeps the caller-selected pwntools input-limit source", () => { update_mode: "parameter", pending_restart: false, parameter: "producer_limits.input_bytes", + unit: "bytes", }); - expect(projected.remediation.action).toContain( - "producer_limits.input_bytes is 4096 bytes", - ); expect(projected.remediation.action).not.toContain("launch default of"); }); @@ -90,11 +88,9 @@ it("names a runtime pwntools ceiling instead of the built-in default", () => { expect(projected.details?.limit).toMatchObject({ effective_value: 67_108_864, source: "runtime", + unit: "bytes", update_mode: "runtime", }); - expect(projected.remediation.action).toContain( - "67108864 bytes (source runtime)", - ); expect(projected.remediation.action).toContain("update_analysis_settings"); expect(projected.message).not.toContain( "Selected producer_limits.input_bytes is", @@ -123,10 +119,10 @@ it("distinguishes the wall deadline from caller-selected producer resource budge parameter: "pwntools_timeout_ms", effective_value: 4_500, default_value: 30_000, + applies_at: "next_call", }); expect(projected.remediation.action).toContain("cpu_seconds=30"); expect(projected.remediation.action).toContain("producer_limits"); - expect(projected.remediation.action).toContain("no REA restart"); expect(projected.remediation.action).toContain("67108864"); }); @@ -234,13 +230,14 @@ it("binds diagnostic_bytes as the only control of the command output budget", () parameter: "producer_limits.diagnostic_bytes", effective_value: 64, default_value: 1048576, + applies_at: "next_call", }, }, }); // output_bytes bounds the reply file, not this budget. expect(projected.message).not.toContain("output_bytes"); expect(projected.remediation.action).toContain( - "Increase producer_limits.diagnostic_bytes above 64", + "producer_limits.diagnostic_bytes", ); expect(projected.remediation.action).not.toContain("--"); }); diff --git a/src/process/ArtifactAnalysisResources.test.ts b/src/process/ArtifactAnalysisResources.test.ts index 1b7289feb4..65bff6abfd 100644 --- a/src/process/ArtifactAnalysisResources.test.ts +++ b/src/process/ArtifactAnalysisResources.test.ts @@ -728,9 +728,6 @@ it("keeps an unchanged SIGXFSZ retry uncertain when the inherited limit was not undefined, ), ); - expect(projected.remediation.action).toContain( - "The effective inherited limit was not reported.", - ); expect(projected.remediation.action).toContain( "an unchanged retry may succeed or may fail the same way", ); @@ -774,13 +771,17 @@ it("treats a fixed command-output cap as a non-retryable capture allowance", asy fixedAllowance: { kind: "capture", limit: 1024, unit: "bytes" }, }); const projected = projectAnalysisError(error); - expect(projected.retryable).toBe(false); - expect(projected.remediation.action).toContain( - "The retained command-output allowance of 1024 bytes", - ); - expect(projected.remediation.action).toContain( - "this release has no runtime override", - ); + expect(projected).toMatchObject({ + retryable: false, + details: { + refusal: { + kind: "fixed_ceiling", + allowance_kind: "capture", + limit: 1024, + unit: "bytes", + }, + }, + }); expect(projected.remediation.action).not.toMatch( /Review the reported worker memory limits/u, ); diff --git a/src/resources/ArtifactOperationFailure.test.ts b/src/resources/ArtifactOperationFailure.test.ts index 7fe6ec4590..19d2f9ea93 100644 --- a/src/resources/ArtifactOperationFailure.test.ts +++ b/src/resources/ArtifactOperationFailure.test.ts @@ -243,7 +243,6 @@ it.each([ }, }, }); - expect(projected.remediation.action).toContain("No supported increase"); }, ); @@ -383,7 +382,6 @@ it("keeps a fixed reader ceiling's refusal through cleanup wrapping and public p retryable: false, details: { refusal, cleanup: "incomplete", resources: ["handle"] }, }); - expect(projected.remediation.action).toContain("The allowance is 64 records"); }); it("keeps producer-owned recovery through cleanup wrapping and public projection", () => { diff --git a/src/sqlite/SqliteDatabaseSnapshotLimits.test.ts b/src/sqlite/SqliteDatabaseSnapshotLimits.test.ts index bc2d4b0ae4..b92d6e2eac 100644 --- a/src/sqlite/SqliteDatabaseSnapshotLimits.test.ts +++ b/src/sqlite/SqliteDatabaseSnapshotLimits.test.ts @@ -1,15 +1,7 @@ -import { - lstat, - mkdir, - mkdtemp, - open, - readdir, - rm, - writeFile, -} from "node:fs/promises"; +import { lstat, mkdir, open, readdir, writeFile } from "node:fs/promises"; import { classifyProviderFailure } from "../providers/classifyProviderFailure.js"; -import { tmpdir } from "node:os"; import { join } from "node:path"; +import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js"; import { expect, it } from "vitest"; @@ -25,7 +17,7 @@ import { SQLITE_DATABASE_LIMITS } from "./SqliteDatabaseLimits.js"; import { sqliteDatabaseDialect } from "./SqliteDatabaseFailures.js"; it("tags an exact caller reason at snapshot admission", async () => { - const workspace = await mkdtemp(join(tmpdir(), "rea-sqlite-snapshot-entry-")); + const workspace = await createTestTempDirectory("rea-sqlite-snapshot-entry-"); const reason = { requested: "cancel at snapshot admission" }; const controller = new AbortController(); controller.abort(reason); @@ -60,13 +52,12 @@ it("tags an exact caller reason at snapshot admission", async () => { expect(projected.cause).toBe(reason); } finally { await resourceScope.close(); - await rm(workspace, { force: true, recursive: true }); } }); it("keeps the exact caller reason when cancellation lands at final snapshot verification", async () => { - const workspace = await mkdtemp( - join(tmpdir(), "rea-sqlite-snapshot-cancel-"), + const workspace = await createTestTempDirectory( + "rea-sqlite-snapshot-cancel-", ); const databasePath = join(workspace, "selected.db"); const privateRoot = join(workspace, "private"); @@ -111,14 +102,13 @@ it("keeps the exact caller reason when cancellation lands at final snapshot veri expect(projected.cause).toBe(reason); } finally { await resourceScope.close(); - await rm(workspace, { force: true, recursive: true }); } }); it("reports filesystem sizes above the safe-integer range exactly before opening files", async () => { const databaseBytes = BigInt(Number.MAX_SAFE_INTEGER) + 1n; const walBytes = 17n; - const workspace = await mkdtemp(join(tmpdir(), "rea-sqlite-budget-")); + const workspace = await createTestTempDirectory("rea-sqlite-budget-"); const databasePath = join(workspace, "selected.db"); const walPath = `${databasePath}-wal`; const journalPath = `${databasePath}-journal`; @@ -202,7 +192,6 @@ it("reports filesystem sizes above the safe-integer range exactly before opening }); } finally { await resourceScope.close(); - await rm(workspace, { force: true, recursive: true }); } }); @@ -212,7 +201,7 @@ it.each([ ])( "preserves $label when a late read-limit failure becomes changed evidence", async ({ retainCleanup }) => { - const workspace = await mkdtemp(join(tmpdir(), "rea-sqlite-read-cleanup-")); + const workspace = await createTestTempDirectory("rea-sqlite-read-cleanup-"); const databasePath = join(workspace, "selected.db"); await writeFile(databasePath, "tiny fixture"); const stat = await lstat(databasePath, { bigint: true }); @@ -291,7 +280,6 @@ it.each([ } } finally { await resourceScope.close(); - await rm(workspace, { force: true, recursive: true }); } }, ); diff --git a/src/wasm/WasmInterfaceBudget.test.ts b/src/wasm/WasmInterfaceBudget.test.ts index 9e270cab4d..7824b54072 100644 --- a/src/wasm/WasmInterfaceBudget.test.ts +++ b/src/wasm/WasmInterfaceBudget.test.ts @@ -43,11 +43,14 @@ it("does not suggest an impossible increase at the runtime representation maximu if (!(error instanceof AnalysisResourceConstraintError)) throw error; const projected = projectAnalysisError(error); expect(projected).toMatchObject({ - details: { reported_limits: { source: "request" } }, + details: { + reported_limits: { + source: "request", + maximum_bytes: MAX_WASM_INTERFACE_REPRESENTATION_BYTES, + maximum_supported_bytes: MAX_WASM_INTERFACE_REPRESENTATION_BYTES, + }, + }, }); - expect(projected.remediation.action).toContain( - "already at the runtime representation maximum", - ); expect(projected.remediation.action).not.toContain( "Raise max_interface_bytes", );