fix(capture): retain Electron observations and HAR resource failures
This commit is contained in:
@@ -71,6 +71,12 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
||||
let application: ElectronApplication | undefined;
|
||||
let ownership: OwnedProcessGroup | undefined;
|
||||
let lineage: ProcessLineageObservation | undefined;
|
||||
let capture: ElectronActiveObservationResult | undefined;
|
||||
let paths: ElectronPaths | undefined;
|
||||
let initialState:
|
||||
| Awaited<ReturnType<typeof readApplicationState>>
|
||||
| undefined;
|
||||
let actions: ElectronActiveObservationResult["actions"] = [];
|
||||
let outcome: Result<ElectronActiveObservationResult, AnalysisError>;
|
||||
const runId = randomUUID();
|
||||
try {
|
||||
@@ -78,7 +84,7 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
||||
throw new BrowserObservationError(OPERATION, "cancelled");
|
||||
await prepareProcessOwnershipInspection(options.signal);
|
||||
const startupDeadline = Date.now() + STARTUP_TIMEOUT_MS;
|
||||
const paths = await canonicalPaths(input);
|
||||
paths = await canonicalPaths(input);
|
||||
const captureBaseline =
|
||||
await systemProcessOwnershipHost.captureBaseline?.(options.signal);
|
||||
if (options.signal?.aborted)
|
||||
@@ -109,24 +115,66 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
||||
sweepTokenOwnedProcesses: true,
|
||||
...(captureBaseline === undefined ? {} : { captureBaseline }),
|
||||
};
|
||||
const actions = await runElectronActions(application, input, options);
|
||||
lineage = await observeOwnedProcessLineage(ownership);
|
||||
initialState = await readApplicationState(application);
|
||||
actions = await runElectronActions(application, input, options);
|
||||
const state = await runWithExecutionLimits(
|
||||
readApplicationState(application),
|
||||
options.signal,
|
||||
undefined,
|
||||
options.signal?.aborted ? Date.now() + 5_000 : undefined,
|
||||
);
|
||||
outcome = ok(projectElectronActiveCapture(paths, actions, state));
|
||||
capture = projectElectronActiveCapture(paths, actions, state);
|
||||
outcome = options.signal?.aborted
|
||||
? err(
|
||||
new BrowserObservationError(OPERATION, "cancelled", {
|
||||
partialObservation: {
|
||||
kind: "electron-active-observation",
|
||||
capture,
|
||||
},
|
||||
}),
|
||||
)
|
||||
: ok(capture);
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
options.signal?.aborted &&
|
||||
paths !== undefined &&
|
||||
initialState !== undefined
|
||||
) {
|
||||
const retainedCapture = projectElectronActiveCapture(
|
||||
paths,
|
||||
actions,
|
||||
initialState,
|
||||
);
|
||||
capture = {
|
||||
...retainedCapture,
|
||||
limitations: [
|
||||
...retainedCapture.limitations,
|
||||
`Final Electron state was unavailable after cancellation: ${cause instanceof Error ? cause.message : String(cause)}. Windows, metrics, IPC, and timeline are the snapshot collected before actions and may omit their effects.`,
|
||||
],
|
||||
};
|
||||
}
|
||||
outcome = err(
|
||||
options.signal?.aborted === true &&
|
||||
(cause === options.signal.reason ||
|
||||
(cause instanceof Error && cause.name === "AbortError"))
|
||||
? new BrowserObservationError(OPERATION, "cancelled", { cause })
|
||||
options.signal?.aborted === true
|
||||
? new BrowserObservationError(OPERATION, "cancelled", {
|
||||
cause,
|
||||
...(capture === undefined
|
||||
? {}
|
||||
: {
|
||||
partialObservation: {
|
||||
kind: "electron-active-observation" as const,
|
||||
capture,
|
||||
},
|
||||
}),
|
||||
})
|
||||
: providerError(cause),
|
||||
);
|
||||
}
|
||||
if (application !== undefined) {
|
||||
if (ownership !== undefined)
|
||||
lineage = await observeOwnedProcessLineage(ownership);
|
||||
if (ownership !== undefined) {
|
||||
const currentLineage = await observeOwnedProcessLineage(ownership);
|
||||
if (currentLineage.status === "verified" || lineage === undefined)
|
||||
lineage = currentLineage;
|
||||
}
|
||||
let closeError: unknown;
|
||||
try {
|
||||
await runWithExecutionLimits(
|
||||
@@ -146,13 +194,51 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
|
||||
: await cleanupElectronProcesses(ownership, lineage);
|
||||
if (!cleanup.cleaned)
|
||||
return err(
|
||||
providerError(
|
||||
new BrowserObservationError(OPERATION, "cleanup_failed", {
|
||||
cause: new Error(cleanup.reason),
|
||||
}),
|
||||
),
|
||||
new BrowserObservationError(OPERATION, "cleanup_failed", {
|
||||
cause: outcome.ok ? new Error(cleanup.reason) : outcome.error,
|
||||
detail: `Electron cleanup could not be verified: ${cleanup.reason}.${capture !== undefined ? " Collected observations are retained in partial_observation." : ""}${outcome.ok ? "" : ` Capture also failed: ${outcome.error.message}.`} Inspect the reported process resources before launching another capture.`,
|
||||
cleanup: {
|
||||
reason: cleanup.reason,
|
||||
resources:
|
||||
ownership === undefined
|
||||
? ["owned_process_group"]
|
||||
: [
|
||||
"owned_process_group",
|
||||
`run:${ownership.runId}`,
|
||||
`process-group:${String(ownership.processGroupId)}`,
|
||||
],
|
||||
},
|
||||
...(capture !== undefined
|
||||
? {
|
||||
partialObservation: {
|
||||
kind: "electron-active-observation" as const,
|
||||
capture: {
|
||||
...capture,
|
||||
application: {
|
||||
...capture.application,
|
||||
cleanup: "unverified" as const,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
);
|
||||
if (closeError !== undefined)
|
||||
return err(
|
||||
new BrowserObservationError(OPERATION, "cleanup_failed", {
|
||||
cause: outcome.ok ? closeError : outcome.error,
|
||||
detail: `Electron transport teardown failed after process cleanup: ${closeError instanceof Error ? closeError.message : String(closeError)}.${capture !== undefined ? " Collected observations are retained in partial_observation." : ""}${outcome.ok ? "" : ` Capture also failed: ${outcome.error.message}.`}`,
|
||||
...(capture !== undefined
|
||||
? {
|
||||
partialObservation: {
|
||||
kind: "electron-active-observation" as const,
|
||||
capture,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
);
|
||||
if (closeError !== undefined) return err(providerError(closeError));
|
||||
if (outcome.ok && cleanup.unverified !== undefined)
|
||||
outcome = ok({
|
||||
...outcome.value,
|
||||
@@ -294,5 +380,8 @@ const providerError = (cause: unknown): AnalysisError =>
|
||||
OPERATION,
|
||||
{
|
||||
cause,
|
||||
diagnostics: {
|
||||
message: cause instanceof Error ? cause.message : String(cause),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user