Skip to content

test: browser coverage for accessor attach timing (state contract + event laziness) - #420

Open
cpsievert wants to merge 3 commits into
feat/eager-state-accessorsfrom
test/eager-accessor-regression
Open

cpsievert wants to merge 3 commits into
feat/eager-state-accessorsfrom
test/eager-accessor-regression

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

Stacked on #412.

Summary

Browser-level tests for accessor attach timing, following up #412:

  • test_state_accessor_captures_gesture_before_first_read — a zoom-in gesture before a button-gated first read of ipyleaflet zoom(); the read reflects the gesture. This is a scenario-contract guard, not a feat: state-kind accessors attach eagerly at render by default #412-specific regression test: it passes both pre- and post-feat: state-kind accessors attach eagerly at render by default #412 (verified by flipping AccessorSpec.eager's default back to False), because ipyleaflet pushes synced traits unconditionally and the lazy attach's seed self-heals. What it guards is the user-visible contract against any future frontend that gates state sync on a listener existing. Attach timing itself is covered by feat: state-kind accessors attach eagerly at render by default #412's unit tests.
  • test_event_accessor_misses_click_before_first_read — characterization of intentional behavior: kind="event" clicked() still attaches lazily, so a pre-read map click is missed while post-read clicks are captured. Acts as a tripwire if the event default ever changes.

The app fixture gates all accessor reads behind @reactive.event buttons and exposes a raw-trait sentinel output so tests wait for browser→server sync deterministically.

A survey of every state-kind accessor in the package (ipyleaflet, jscatter, altair, bokeh, quak, mosaic, perspective, itables, ipydatagrid, embedding_atlas, pythreejs, k3d, ipyaladin, lonboard, matplotlib) found all are trait/signal-backed with self-healing seeds; the only browser-listener-gated mechanisms are the plotly bridge (event-kind only) and the reactable bridge (state-kind, but re-seeds on bind). So no current state accessor can discriminate pre/post-#412 in a browser test — a truly discriminating test would need a listener-gated state frontend that doesn't exist in the package yet.

Verification

State-kind scenario (zoom before a gated first read): guards the contract
that a gesture made before the accessor's first read is reflected in that
read. It passes both pre- and post-#412 -- ipyleaflet pushes its synced
traits to Python unconditionally, so the pre-#412 lazy attach's seed
self-healed -- and would catch a frontend that ever gates its state sync
on a Python-side listener.

Event-kind characterization (clicked): documents the intentional lazy
attach -- a map click made before the first read is missed, and clicks
after it are captured.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The test can pass before the first read completes and accept coordinates from the pre-read click, so it may miss an eager-listener regression without a distinct no-event value to wait for.

1 open issue
What changed in this PR

Adds browser coverage for accessor behavior when the first read is delayed, complementing #412’s unit tests for attach timing.

Changes:

  • Adds a state-accessor contract test verifying that a zoom gesture is reflected in the first read.
  • Adds an event-accessor characterization test for lazy click-listener attachment.
  • Introduces a fixture with button-gated reads and a raw zoom-trait synchronization sentinel.
File Description
tests/​playwright/​ipyleaflet_eager_attach/​test_ipyleaflet_eager_attach.py Adds browser tests for state and event behavior before the first accessor read.
tests/​playwright/​ipyleaflet_eager_attach/​app.py Provides gated accessor reads and a zoom synchronization output.

Review effort: Balanced

An empty string couldn't distinguish 'server processed the read and
there was no event' from 'server hasn't re-rendered yet', so the test
could proceed to the second map click before the lazy listener attached
(and, if event accessors ever become eager, accept stale coordinates).
Waiting for the distinct None marker fixes both.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified in the added browser-level coverage for accessor behavior before the first read.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@cpsievert
cpsievert marked this pull request as ready for review November 4, 2026 18:27
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.

2 participants