Merge pull request #1201 from morluto/fix/ghidra-runtime-cleanup-retry

fix(ghidra): keep and name a runtime directory that close could not remove
This commit is contained in:
Kaoru0822
2026-10-08 22:49:12 -07:00
committed by GitHub
5 changed files with 132 additions and 15 deletions
@@ -0,0 +1,45 @@
import { expect, it } from "vitest";
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
import { err } from "../../domain/result.js";
import type { AnalysisClient } from "../AnalysisProvider.js";
import { closeAnalysisClient } from "./AnalysisClientCleanup.js";
const clientClosingWith = (cause: unknown): AnalysisClient => ({
execute: () => Promise.resolve(err(new ProviderCleanupError("x", [], {}))),
close: () => Promise.reject(cause),
});
it("keeps the leftover resources a typed cleanup failure names", async () => {
const leftover = "/tmp/rea-ghidra-fixture";
const failure = new ProviderCleanupError("ghidra", [leftover], {
reason: "runtime directory retained",
});
const closed = await closeAnalysisClient(
clientClosingWith(failure),
"ghidra",
);
expect(closed.ok).toBe(false);
if (!closed.ok)
expect(projectAnalysisError(closed.error)).toMatchObject({
code: "cleanup_incomplete",
details: { resources: [leftover] },
});
});
it("still reports an untyped close rejection as the provider client", async () => {
const closed = await closeAnalysisClient(
clientClosingWith(new Error("unexpected")),
"ghidra",
);
expect(closed.ok).toBe(false);
if (!closed.ok)
expect(projectAnalysisError(closed.error)).toMatchObject({
code: "cleanup_incomplete",
details: { resources: ["provider-client"] },
});
});
@@ -1,6 +1,6 @@
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
import { err, ok, type Result } from "../../domain/result.js";
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
import { AnalysisError } from "../../domain/analysisErrorBase.js";
import type { AnalysisClient, ExecutionOptions } from "../AnalysisProvider.js";
/** Close one provider client and normalize unexpected adapter rejection. */
@@ -17,6 +17,9 @@ export const closeAnalysisClient = async (
await client.close();
return ok(null);
} catch (cause: unknown) {
// A typed cleanup failure already names its leftover resources.
if (cause instanceof AnalysisError && cause.cleanupIncomplete)
return err(cause);
return err(
new ProviderCleanupError(
providerId,