test: restore 100% coverage — cover the 46 snapshot.py branches left untested by #226#247
Merged
Merged
Conversation
PR #226 (CORS iframes + closed shadow DOM parity) added new guard and error-fallback branches to percy/snapshot.py without tests for all of them, dropping total coverage from 100% to 94% and tripping the fail-under=100 gate in `make coverage` on every run since — both normal push CI (released @percy/cli) and the PER-9772 regression dispatch (@percy/cli built from git) fail with the identical missing-lines set, so the gap is deterministic, not CLI-flavor dependent. Add plain unit tests (no CLI needed) to tests/test_snapshot_units.py covering every previously missed line: - 36-37: invalid PERCY_RESIZE_SETTLE_SECONDS falls back to 0.5 - 247-248, 253-254: _should_skip_iframe invalid-origin / missing percyElementId skips - 272-274, 303-305, 316-317, 341-343, 364-366, 374, 377: process_frame_tree depth cap, missing element, document.URL read failure, empty serialize result, nested-enumeration failure, skipped child continue, nested capture collection - 408-409, 416: context-loss recovery (default_content failure at depth 1; PercyContextLost chaining the original error at depth > 1) - 460-462: _capture_cors_iframes outer error guard - 483-484, 549, 557-560, 564-565: expose_closed_shadow_roots capabilities failure, missing objectIds, resolveNode failure, getDocument + DOM.disable failures - 605, 607-608, 613-614: get_origin parse failures and _get_origin shim - 807-808: get_serialized_dom current_url read failure - 959-963: PERCY_DEBUG responsive snapshot dump (write + failure path) Verified locally on Python 3.9: full `make coverage` sequence (test_snapshot under `percy exec --testing` + the five plain modules) reports 759/759 statements, TOTAL 100%; pylint 10.00/10. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
aryanku-dev
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The PER-9772 SDK-regression dispatch run (28640545663) failed
make coveragewith zero test failures — only the coverage gate tripped:percy/snapshot.py 564 stmts, 46 miss, 92%→ TOTAL 94% <fail_under = 100(.coveragerc).This is not CLI-flavor dependent. The normal push-CI run for the same commit (28495875576 / 28495790591, released
@percy/cli) fails with the byte-identical missing-lines list. Master has been red since #226 (feat: CORS iframes + closed shadow DOM parity) merged: it added new guard/error-fallback branches topercy/snapshot.pywithout tests for all of them.Exact missing lines (identical in both the dispatch and push runs):
Fix
Add deterministic, CLI-independent unit tests to
tests/test_snapshot_units.py(runs as a plain unittest module, nopercy exec) covering every missed branch:PERCY_RESIZE_SETTLE_SECONDSenv falls back to 0.5 (module reload)_should_skip_iframe: unparseable origin; cross-origin frame missingdata-percy-element-idprocess_frame_tree: depth >max_frame_depthcapdata-percy-element-iddocument.URLread failure treated as unsupportedPercyDOM.serializeresult for a framecontinue); successful nested capture collecteddefault_content()failure swallowed at depth 1PercyContextLostchains the original processing error as__cause___capture_cors_iframesouter error guard (malformed enumeration entry)driver.capabilitiesaccess failure treated as non-ChromiumobjectIds,DOM.resolveNodefailure,DOM.getDocument+DOM.disablefailuresget_originno-scheme/netloc and parse-raise paths;_get_origincompat shimdriver.current_urlread failure inget_serialized_domPERCY_DEBUGresponsive snapshot dump (write path + failure path)No production code changes and no
# pragma: no cover— all branches are deterministically exercisable with mocks. Since the new tests never touch the CLI, coverage of these lines no longer depends on which@percy/cli(released or built-from-git) is installed.Verification
Local, Python 3.9.18, mirroring the Makefile
coveragetarget exactly (tests.test_snapshotunderpercy exec --testingwith @percy/cli 1.32.2 + the five plain modules,coverage combine,coverage report):tests.test_snapshot_unitspass (was 8, +25 new);tests.test_snapshotunchanged and green (96 tests).pylint percy/* tests/*→ 10.00/10.🤖 Generated with Claude Code