Skip to content

test(tools): comprehensive test suite for browser_utils module (+107 tests) - #153

Open
manus-use wants to merge 1 commit into
mainfrom
feat/test-browser-utils
Open

test(tools): comprehensive test suite for browser_utils module (+107 tests)#153
manus-use wants to merge 1 commit into
mainfrom
feat/test-browser-utils

Conversation

@manus-use

Copy link
Copy Markdown
Owner

Summary

Adds a comprehensive test suite for the manus_agent.tools.browser_utils module — 107 fully-mocked tests covering the entire public API surface.

What's tested

Area Tests Coverage
BrowserTimeoutError 6 Exception construction, message formatting, attribute access
make_dom_read_script_null_safe 9 All 5 DOM property patterns (textContent, innerText, innerHTML, value, href), empty/unrelated scripts, multiple patterns
normalize_evaluate_script 14 Function/arrow passthrough, expression wrapping, statement block wrapping, empty/whitespace/non-string edge cases
prepare_evaluate_script 3 Combined null-safety + normalization pipeline
normalize_browser_selector 9 Whitespace stripping, quote removal, None/empty/non-string handling, mismatched quotes
is_selector_syntax_error 8 All 6 error marker patterns, false negatives for timeouts/generic errors
is_probably_raw_text_page 8 URL hints (.patch/.diff), content-type detection, pre-only heuristic, rich page rejection, exception handling
extract_raw_page_text 5 pre/body/documentElement fallback chain, all-fail case, empty-string skipping
get_text_with_fallback 10 Primary selector success, fallback chain, timeout propagation, raw-text fallback, syntax error raising, custom timeout
get_html_with_fallback 9 No-selector full page, valid selector inner_html, timeout handling, raw-text detection, syntax errors, custom timeout
find_best_content_selector 5 Priority ordering, short-content skipping, body fallback, exception resilience
extract_page_text 5 Success path, HTML fallback, JS fallback, all-fail error path, URL exception handling
format_browser_error 7 Basic formatting, URL/selector context, Playwright timeout suggestions, empty/no context
Module constants 5 DEFAULT_TIMEOUT, RAW_TEXT_URL_HINTS, FALLBACK_SELECTORS structure validation

Why this module

browser_utils.py (287 lines) is the foundational utility layer for all browser-related tools — it handles timeout management, selector normalization, evaluate script preparation, fallback logic, and raw-text page detection. Despite being imported by both use_browser_patch.py and browser_tools.py, it had virtually zero dedicated test coverage (only a single import reference in test_tools.py).

Testing approach

  • 100% mocked — no real browser, Playwright, or HTTP calls
  • All async functions tested with pytest.mark.asyncio
  • Playwright TimeoutError properly simulated
  • Page objects mocked with AsyncMock for realistic async behavior

Open PRs checked (no overlap)

This PR tests browser_utils.py — none of the following open PRs cover this module:

Test results

1265 passed, 3 deselected, 3 warnings in 24.50s

(Baseline: 1158 + 107 new = 1265 total, 0 failures)

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.

1 participant