fix(runtime)!: preserve unknown debugger attachment state

Keep omitted discovery attachment state as null through Node, browser, Electron, and reconciliation evidence. Report the uncertainty while retaining Node observation unless discovery explicitly marks the target attached. Reject worker TargetInfo records missing the required boolean with partial coverage.

Validate omitted and explicit states through provider, CLI, and MCP boundaries and real Node 24 Inspector workflows. Consolidate Electron regression coverage into the existing list-and-inspect workflow.

BREAKING CHANGE: attached fields in JavaScript runtime, browser, and Electron target discovery and inspection results may be null when discovery does not report attachment state.
This commit is contained in:
morluto
2026-10-12 12:37:00 +08:00
parent 48c352b6bf
commit e55ef72135
23 changed files with 249 additions and 40 deletions
+5
View File
@@ -107,6 +107,11 @@ export class CdpBrowserProvider implements BrowserObservationPort {
: [
`${String(selected.unconnectable)} otherwise allowed page target(s) lacked a validated direct CDP WebSocket and were excluded.`,
]),
...(selected.allowed.some((target) => target.attached === null)
? [
"CDP discovery omitted attachment state for one or more targets; attached is reported as unknown.",
]
: []),
],
}),
);
+5
View File
@@ -57,6 +57,11 @@ export const inspectCdpElectronPage = async (
"Local file paths exposed by the selected CDP target are retained in the observation.",
"REA does not evaluate renderer JavaScript, invoke Electron APIs, navigate, click, or close the page.",
"Select include_script_sources to retain script contents.",
...(context.target.attached === null
? [
"CDP discovery omitted the target attachment state; attached is reported as unknown.",
]
: []),
],
mainFrameId: undefined,
navigationDuringCapture: false,
+5
View File
@@ -91,6 +91,11 @@ export class CdpElectronProvider implements ElectronObservationPort {
: [
`${String(unconnectable)} otherwise allowed page target(s) lacked a validated direct CDP WebSocket and were excluded.`,
]),
...(allowed.some((target) => target.attached === null)
? [
"CDP discovery omitted attachment state for one or more targets; attached is reported as unknown.",
]
: []),
],
}),
);
+5 -1
View File
@@ -61,11 +61,15 @@ export const captureElectronWorkers = async (input: {
input.completeness.exclude("workers", "invalid_protocol_value");
continue;
}
if (typeof target.attached !== "boolean") {
input.completeness.exclude("workers", "invalid_protocol_value");
continue;
}
workers.push({
target_id: targetId,
type,
file_path: path,
attached: target.attached === true,
attached: target.attached,
opener_target_id: openerTargetId,
parent_frame_id: parentFrameId,
});
+3 -3
View File
@@ -23,7 +23,7 @@ const endpointTargetSchema = z.object({
type: z.string().min(1),
title: z.string().default(""),
url: z.string(),
attached: z.boolean().default(false),
attached: z.boolean().nullable().optional(),
webSocketDebuggerUrl: z.string().min(1).optional(),
});
const endpointTargetsSchema = z.array(endpointTargetSchema);
@@ -46,7 +46,7 @@ export interface CdpEndpointTarget {
readonly type: string;
readonly title: string;
readonly url: string;
readonly attached: boolean;
readonly attached: boolean | null;
readonly webSocket?: CdpPageWebSocketEndpoint;
}
@@ -106,7 +106,7 @@ export const discoverCdpEndpoint = async (
type: target.type,
title: sanitizeTargetTitle(target.title, target.url),
url: target.url,
attached: target.attached,
attached: target.attached ?? null,
...targetWebSocket(endpoint, target, operation),
})),
};
+5
View File
@@ -84,6 +84,11 @@ export const capturePage = async (
"Raw network headers, bodies, cookies, storage values, console objects, and WebSocket payloads are never retained; explicitly requested primitive console text is retained verbatim, while payload captures retain value-free shapes.",
"Source maps are reported only as declarative URLs and are not fetched.",
"URL-less scripts and console events without an allowed source URL are excluded because their origin cannot be proven.",
...(context.target.attached === null
? [
"CDP discovery omitted the target attachment state; attached is reported as unknown.",
]
: []),
],
startedAt: new Date().toISOString(),
};
+5 -1
View File
@@ -55,12 +55,16 @@ export const captureWorkers = async (
);
continue;
}
if (typeof target.attached !== "boolean") {
completeness.exclude("workers", "invalid_protocol_value");
continue;
}
items.push({
target_id: cdpStringValue(target.targetId) ?? "",
type,
url: url.url,
origin: url.origin,
attached: target.attached === true,
attached: target.attached,
opener_target_id: cdpStringValue(target.openerId) ?? null,
parent_frame_id: cdpStringValue(target.parentFrameId) ?? null,
});
+6 -1
View File
@@ -20,7 +20,12 @@ const browserTargetSchema = z.object({
title: z.string(),
url: z.string(),
origin: z.string(),
attached: z.boolean(),
attached: z
.boolean()
.nullable()
.describe(
"Discovery-reported debugger attachment state; null means unknown",
),
});
/** Complete policy-filtered browser target discovery result. */
+6 -1
View File
@@ -43,7 +43,12 @@ const electronTargetSchema = z.object({
type: z.string(),
title: z.string(),
file_path: z.string(),
attached: z.boolean(),
attached: z
.boolean()
.nullable()
.describe(
"Discovery-reported debugger attachment state; null means unknown",
),
});
/** Complete local file target inventory from one Electron CDP endpoint. */
@@ -89,7 +89,12 @@ export type JavaScriptRuntimeTargetLocation = z.infer<
const javascriptRuntimeTargetSchema = z.strictObject({
target_id: z.string().min(1),
protocol_type: z.string().min(1),
attached: z.boolean(),
attached: z
.boolean()
.nullable()
.describe(
"Discovery-reported debugger attachment state; null means unknown",
),
location: javascriptRuntimeTargetLocationSchema,
});
@@ -44,21 +44,21 @@ interface NormalizedV8Inspection {
readonly target_id: string;
readonly type: string;
readonly title: string;
readonly attached: boolean;
readonly attached: boolean | null;
readonly file_path: string;
}
| {
readonly target_id: string;
readonly type: string;
readonly title: string;
readonly attached: boolean;
readonly attached: boolean | null;
readonly url: string;
}
| {
readonly target_id: string;
readonly type: string;
readonly title: string;
readonly attached: boolean;
readonly attached: boolean | null;
readonly unresolved_location: Extract<
JavaScriptRuntimeObservation["target"]["location"],
{ kind: "unresolved" }
@@ -26,12 +26,19 @@ export const createInspectorExclusionCounts = (): Record<
});
/** Stable safety and protocol limitations shared by target-list Evidence. */
export const describeInspectorTargetLimitations = (): string[] => [
export const describeInspectorTargetLimitations = (
attachmentStateUnknown = false,
): string[] => [
"REA attaches to an already-running exact target and never launches, resumes, evaluates, pauses, or mutates it.",
"Only Runtime.enable and Debugger.enable are sent; source text, object values, EventEmitter activity, and Electron IPC are not inspected.",
"The selected endpoint and target ID authorize observation; discovery file locations can remain unresolved and do not prove filesystem identity.",
"Node discovery reports a best-effort pathname rather than an encoded file URL; lossy Windows paths and ambiguous underscores are preserved without guessing a file path.",
"Every target exposed by the selected Inspector endpoint is eligible for observation; target IDs and locations are not authenticated as operating-system process identity.",
...(attachmentStateUnknown
? [
"Inspector discovery did not report the target's current debugger attachment state; it is retained as unknown, and observation rejects only targets explicitly marked attached.",
]
: []),
"No runtime graph depth is traversed because passive Inspector events do not establish require/import caller edges.",
];
@@ -215,7 +222,7 @@ export const finalizeInspectorCapture = async ({
"A bounded observation window cannot establish that an unobserved script or behavior never occurs.",
"The declared Node/Electron process role is not authenticated by the Inspector protocol.",
],
limitations: describeInspectorTargetLimitations(),
limitations: describeInspectorTargetLimitations(target.attached === null),
};
};
+3 -3
View File
@@ -21,7 +21,7 @@ const targetSchema = z
id: z.string().min(1),
type: z.string().min(1),
url: z.string(),
attached: z.boolean().default(false),
attached: z.boolean().nullable().optional(),
webSocketDebuggerUrl: z.string().min(1),
})
.passthrough();
@@ -31,7 +31,7 @@ export interface V8InspectorTarget {
readonly id: string;
readonly type: string;
readonly url: string;
readonly attached: boolean;
readonly attached: boolean | null;
readonly webSocketUrl: string;
}
@@ -62,7 +62,7 @@ export const discoverV8Inspector = async (
id: target.id,
type: target.type,
url: target.url,
attached: target.attached,
attached: target.attached ?? null,
webSocketUrl: validatedInspectorWebSocket(
endpoint,
target.id,
+4 -2
View File
@@ -117,7 +117,9 @@ export class V8InspectorProvider implements JavaScriptRuntimeObservationPort {
runtime: discovery.runtime,
targets: allowed.map(projectTarget),
excluded: { ...excluded, unconnectable: 0 },
limitations: describeInspectorTargetLimitations(),
limitations: describeInspectorTargetLimitations(
allowed.some((target) => target.attached === null),
),
}),
);
} catch (cause: unknown) {
@@ -357,7 +359,7 @@ const authorizedTarget = async (
product,
});
if (
target.attached ||
target.attached === true ||
!decision.allowed ||
decision.location.kind === "builtin"
)