fix(observation): validate document consistency with bounded identity checks

This commit is contained in:
Ljy-0827
2026-09-09 16:09:09 +08:00
committed by drakezhang
parent 282e6f5623
commit 2d1e5c6d9d
12 changed files with 585 additions and 11 deletions
@@ -38,6 +38,7 @@ export interface FrameContext {
export interface NormalizedDocument {
nodes: NodeFacts[];
index: DocumentIndex;
documentElementBackendNodeId?: number;
}
/** Interpret one document using a supplied projection. No live reads or frame scheduling. */
@@ -98,6 +99,12 @@ export async function normalizeDocument(
(node) => !node.tag.startsWith("#") && !index.excludedBackendNodeIds.has(node.backendNodeId),
),
index,
documentElementBackendNodeId: nodes.find(
(node) =>
node.nodeType === 1 &&
node.parentBackendNodeId !== null &&
index.nodes.get(node.parentBackendNodeId)?.nodeType === 9,
)?.backendNodeId,
};
}