-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[test]: add tests for frame merging & prefix computation #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[test]: add tests for frame merging & prefix computation #1452
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant Test as "Test Suite"
participant Capture as "capture.ts"
participant Mock as "Mock Page/CDP"
Note over Test,Mock: NEW: Unit Tests for "computeFramePrefixes"
Test->>Capture: computeFramePrefixes(page, context, perFrameMaps)
loop For each child frame in context
Capture->>Mock: getSessionForFrame(parentId)
Capture->>Mock: send("DOM.getFrameOwner", { frameId: childId })
alt Success (Same Process / Local Frame)
Mock-->>Capture: { backendNodeId: 200 }
Capture->>Capture: Look up XPath for node 200 in parent map
Note right of Capture: e.g., "/html/body/iframe[1]"
Capture->>Capture: Store AbsPrefix = ParentPrefix + IframeXPath
Capture->>Capture: Map ChildFrame to EncodedHostID
else Failure (OOPIF / Cross-Process)
Mock-->>Capture: Error or Empty
Capture->>Capture: Fallback: Inherit ParentPrefix
Note right of Capture: No explicit host mapping created
end
end
Capture-->>Test: Return { absPrefix, iframeHostEncByChild }
Note over Test,Mock: NEW: Unit Tests for "mergeFramesIntoSnapshot"
Test->>Capture: mergeFramesIntoSnapshot(maps, outlines, prefixes...)
loop For each frame
Capture->>Capture: Retrieve AbsPrefix for frame
Capture->>Capture: Prefix all entries in XPath map
Capture->>Capture: Merge URL/Scroll maps into root
end
Capture->>Capture: Identify Root Frame Outline
loop For each child frame
alt Parent Iframe Host Exists
Capture->>Capture: Locate encoded ID in Parent Outline
Capture->>Capture: Inject Child Outline into Parent Tree
opt Multiple children same slot
Capture->>Capture: Overwrite previous child (Last write wins)
end
else Orphaned / No Host Map
Capture->>Capture: Skip tree injection
end
end
Capture-->>Test: Return Combined Snapshot (Tree + Maps)
Greptile SummaryAdded comprehensive test coverage for frame prefix computation and snapshot merging logic that Key changes:
The tests use mock CDP sessions and pages to isolate the frame tree traversal and merging logic without requiring a full browser context. All assertions validate both the computed data structures ( Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant Page as Mock Page
participant Session as Mock CDP Session
participant Compute as computeFramePrefixes
participant Merge as mergeFramesIntoSnapshot
Note over Test,Merge: Test: Frame Prefix Computation
Test->>Page: Create mock page with sessions
Test->>Compute: computeFramePrefixes(page, context, perFrameMaps)
loop For each child frame
Compute->>Page: parentSession(parent)
Compute->>Session: DOM.getFrameOwner(frameId)
alt Frame owner found
Session-->>Compute: { backendNodeId }
Compute->>Compute: Look up iframe XPath in parent maps
Compute->>Compute: prefix = prefixXPath(parentAbs, iframeXPath)
else Frame owner fails (OOPIF)
Session-->>Compute: throw Error
Compute->>Compute: prefix = inherit parent prefix
end
Compute->>Compute: Store absPrefix[child] and iframeHostEncByChild[child]
end
Compute-->>Test: { absPrefix, iframeHostEncByChild }
Note over Test,Merge: Test: Snapshot Merging
Test->>Merge: mergeFramesIntoSnapshot(context, maps, outlines, prefixes, hosts)
loop For each frame
Merge->>Merge: Get frame maps and absolute prefix
alt Is root frame
Merge->>Merge: Copy xpathMap and urlMap as-is
else Is child frame
Merge->>Merge: Prefix each xpath with absolute prefix
Merge->>Merge: Merge urlMap
end
end
Merge->>Merge: Build idToTree map from iframeHostEncByChild
Merge->>Merge: injectSubtrees(rootOutline, idToTree)
Merge-->>Test: HybridSnapshot with combined maps and tree
|
why
captureHybridSnapshot()depends onwhat changed
computeFramePrefixes()&mergeFramesIntoSnapshot()for testingsnapshot-frame-merge.test.ts, which holds tests for the following functions:computeFramePrefixes()mergeFramesIntoSnapshot()test plan
Summary by cubic
Add unit tests for computeFramePrefixes and mergeFramesIntoSnapshot to improve coverage for captureHybridSnapshot. Exported these functions from capture.ts for testing; no runtime behavior changes.
Written for commit 912b7c1. Summary will update automatically on new commits.