From d3d0355a9a598a2af798190ea48ebd5cefc2e456 Mon Sep 17 00:00:00 2001 From: RRFZ <247457381+Plastic-time@users.noreply.github.com> Date: Thu, 19 Nov 2026 17:28:13 -0500 Subject: [PATCH] refactor(kuna): share cleanup aggregation for commands and sessions (#12528) --- .../baselines/cleanup-dependency-binding.json | 2 -- src/kuna/KunaSessionClient.ts | 24 +++++++-------- src/kuna/KunaTargetCommands.ts | 29 +++++++++---------- .../kuna/kunaCommandCancellation.test.ts | 14 +++++++++ 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/scripts/verify/baselines/cleanup-dependency-binding.json b/scripts/verify/baselines/cleanup-dependency-binding.json index f263b223a5..e77da1cb0b 100644 --- a/scripts/verify/baselines/cleanup-dependency-binding.json +++ b/scripts/verify/baselines/cleanup-dependency-binding.json @@ -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, diff --git a/src/kuna/KunaSessionClient.ts b/src/kuna/KunaSessionClient.ts index bbe1e43a51..cbdddc096d 100644 --- a/src/kuna/KunaSessionClient.ts +++ b/src/kuna/KunaSessionClient.ts @@ -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; diff --git a/src/kuna/KunaTargetCommands.ts b/src/kuna/KunaTargetCommands.ts index ab86849ef0..02759aece9 100644 --- a/src/kuna/KunaTargetCommands.ts +++ b/src/kuna/KunaTargetCommands.ts @@ -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), + ), ); } diff --git a/tests/boundary/providers/kuna/kunaCommandCancellation.test.ts b/tests/boundary/providers/kuna/kunaCommandCancellation.test.ts index b936622bd9..da6e15f433 100644 --- a/tests/boundary/providers/kuna/kunaCommandCancellation.test.ts +++ b/tests/boundary/providers/kuna/kunaCommandCancellation.test.ts @@ -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);