fix(electron): attribute unresolved paths to selected inputs

Resolve each caller-selected Electron path once at the application boundary, collect field-specific failures with original causes, and pass canonical paths directly to the provider. Update direct provider consumers and route the real verifier through the shared application workflow.

Validation: public CLI/MCP invalid-path acceptance, canonicalization boundary, provider tests, and cancellation/cleanup checks. Live Electron launch was not verified. This does not address the separate Playwright launch-rejection crash in #2269.

Fixes #2272
This commit is contained in:
morluto
2026-10-13 04:12:40 +08:00
parent 049132ab43
commit b7169c8b74
8 changed files with 186 additions and 92 deletions
@@ -1,4 +1,5 @@
import { afterEach, expect, it, vi } from "vitest";
import { dirname } from "node:path";
import * as processOwnership from "../process/ProcessOwnership.js";
import * as electronActions from "./PlaywrightElectronActiveActions.js";
@@ -28,12 +29,13 @@ it("passes the selected environment and ownership token to Electron launch", asy
throw new Error("launch boundary reached");
},
);
const result = await provider.capture(
electronActiveObservationInputSchema.parse({
const result = await provider.capture({
...electronActiveObservationInputSchema.parse({
executable_path: process.execPath,
application_path: process.execPath,
}),
);
application_root: dirname(process.execPath),
});
expect(result.ok).toBe(false);
expect(launchedEnvironment).toEqual({
@@ -151,12 +153,13 @@ it("retains the partial capture without taskkill when Windows lineage is unavail
);
try {
const result = await provider.capture(
electronActiveObservationInputSchema.parse({
const result = await provider.capture({
...electronActiveObservationInputSchema.parse({
executable_path: process.execPath,
application_path: process.execPath,
}),
);
application_root: dirname(process.execPath),
});
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected unverified cleanup to fail");
+10 -22
View File
@@ -1,5 +1,3 @@
import { realpath } from "node:fs/promises";
import { dirname } from "node:path";
import { randomUUID } from "node:crypto";
import { fileURLToPath } from "node:url";
@@ -9,11 +7,11 @@ import type {
ExecutionOptions,
ProviderIdentity,
} from "../application/AnalysisProvider.js";
import type { ElectronActiveObservationPort } from "../application/javascript/ElectronActiveObservationPort.js";
import type {
ElectronActiveObservationInput,
ElectronActiveObservationResult,
} from "../domain/javascript/electronActiveObservation.js";
CanonicalElectronActiveObservationInput,
ElectronActiveObservationPort,
} from "../application/javascript/ElectronActiveObservationPort.js";
import type { ElectronActiveObservationResult } from "../domain/javascript/electronActiveObservation.js";
import { AnalysisError } from "../domain/analysisErrorBase.js";
import { BrowserObservationError } from "../domain/browserObservationError.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
@@ -70,7 +68,7 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
}
async capture(
input: ElectronActiveObservationInput,
input: CanonicalElectronActiveObservationInput,
options: ExecutionOptions = {},
): Promise<Result<ElectronActiveObservationResult, AnalysisError>> {
let application: ElectronApplication | undefined;
@@ -89,7 +87,11 @@ export class PlaywrightElectronActiveProvider implements ElectronActiveObservati
throw new BrowserObservationError(OPERATION, "cancelled");
await prepareProcessOwnershipInspection(options.signal);
const startupDeadline = Date.now() + STARTUP_TIMEOUT_MS;
paths = await canonicalPaths(input);
paths = {
executable: input.executable_path,
application: input.application_path,
root: input.application_root,
};
const captureBaseline =
await systemProcessOwnershipHost.captureBaseline?.(options.signal);
if (options.signal?.aborted)
@@ -353,20 +355,6 @@ export const cleanupElectronProcesses = async (
};
};
const canonicalPaths = async (
input: ElectronActiveObservationInput,
): Promise<ElectronPaths> => {
const [executable, application] = await Promise.all([
realpath(input.executable_path),
realpath(input.application_path),
]);
const root =
input.application_root === undefined
? dirname(application)
: await realpath(input.application_root);
return { executable, application, root };
};
const safeElectronEnvironment = (
environment: Readonly<Record<string, string | undefined>>,
runId: string,