refactor(browser): share cleanup observation facts
This commit is contained in:
1 parent
bc1c5073df
commit
9c0c2765c5
4 files changed
+28
-36
No files matched your search
@@ -10,6 +10,7 @@ import type {
|
||||
} from "../domain/browserScenarioCaptureValues.js";
|
||||
import type { BrowserScenarioSessionPort } from "./BrowserScenarioSessionPort.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { browserCleanupObservation } from "../domain/browserObservationError.js";
|
||||
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
@@ -104,20 +105,6 @@ export const browserScenarioCaptureData = (input: {
|
||||
};
|
||||
};
|
||||
|
||||
/** Describe the cleanup failure without discarding its resource evidence. */
|
||||
export const browserScenarioCleanupObservation = (
|
||||
cause: unknown,
|
||||
): { readonly reason: string; readonly resources: readonly string[] } =>
|
||||
cause instanceof AnalysisError && cause.cleanup !== undefined
|
||||
? cause.cleanup
|
||||
: {
|
||||
reason: cause instanceof Error ? cause.message : String(cause),
|
||||
resources:
|
||||
cause instanceof AnalysisError && cause.cleanupResources.length > 0
|
||||
? cause.cleanupResources
|
||||
: ["browser_transport"],
|
||||
};
|
||||
|
||||
/** Retain operation diagnostics and capture data after cleanup settles. */
|
||||
export const browserScenarioOperationFailure = (
|
||||
cause: unknown,
|
||||
@@ -134,7 +121,7 @@ export const browserScenarioOperationFailure = (
|
||||
);
|
||||
primary.retainPartialObservation(partialObservation);
|
||||
if (cleanupFailure === undefined) return primary;
|
||||
const observation = browserScenarioCleanupObservation(cleanupFailure.cause);
|
||||
const observation = browserCleanupObservation(cleanupFailure.cause);
|
||||
const cleanup =
|
||||
cleanupFailure.cause instanceof AnalysisError &&
|
||||
cleanupFailure.cause.cleanupIncomplete
|
||||
|
||||
@@ -35,7 +35,10 @@ import {
|
||||
} from "../domain/browserScenarioCaptureValues.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
||||
import { BrowserObservationError } from "../domain/browserObservationError.js";
|
||||
import {
|
||||
BrowserObservationError,
|
||||
browserCleanupObservation,
|
||||
} from "../domain/browserObservationError.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import type {
|
||||
@@ -47,7 +50,6 @@ import {
|
||||
type ScenarioActionStop,
|
||||
} from "./ScenarioActionSequence.js";
|
||||
import {
|
||||
browserScenarioCleanupObservation,
|
||||
browserScenarioOperationFailure,
|
||||
browserScenarioCaptureData,
|
||||
} from "./BrowserScenarioPartialObservation.js";
|
||||
@@ -302,7 +304,7 @@ const runScenario = async (
|
||||
try {
|
||||
cleanupOutcome = { ok: true, cleanup: await session.close() };
|
||||
} catch (cause: unknown) {
|
||||
const cleanup = browserScenarioCleanupObservation(cause);
|
||||
const cleanup = browserCleanupObservation(cause);
|
||||
const failure = new BrowserObservationError(OPERATION, "cleanup_failed", {
|
||||
cause,
|
||||
cleanup,
|
||||
@@ -319,7 +321,7 @@ const runScenario = async (
|
||||
cause: options.signal.reason,
|
||||
}),
|
||||
};
|
||||
const cleanup = browserScenarioCleanupObservation(cleanupOutcome.cause);
|
||||
const cleanup = browserCleanupObservation(cleanupOutcome.cause);
|
||||
const partialObservation: BrowserScenarioPartialObservation = {
|
||||
kind: "browser-scenario-observation",
|
||||
capture: browserScenarioCaptureData({
|
||||
|
||||
@@ -6,9 +6,11 @@ import { withCommandCancellation } from "./cli/commandCancellation.js";
|
||||
import { CLI_COMMANDS } from "./cliCommandNames.js";
|
||||
import { parseCliJsonInput, resolveCliJsonPaths } from "./cliJsonInput.js";
|
||||
import { logCliCommand } from "./cliLogging.js";
|
||||
import { AnalysisError } from "./domain/analysisErrorBase.js";
|
||||
import { projectAnalysisError } from "./domain/analysisErrorProjection.js";
|
||||
import { BrowserObservationError } from "./domain/browserObservationError.js";
|
||||
import {
|
||||
BrowserObservationError,
|
||||
browserCleanupObservation,
|
||||
} from "./domain/browserObservationError.js";
|
||||
import { analysisInputErrorFromIssues } from "./domain/inputIssueProjection.js";
|
||||
import { browserScenarioSchema } from "./domain/browserScenario.js";
|
||||
import type { BrowserScenarioCapturePort } from "./application/BrowserScenarioCapturePort.js";
|
||||
@@ -78,21 +80,7 @@ export const registerBrowserScenarioCommands = (
|
||||
if (result?.ok)
|
||||
throw new BrowserObservationError(OPERATION, "cleanup_failed", {
|
||||
cause,
|
||||
cleanup:
|
||||
cause instanceof AnalysisError &&
|
||||
cause.cleanup !== undefined
|
||||
? cause.cleanup
|
||||
: {
|
||||
reason:
|
||||
cause instanceof Error
|
||||
? cause.message
|
||||
: String(cause),
|
||||
resources:
|
||||
cause instanceof AnalysisError &&
|
||||
cause.cleanupResources.length > 0
|
||||
? cause.cleanupResources
|
||||
: ["browser_transport"],
|
||||
},
|
||||
cleanup: browserCleanupObservation(cause),
|
||||
partialObservation: result.value,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,10 +4,25 @@ import type {
|
||||
} from "./browserObservationErrors.js";
|
||||
import {
|
||||
AnalysisError,
|
||||
type AnalysisCleanupObservation,
|
||||
type AnalysisErrorOptions,
|
||||
} from "./analysisErrorBase.js";
|
||||
import { AnalysisCancelledError } from "./analysisErrorCore.js";
|
||||
|
||||
/** Describe browser cleanup failure without discarding its resource evidence. */
|
||||
export const browserCleanupObservation = (
|
||||
cause: unknown,
|
||||
): AnalysisCleanupObservation =>
|
||||
cause instanceof AnalysisError && cause.cleanup !== undefined
|
||||
? cause.cleanup
|
||||
: {
|
||||
reason: cause instanceof Error ? cause.message : String(cause),
|
||||
resources:
|
||||
cause instanceof AnalysisError && cause.cleanupResources.length > 0
|
||||
? cause.cleanupResources
|
||||
: ["browser_transport"],
|
||||
};
|
||||
|
||||
/** A bounded passive browser observation failed at its CDP boundary. */
|
||||
export class BrowserObservationError extends AnalysisError {
|
||||
readonly _tag = "BrowserObservationError";
|
||||
|
||||
Reference in new issue
Block a user