Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(kuna): attribute installation failures to caller operations

morluto5717ad24aa64
diff --git a/src/kuna/KunaSessionClient.ts b/src/kuna/KunaSessionClient.ts
index 0c281cbf3..87be47682 100644
--- a/src/kuna/KunaSessionClient.ts
+++ b/src/kuna/KunaSessionClient.ts
@@ -79,6 +79,7 @@ import {
} from "../filesystem/OwnedRegularFile.js";
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
import { ArtifactReaderFailure } from "../artifacts/ArtifactReader.js";
+import { analysisClientFailureForOperation } from "../providers/AnalysisClientFailure.js";
/** How often a request waiting on the project export reports that it still waits. */
const WAIT_PROGRESS_INTERVAL_MS = 10_000;
@@ -358,7 +359,16 @@ export class KunaSessionClient implements AnalysisClient {
),
);
const installation = await this.#ensureInstallation();
- if (!installation.ok) return installation;
+ if (!installation.ok)
+ return operation === "health"
+ ? installation
+ : err(
+ analysisClientFailureForOperation(
+ installation.error,
+ KUNA_PROVIDER_ID,
+ operation,
+ ),
+ );
try {
if (operation === "health")
return ok(
diff --git a/tests/boundary/providers/kuna/kunaHashOwnerPropagation.test.ts b/tests/boundary/providers/kuna/kunaHashOwnerPropagation.test.ts
index 48dfdec03..566243749 100644
--- a/tests/boundary/providers/kuna/kunaHashOwnerPropagation.test.ts
+++ b/tests/boundary/providers/kuna/kunaHashOwnerPropagation.test.ts
@@ -2,6 +2,8 @@ import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { afterEach, expect, it, vi } from "vitest";
+import { AnalysisError } from "../../../../src/domain/analysisErrorBase.js";
+import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
import { ArtifactResourceScope } from "../../../../src/artifacts/ArtifactResourceScope.js";
import type { FileCloseResourceOwner } from "../../../../src/application/AnalysisProvider.js";
@@ -106,27 +108,49 @@ import { inspectKunaInstallationOwned } from "./kunaFileCloseOwner.js";
import { fakeKunaCalls } from "./fakeKuna.js";
import { run, session } from "./kunaSessionFixture.js";
-it
- .skipIf(process.platform === "win32")
- .each([{ stage: "fingerprint" }, { stage: "shebang" }] as const)(
- "resolves the originating installation cleanup error after a $stage close failure is retried at retirement",
- async ({ stage }) => {
+it.skipIf(process.platform === "win32").each(
+ (["fingerprint", "shebang"] as const).flatMap((stage) =>
+ (["health", "search_procedures"] as const).map((operation) => ({
+ stage,
+ operation,
+ })),
+ ),
+)(
+ "resolves $operation installation cleanup ownership after a $stage close failure is retried",
+ async ({ stage, operation }) => {
const fixture = await session("rea-kuna-installation-owner-resolution-");
const client = fixture.open();
injected.closeCalls = 0;
injected.failCloseReadStage = stage;
try {
- const health = await client.execute("health", {});
- expect(health.ok).toBe(false);
- if (health.ok)
+ const inspected = await client.execute(
+ operation,
+ operation === "health"
+ ? {}
+ : {
+ pattern: "main",
+ mode: "literal",
+ case_sensitive: false,
+ },
+ );
+ expect(inspected.ok).toBe(false);
+ if (inspected.ok)
throw new Error("installation inspection unexpectedly passed");
- const originatingError = health.error;
+ const originatingError = inspected.error;
const originalCause = originatingError.cause;
+ expect(projectAnalysisError(originatingError).details).toMatchObject({
+ operation,
+ });
expect(originatingError).toMatchObject({
cleanupIncomplete: true,
cleanupResources: [fixture.kuna],
});
- expect(originalCause).toMatchObject({
+ const producer =
+ operation === "health" ? originatingError : originalCause;
+ expect(producer).toBeInstanceOf(AnalysisError);
+ if (!(producer instanceof AnalysisError))
+ throw new Error("Missing producer error");
+ expect(producer.cause).toMatchObject({
name: "RegularFileCleanupFailure",
});
const failedCloseCall = stage === "fingerprint" ? 1 : 2;
@@ -134,6 +158,7 @@ it
expect(await client.close()).toEqual({ ok: true, value: null });
expect(originatingError.cleanupIncomplete).toBe(false);
+ expect(producer.cleanupIncomplete).toBe(false);
expect(originatingError.cause).toBe(originalCause);
expect(injected.closeCalls).toBe(failedCloseCall + 1);
} finally {
diff --git a/tests/boundary/providers/kuna/kunaInstallationAttribution.test.ts b/tests/boundary/providers/kuna/kunaInstallationAttribution.test.ts
new file mode 100644
index 000000000..18ab36dbf
--- /dev/null
+++ b/tests/boundary/providers/kuna/kunaInstallationAttribution.test.ts
@@ -0,0 +1,81 @@
+import { appendFile, unlink } from "node:fs/promises";
+import { expect, it } from "vitest";
+import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
+import { fakeKunaCalls, setFakeKunaBehavior } from "./fakeKuna.js";
+import { session } from "./kunaSessionFixture.js";
+
+it
+ .skipIf(process.platform === "win32")
+ .each(["version-refusal", "changed", "removed"] as const)(
+ "attributes a shared %s installation failure independently to each caller",
+ async (mode) => {
+ const fixture = await session("rea-kuna-installation-attribution-");
+ if (mode === "version-refusal")
+ await setFakeKunaBehavior(fixture.kuna, { version: { exit: 7 } });
+ if (mode === "changed")
+ await appendFile(fixture.kuna, "\n// changed executable\n");
+ if (mode === "removed") await unlink(fixture.kuna);
+ const client = fixture.open();
+ try {
+ const [search, strings, health] = await Promise.all([
+ client.execute("search_procedures", {
+ pattern: "main",
+ mode: "literal",
+ case_sensitive: false,
+ }),
+ client.execute("list_strings", {}),
+ client.execute("health", {}),
+ ]);
+ if (search.ok || strings.ok || health.ok)
+ throw new Error("Expected installation failures");
+ for (const [result, operation] of [
+ [search, "search_procedures"],
+ [strings, "list_strings"],
+ ] as const) {
+ expect(projectAnalysisError(result.error).details).toMatchObject({
+ operation,
+ });
+ expect(result.error._tag).toBe(health.error._tag);
+ expect(result.error.diagnostics).toEqual(health.error.diagnostics);
+ expect(result.error.cause).toBe(health.error);
+ expect(projectAnalysisError(result.error).retryable).toBe(
+ projectAnalysisError(health.error).retryable,
+ );
+ }
+ expect(projectAnalysisError(health.error).details).toMatchObject({
+ operation: "health",
+ });
+ expect(
+ (await fakeKunaCalls(fixture.kuna)).map(({ argv }) => argv[0]),
+ ).toEqual(
+ mode === "removed" ? ["--version"] : ["--version", "--version"],
+ );
+ } finally {
+ expect((await client.close()).ok).toBe(true);
+ }
+ },
+);
+
+it.skipIf(process.platform === "win32")(
+ "preserves successful procedure search after installation acquisition",
+ async () => {
+ const fixture = await session("rea-kuna-installation-search-control-");
+ const client = fixture.open();
+ try {
+ const result = await client.execute("search_procedures", {
+ pattern: "main",
+ mode: "literal",
+ case_sensitive: false,
+ });
+ if (!result.ok) throw result.error;
+ expect(result.value.result).toEqual([
+ { address: "0x1000", value: "main" },
+ ]);
+ expect(
+ (await fakeKunaCalls(fixture.kuna)).map(({ argv }) => argv[0]),
+ ).toEqual(["--version", "--version", "functions"]);
+ } finally {
+ expect((await client.close()).ok).toBe(true);
+ }
+ },
+);