-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[test]: add tests for ax tree fetching & object ID resolvers #1451
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 ax tree fetching & object ID resolvers #1451
Conversation
|
Greptile SummaryThis PR adds comprehensive unit tests for the accessibility tree fetching and object ID resolution logic that
The only production code change is exporting Key strengths:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Test as Test Suite
participant a11y as a11yForFrame()
participant resolve as resolveObjectId*()
participant scoped as tryScopedSnapshot()
participant session as MockCDPSession
participant ctx as executionContexts
Note over Test,ctx: Test Flow for AX Tree & Object ID Resolvers
rect rgb(240, 248, 255)
Note right of Test: a11yForFrame() Tests
Test->>a11y: call with focusSelector
a11y->>session: Accessibility.getFullAXTree
session-->>a11y: return nodes
a11y->>resolve: resolveObjectIdForXPath/Css
resolve->>ctx: waitForMainWorld(frameId)
ctx-->>resolve: return contextId
resolve->>session: Runtime.evaluate
session-->>resolve: return objectId
resolve-->>a11y: objectId or null
a11y->>session: DOM.describeNode
session-->>a11y: backendNodeId
a11y-->>Test: {outline, urlMap, scopeApplied}
end
rect rgb(255, 248, 240)
Note right of Test: resolveObjectId Tests
Test->>resolve: resolveObjectIdForXPath/Css
resolve->>ctx: waitForMainWorld(frameId)
alt context available
ctx-->>resolve: contextId
resolve->>session: Runtime.evaluate
alt success
session-->>resolve: {result: {objectId}}
resolve-->>Test: objectId
else exception
session-->>resolve: {exceptionDetails}
resolve-->>Test: null
end
else context missing
ctx-->>resolve: throw error
resolve-->>Test: null
end
end
rect rgb(248, 255, 240)
Note right of Test: tryScopedSnapshot() Tests
Test->>scoped: call with focusSelector
alt CSS selector
scoped->>resolve: resolveCssFocusFrameAndTail
resolve-->>scoped: {targetFrameId, tailSelector, absPrefix}
else XPath selector
scoped->>resolve: resolveFocusFrameAndTail
resolve-->>scoped: {targetFrameId, tailXPath, absPrefix}
end
scoped->>a11y: a11yForFrame(tailSelector)
a11y-->>scoped: {outline, urlMap, scopeApplied}
alt scopeApplied true
scoped-->>Test: HybridSnapshot
else scopeApplied false
scoped->>scoped: logScopeFallback()
scoped-->>Test: null
end
end
|
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 5 files
Architecture diagram
sequenceDiagram
participant Caller as Snapshot Capture
participant Scope as tryScopedSnapshot
participant Resolve as Object ID Resolver
participant CDP as CDP / MockSession
participant Context as Execution Contexts
Note over Caller,Context: Diagram 1: Scoped Accessibility & Focus Resolution (New Test Coverage)
Caller->>Scope: tryScopedSnapshot(page, options)
alt Selectors Provided (CSS or XPath)
Scope->>Resolve: resolveObjectId(selector)
alt Strategy: XPath
Resolve->>Context: waitForMainWorld()
Context-->>Resolve: contextId
Resolve->>CDP: Runtime.evaluate(xpath, contextId)
else Strategy: CSS
Resolve->>CDP: Runtime.evaluate(primarySelector)
opt Primary Evaluation Fails
Resolve->>CDP: Runtime.evaluate(fallbackPierceSelector)
end
end
alt Resolution Success
CDP-->>Resolve: objectId
Resolve-->>Scope: objectId
Scope->>CDP: Accessibility.getFullAXTree(objectId)
CDP-->>Scope: Trimmed AX Tree
Scope-->>Caller: Scoped Snapshot (scopeApplied: true)
else Resolution Fails / Error
Resolve-->>Scope: null
Scope-->>Caller: null (Fallback to full snapshot)
end
else No Selector
Scope-->>Caller: null
end
Caller->>CDP: Accessibility.getFullAXTree(depth: -1)
CDP-->>Caller: Full AX Tree
sequenceDiagram
participant Service as Snapshot Service
participant Builder as DOM Builder
participant CDP as CDP / MockSession
Note over Service,CDP: Diagram 2: Robust DOM Fetching with CBOR Fallback (New Test Coverage)
Service->>Builder: getDomTreeWithFallback()
Builder->>CDP: DOM.getDocument(depth: -1)
alt Standard Success
CDP-->>Builder: Full DOM Tree
else CBOR Error (Stack Limit Exceeded)
Note right of Builder: NEW: Retry logic for large DOMs
Builder->>CDP: DOM.getDocument(depth: 256)
CDP-->>Builder: Partial DOM Tree
loop For every truncated node
Builder->>Builder: hydrateDomTree(node)
Builder->>CDP: DOM.describeNode(backendNodeId, depth: 2)
alt Describe Success
CDP-->>Builder: Node Details
else CBOR Error on Describe
Note right of Builder: Retry describe once
Builder->>CDP: DOM.describeNode(backendNodeId)
CDP-->>Builder: Node Details
end
end
else Network/Other Error
CDP-->>Builder: Throw Error
Builder-->>Service: Throw StagehandDomProcessError
end
Builder-->>Service: Fully Hydrated DOM Root
1117b16 to
1d219bf
Compare
why
captureHybridSnapshot()depends onwhat changed
added
snapshot-a11y-resolvers.test.tswhich tests the following functions:a11yForFrame()frameIdscopeAppliedfalseresolveObjectIdForXPath()resolveObjectIdForCss()primaryExprevaluation success, the object id is returnedfallbackExpris used whenprimaryExprfailsprimaryExprandfallbackExprfailtryScopedSnapshot()a11yForFrame()returnsscopeApplied: falsethe helper logs and returns nulltest plan
Summary by cubic
Adds unit tests covering AX tree scoping, CSS/XPath object ID resolvers, DOM session builders, and CBOR fallback paths to harden captureHybridSnapshot and related helpers.
Written for commit 1117b16. Summary will update automatically on new commits.