Skip to content

feat: PER-7348 add waitForReady() call before serialize()#30

Merged
Shivanshu-07 merged 7 commits into
mainfrom
PER-7348-readiness-in-serialize
May 26, 2026
Merged

feat: PER-7348 add waitForReady() call before serialize()#30
Shivanshu-07 merged 7 commits into
mainfrom
PER-7348-readiness-in-serialize

Conversation

@Shivanshu-07

Copy link
Copy Markdown
Contributor

Summary

Adopts the readiness gate from percy/cli#2184 (PER-7348). New wait_for_ready(driver, options) 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 snapshot hash as 'readiness_diagnostics'. Serialize is unchanged.

Contract

  • Config precedence: options[:readiness] / options['readiness']@cli_config.dig('snapshot','readiness'){} (CLI balanced default)
  • Backward compat: in-browser typeof PercyDOM.waitForReady === 'function' guard
  • Disabled preset short-circuits
  • Graceful on any StandardError; logged at debug

Tests

4 new RSpec tests inside describe '.get_serialized_dom':

  • ✅ happy path — execute_async_script called with waitForReady + typeof guard; diagnostics attached
  • ✅ per-snapshot config embedded in the script (JSON-escaped)
  • ✅ disabled preset skips execute_async_script
  • ✅ raised execute_async_script leaves serialize intact

Test results

Check Status Notes
Syntax (ruby -c) ✅ pass
Unit tests (bundle exec rspec) ⚠️ not executed locally bundle install needs capybara ~> 3.35; not present on fan-out machine
Smoke test ⚠️ skipped: toolchain missing

Related

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>
Shivanshu-07 and others added 6 commits May 22, 2026 12:18
- 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.
@Shivanshu-07 Shivanshu-07 marked this pull request as ready for review May 25, 2026 11:42
@Shivanshu-07 Shivanshu-07 requested a review from a team as a code owner May 25, 2026 11:42
@Shivanshu-07 Shivanshu-07 merged commit 9a71cdb into main May 26, 2026
6 checks passed
@Shivanshu-07 Shivanshu-07 deleted the PER-7348-readiness-in-serialize branch May 26, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants