refactor(cleanup): share failure composition and retain native UI owners

Validation: integrated changes passed formatting, typecheck, lint, resolved module-boundary verification and git diff --check. Tests and real-provider workflows were not run.
This commit is contained in:
morluto
2026-10-11 00:03:18 +08:00
parent 6543405252
commit 2a0b58e440
12 changed files with 225 additions and 63 deletions
+3 -1
View File
@@ -99,6 +99,7 @@ import type { BrowserScenarioPartialObservation } from "./browserScenarioCapture
import type { Evidence } from "./evidence.js";
import type { AndroidPartialObservation } from "./android/androidPartialObservation.js";
import type { FirmwarePartialObservation } from "./firmware/firmwareAnalysis.js";
import type { NativeUiObservationResult } from "./native/nativeUiObservation.js";
/** Provider-neutral evidence collected before a typed analysis failure. */
export type AnalysisPartialObservation =
@@ -111,4 +112,5 @@ export type AnalysisPartialObservation =
| ArtifactInventoryPartialObservation
| Evidence
| AndroidPartialObservation
| FirmwarePartialObservation;
| FirmwarePartialObservation
| NativeUiObservationResult;
+39
View File
@@ -0,0 +1,39 @@
import { ProviderAdapterError } from "./providerAdapterError.js";
import { projectAnalysisError } from "./analysisErrorProjection.js";
import type { AnalysisError } from "./analysisErrorBase.js";
/** Preserve the original lifecycle failure alongside incomplete cleanup. */
export const analysisErrorWithCleanupFailure = (
primary: AnalysisError,
cleanup: AnalysisError,
operation = "close_binary",
): AnalysisError => {
const projected = projectAnalysisError(cleanup);
return new ProviderAdapterError(
cleanup instanceof ProviderAdapterError ? cleanup.providerId : "rea",
operation,
{
cause: primary,
userMessage: projectAnalysisError(primary).message,
...(primary.capturedOutput === undefined
? {}
: { capturedOutput: primary.capturedOutput }),
...(primary.partialObservation === undefined
? {}
: { partialObservation: primary.partialObservation }),
cleanup: {
reason: projected.message,
resources: [
...new Set([
...primary.cleanupResources,
...cleanup.cleanupResources,
]),
],
},
diagnostics: {
primary_error: projectAnalysisError(primary),
cleanup_error: projected,
},
},
);
};
+2
View File
@@ -156,3 +156,5 @@ export const nativeUiResultSchema = z.strictObject({
restore: z.literal("leave-as-is"),
limitations: z.array(z.string()),
});
export type NativeUiObservationResult = z.infer<typeof nativeUiResultSchema>;