Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions percy/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,19 +500,23 @@ def percy_snapshot(driver, name, **kwargs):
driver.execute_script(percy_dom_script)
cookies = driver.get_cookies()

# Merge .percy.yml config options with snapshot options (snapshot options take priority)
config_options = data['config'].get('snapshot') or {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[Medium] Guard config itself against null, not just `config['snapshot']

This fixes snapshot being null, but data['config'] itself can be None: is_percy_enabled() does data.get('config', {}), which only defaults when the key is absent — a healthcheck returning {"config": null} makes data['config'] None, and .get('snapshot') then raises AttributeError. The codebase's own _resolve_readiness_config defends against exactly this (config = percy_config or {}, see snapshot.py:198-200).

Suggestion:

Suggested change
config_options = data['config'].get('snapshot') or {}
config_options = (data['config'] or {}).get('snapshot') or {}

Reviewer: stack:code-review

merged_kwargs = {**config_options, **kwargs}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[Medium] Missing tests for the new config-merge behavior

No test covers that config-level snapshot options flow into serializeDOM, that per-call kwargs override config options, or that a null snapshot config degrades to {} on the percy_snapshot path. The existing null-config test (test_snapshot.py:505) only exercises _resolve_readiness_config, a different function.

Suggestion: Add percy_snapshot tests with mocked healthcheck config {'snapshot': {...}} asserting the option reaches the serialize path, a kwargs-override case, and a {'snapshot': None} (and config: None) case.

Reviewer: stack:code-review


# Serialize and capture the DOM
if is_responsive_snapshot_capture(data['config'], **kwargs):
if is_responsive_snapshot_capture(data['config'], **merged_kwargs):
dom_snapshot = capture_responsive_dom(
driver=driver,
cookies=cookies,
config=data['config'],
percy_dom_script=percy_dom_script,
**kwargs,
**merged_kwargs,
)
else:
dom_snapshot = get_serialized_dom(
driver, cookies, percy_config=data.get('config'),
percy_dom_script=percy_dom_script, **kwargs)
percy_dom_script=percy_dom_script, **merged_kwargs)

# Strip SDK-local `readiness` from the snapshot POST body. The CLI
# already has it via healthcheck; sending it again here risks future
Expand Down
Loading