refactor(admission): own inspector, web, and CLI state per host (#8058)

* refactor(admission): own inspector, web, and CLI state per host

Replace the process-global inspector, web-bundle, guidance, and JavaScript
counters with objects a host passes in, so independent instances do not
share admission or cleanup.

* fix(admission): keep worker and file cleanup on the host

Web-bundle and JavaScript workers retry only their host registry, and
each Inspector admission authorizes and closes its own file scope.
Browser providers can share one web-bundle admission.

* test(inspector): gate one admission's file cleanup

The isolation test delayed the first ArtifactResourceScope.retryCleanup
call, so a second call on a shared ElectronFileScope still finished.
Hold first.files.retryCleanup until the other admission's close
finishes, then release and join before restoring the method.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
morlutoandCursor Agent authored and GitHub committed 2026-10-30 05:23:33 +08:00
1 parent b663c79552
commit 395b598383
21 files changed
+782 -269

No files matched your search

+10 -1
View File
@@ -14,7 +14,10 @@ import type {
JavaScriptRuntimeTargetLocation,
} from "../domain/javascript/javascriptRuntimeObservation.js";
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
import { authorizedElectronFile } from "../browser/ElectronFileScope.js";
import {
authorizedElectronFile,
type ElectronFileScope,
} from "../browser/ElectronFileScope.js";
export type RuntimeLocationDecision =
| { readonly allowed: true; readonly location: JavaScriptRuntimeLocation }
@@ -56,6 +59,7 @@ export const authorizeRuntimeLocation = async (
| "observe_javascript_runtime"
| "list_javascript_runtime_targets" = "observe_javascript_runtime",
asarHeaderAdmission: AsarHeaderAdmission = DEFAULT_ASAR_HEADER_ADMISSION,
files?: ElectronFileScope,
): Promise<RuntimeLocationDecision> => {
throwIfRuntimeObservationCancelled(signal, operation);
if (URL.parse(value)?.protocol === "file:") {
@@ -64,6 +68,7 @@ export const authorizeRuntimeLocation = async (
signal,
operation,
asarHeaderAdmission,
files,
);
throwIfRuntimeObservationCancelled(signal, operation);
return filePath === undefined
@@ -114,6 +119,7 @@ export const authorizeRuntimeTargetLocation = async (
| "observe_javascript_runtime"
| "list_javascript_runtime_targets" = "list_javascript_runtime_targets",
asarHeaderAdmission: AsarHeaderAdmission = DEFAULT_ASAR_HEADER_ADMISSION,
files?: ElectronFileScope,
): Promise<
| {
readonly allowed: true;
@@ -132,6 +138,7 @@ export const authorizeRuntimeTargetLocation = async (
signal,
operation,
asarHeaderAdmission,
files,
);
const reportedPath = value.slice("file://".length);
if (!reportedPath.startsWith("/") && !/^[a-z]:[/\\_]/iu.test(reportedPath))
@@ -140,6 +147,7 @@ export const authorizeRuntimeTargetLocation = async (
signal,
operation,
asarHeaderAdmission,
files,
);
// Node concatenates the pathname, then replaces quotes and backslashes with
@@ -151,6 +159,7 @@ export const authorizeRuntimeTargetLocation = async (
signal,
operation,
asarHeaderAdmission,
files,
);
if (decision.allowed) return decision;
}