Skip to content

Conversation

@seanmcguire12
Copy link
Member

@seanmcguire12 seanmcguire12 commented Dec 19, 2025

why

  • to add more coverage for the hybrid snapshot flow by testing lower level helpers

what changed

added tests/snapshot-a11y-tree-utils.test.ts which tests:

  • decorateRoles()
    • checks that scrollable nodes get labelled correctly
    • checks that #document nodes get left as 'generic'
    • checks that html nodes always get the scrollable label
  • buildHierarchicalTree()
    • checks that structural nodes with no meaningful content are excluded
    • combobox & select roles are remapped to their HTML tag names
    • tag name substitution is applied to non-combobox structural nodes
    • nodes with negative IDs are skipped
  • isStructural()
    • confirms "generic", "none", and "InlineTextBox" roles are flagged structural while real roles like "button" stay non-structural
  • removeRedundantStaticTextChildren()
    • removes StaticText children when their combined text exactly matches the parent label, keeps them when the text differs, and returns the original array when the parent has no name
  • extractUrlFromAXNode()
    • trims and returns the URL when a valid url property exists, but yields undefined when the property is missing or the value isn’t a string

test plan

  • this is it

Summary by cubic

Add unit tests for AX tree post-processing helpers to increase coverage of the hybrid snapshot flow (STG-1095). Covers role decoration (scrollable labels, encoding fallback), hierarchical tree building (structural pruning, tag remapping, negative ID skip), structural role detection, redundant StaticText pruning, and URL extraction.

Written for commit 310fd75. Summary will update automatically on new commits.

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2025

⚠️ No Changeset found

Latest commit: 310fd75

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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 1 file

Architecture diagram
sequenceDiagram
    participant Test as Vitest Runner
    participant Utils as a11yTree Utils
    participant Helper as Helper Functions

    Note over Test,Helper: NEW: Unit Test Coverage for Hybrid Snapshot Processing

    %% decorateRoles Tests
    rect rgb(23,37,84)
        Note right of Test: Test Suite: decorateRoles()
        Test->>Utils: decorateRoles(nodes, options)
        
        loop For each node
            Utils->>Utils: Lookup backendID in tagNameMap
            alt Node mapped as Scrollable
                Utils->>Utils: NEW TEST: Prepend "scrollable" to role
            else Standard Node
                Utils->>Utils: Keep original role
            end
            opt Encoding Error
                Utils->>Utils: NEW TEST: Handle encoding fallback
            end
        end
        Utils-->>Test: Decorated Nodes
        Test->>Test: Assert roles & labels
    end

    %% buildHierarchicalTree Tests
    rect rgb(23,37,84)
        Note right of Test: Test Suite: buildHierarchicalTree()
        Test->>Utils: buildHierarchicalTree(nodes)

        loop Tree Construction
            Utils->>Helper: isStructural(role)
            Helper-->>Utils: true/false
            
            alt NEW TEST: Negative Node ID
                Utils->>Utils: Skip Node
            else NEW TEST: Structural Node (generic/none)
                alt No Name & No Children
                    Utils->>Utils: Prune from tree
                else Only Structural Children
                    Utils->>Utils: Prune & promote descendants
                else Valid Content
                    Utils->>Utils: Remap tag name (e.g. section)
                end
            else NEW TEST: Role is Combobox/Select
                Utils->>Utils: Force role to HTML tag name
            end
            
            Utils->>Helper: removeRedundantStaticTextChildren()
            alt NEW TEST: Child text == Parent Name
                Helper-->>Utils: Remove child
            else Text differs
                Helper-->>Utils: Keep child
            end
        end

        Utils-->>Test: Final Hierarchical Tree
        Test->>Test: Assert structure & pruning
    end

    %% URL Extraction Tests
    rect rgb(23,37,84)
        Note right of Test: Test Suite: extractUrlFromAXNode()
        Test->>Utils: extractUrlFromAXNode(node)
        alt NEW TEST: Valid String Property
            Utils-->>Test: Return trimmed URL
        else Invalid/Missing
            Utils-->>Test: Return undefined
        end
    end
Loading

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 19, 2025

Greptile Summary

Added comprehensive unit tests for AX tree post-processing utilities to increase test coverage for the hybrid snapshot flow. The tests cover:

  • decorateRoles(): Validates scrollable node labeling, #document handling, and encoding fallback behavior
  • buildHierarchicalTree(): Tests structural node pruning, combobox/select remapping, tag name substitution, and negative ID filtering
  • isStructural(): Confirms role classification for structural vs semantic roles
  • removeRedundantStaticTextChildren(): Validates StaticText pruning when concatenated text matches parent name
  • extractUrlFromAXNode(): Tests URL extraction and trimming from node properties

All test data is well-structured using helper functions like makeAxNode() and axString() for creating consistent test fixtures.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The PR only adds comprehensive unit tests without modifying any production code, all test cases are well-structured with clear assertions, and the tests validate critical edge cases like encoding failures, negative IDs, and text normalization
  • No files require special attention

Important Files Changed

Filename Overview
packages/core/tests/snapshot-a11y-tree-utils.test.ts Comprehensive unit tests added for AX tree post-processing helpers covering role decoration, hierarchical tree building, structural detection, text pruning, and URL extraction

Sequence Diagram

sequenceDiagram
    participant Test as Test Suite
    participant Decorate as decorateRoles()
    participant Build as buildHierarchicalTree()
    participant Prune as pruneStructuralSafe()
    participant Static as removeRedundantStaticTextChildren()
    
    Note over Test: Test Flow for AX Tree Post-Processing
    
    Test->>Decorate: Pass AXNode[] + options
    Decorate->>Decorate: Encode backendDOMNodeId
    Decorate->>Decorate: Check scrollable/html tags
    Decorate->>Decorate: Apply role labels
    Decorate-->>Test: Return A11yNode[]
    
    Test->>Build: Pass decorated nodes
    Build->>Build: Filter structural nodes without content
    Build->>Build: Build parent-child relationships
    Build->>Prune: Process each root node
    Prune->>Prune: Skip negative nodeIds
    Prune->>Prune: Recursively clean children
    Prune->>Static: Remove redundant StaticText
    Static->>Static: Compare concatenated text to parent
    Static-->>Prune: Return filtered children
    Prune->>Prune: Apply tag name remapping
    Prune-->>Build: Return cleaned node
    Build-->>Test: Return hierarchical tree
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@seanmcguire12
Copy link
Member Author

@greptileai

@seanmcguire12 seanmcguire12 merged commit 73eda31 into main Dec 19, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants