refactor(kuna): share cleanup aggregation for commands and sessions (#12528)

This commit is contained in:
RRFZ authored and GitHub committed 2026-11-19 17:28:13 -05:00
1 parent fa9abed521
commit d3d0355a9a
4 files changed
+38 -31

No files matched your search

@@ -25,8 +25,6 @@
"src/jeb/JebMcpConnectionOwner.ts": 1,
"src/jeb/JebProvider.ts": 1,
"src/kuna/KunaProjectCache.ts": 1,
"src/kuna/KunaSessionClient.ts": 1,
"src/kuna/KunaTargetCommands.ts": 1,
"src/native/LldbCallTracer.ts": 3,
"src/native/NativeCommandAnalysisError.ts": 1,
"src/native/NativeMacOSProvider.ts": 2,
+10 -14
View File
@@ -56,6 +56,7 @@ import type { JsonValue } from "../domain/jsonValue.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import type { RelationshipCoverage } from "../domain/relationshipCoverage.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { providerCleanupErrorFromFailures } from "../domain/analysisErrorCleanup.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
import {
classifyProviderFailure,
@@ -679,24 +680,19 @@ export class KunaSessionClient implements AnalysisClient {
}
if (failures.length > 0)
return err(
new ProviderCleanupError(
providerCleanupErrorFromFailures(
KUNA_PROVIDER_ID,
failures.flatMap((failed) => failed.cleanupResources),
failures,
failures
.map((failure) =>
String(failure.diagnostics?.["reason"] ?? failure.message),
)
.join("; "),
{
reason: failures
.map((failed) =>
String(failed.diagnostics?.["reason"] ?? failed.message),
)
.join("; "),
},
{
cause: new AggregateError(
failures,
"Kuna session cleanup remains incomplete",
),
operation: "close_binary",
message: "Kuna session cleanup remains incomplete",
},
).bindCleanupDependencies(failures),
),
);
this.#releasePin?.();
this.#releasePin = undefined;
+14 -15
View File
@@ -26,7 +26,10 @@ import {
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
import { analysisErrorWithCleanupDependencies } from "../domain/analysisErrorCleanup.js";
import {
analysisErrorWithCleanupDependencies,
providerCleanupErrorFromFailures,
} from "../domain/analysisErrorCleanup.js";
import { err, ok, type Result } from "../domain/result.js";
import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
import { prepareProcessOwnershipInspection } from "../process/ProcessOwnershipObservation.js";
@@ -328,23 +331,19 @@ export class KunaTargetCommands {
return failures.length === 0
? ok(null)
: err(
new ProviderCleanupError(
providerCleanupErrorFromFailures(
KUNA_PROVIDER_ID,
failures.flatMap((failure) => failure.cleanupResources),
failures,
failures
.map((failure) =>
String(failure.diagnostics?.["reason"] ?? failure.message),
)
.join("; "),
{
reason: failures
.map((failure) =>
String(failure.diagnostics?.["reason"] ?? failure.message),
)
.join("; "),
operation: "close_binary",
message: "Kuna command cleanup remains incomplete",
},
{
cause: new AggregateError(
failures,
"Kuna command cleanup remains incomplete",
),
},
).bindCleanupDependencies(failures),
),
);
}
@@ -143,6 +143,20 @@ it("keeps cancellation output and primary reason while exact command cleanup is
client.close(),
]);
if (rootFailure.ok) throw new Error("Expected workspace cleanup failure");
expect(rootFailure.error.cause).toBeInstanceOf(AggregateError);
expect(rootFailure.error).toMatchObject({
operation: "close_binary",
cleanupResources: [workspace.path],
cause: {
errors: [
{
operation: "close_binary",
cleanupResources: [workspace.path],
cause: expect.any(AggregateError),
},
],
},
});
expect(result.error.cleanupIncomplete).toBe(true);
expect(result.error.cleanupResources).toEqual([workspace.path]);
expect(refuseRootClose).toHaveBeenCalledTimes(1);