feat: PER-7348 add waitForReady() call before serialize()#30
Merged
Conversation
Adds the readiness gate from percy/cli#2184. New wait_for_ready() helper runs PercyDOM.waitForReady via driver.execute_async_script (callback signal) before the existing PercyDOM.serialize execute_script inside get_serialized_dom. The return value is attached to the domSnapshot hash as 'readiness_diagnostics'. serialize is unchanged. Config precedence: options[:readiness] (or 'readiness') > @cli_config.dig('snapshot','readiness') > {} (CLI applies balanced default). Backward compat via in-browser typeof guard. Disabled preset skips the execute_async_script. Graceful on any StandardError. Tests (RSpec): happy path (execute_async_script called with waitForReady + typeof guard, diagnostics on snapshot), per-snapshot config embedded, disabled preset skips execute_async_script, and execute_async_script raising leaves serialize intact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Replaced exclusive precedence (`if nil? else fallback`) with shallow-
merge in a new `resolve_readiness_config` helper. Per-snapshot keys
win, global @cli_config.snapshot.readiness keys inherited — a partial
per-snapshot override no longer silently drops a global preset:disabled.
Also normalises symbol vs string keys so :preset and 'preset' collapse.
- Match driver script_timeout to readiness.timeoutMs (+ 2s buffer)
around the execute_async_script call, with ensure-restore. Avoids the
default ~30s Selenium script timeout silently capping higher
user-configured readiness timeouts via ScriptTimeoutException.
- Strip `readiness` from forwarded PercyDOM.serialize args (consumed by
wait_for_ready upstream) and from the fetch('percy/snapshot', **post_options)
body (CLI already has it via healthcheck).
- Diagnostics-attach now uses `!nil?` instead of truthy check — preserves
legitimate empty-hash returns from waitForReady.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Replaced em-dash (—) with -- in lib/percy.rb comments (Style/AsciiComments)
- Added trailing comma in spec (Style/TrailingCommaInArguments)
- Removed redundant {} wrapping around keyword-style hash literals in spec
(Layout/SpaceInsideHashLiteralBraces)
- Suppressed RSpec/MessageSpies on the two readiness specs that use the
spy pattern intentionally (have_received after action)
CLI 1.31.15-beta.0 ships PercyDOM.waitForReady (the readiness gate). The SDK changes in this PR call waitForReady end-to-end in tests; old CLI pins (1.30.9, 1.31.10) don't have it, causing the typeof guard's done() callback path to never quite settle in geckodriver's async-script handling. Bump so tests run against a CLI that actually has the feature.
The previous commit on this branch (11628af) accidentally bundled a local Python virtualenv into the repo. Remove every .venv path from the index and add .gitignore entry so it can't happen again.
rishigupta1599
approved these changes
May 25, 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.
Summary
Adopts the readiness gate from percy/cli#2184 (PER-7348). New
wait_for_ready(driver, options)helper runsPercyDOM.waitForReadyviadriver.execute_async_script(callback signal) before the existingPercyDOM.serializeexecute_scriptinsideget_serialized_dom. The return value is attached to the snapshot hash as'readiness_diagnostics'. Serialize is unchanged.Contract
options[:readiness]/options['readiness']→@cli_config.dig('snapshot','readiness')→{}(CLIbalanceddefault)typeof PercyDOM.waitForReady === 'function'guardStandardError; logged at debugTests
4 new RSpec tests inside
describe '.get_serialized_dom':execute_async_scriptcalled withwaitForReady+ typeof guard; diagnostics attachedexecute_async_scriptexecute_async_scriptleaves serialize intactTest results
ruby -c)bundle exec rspec)bundle installneeds capybara ~> 3.35; not present on fan-out machineRelated