Stage 2 fixes: the two tests the review named, and the docs drift
From docs/reviews/2026-10-04-stage2-3-review.md (Stage 3 done; Stage 2
done-with-fixes). Its findings 1, 2, 3 and 5, which it called the only
things standing before merge.
(A) REPLAY, THROUGH THE SINK. What existed was
`test_every_keyboard_verb_is_cached_for_the_same_reason`, which
asserts the two verbs are in MUTATING_VERBS -- and the verification
doc had already named that as the false pass: "asserting
`deduplicated` and not the sink. A handler that types and then sets
the flag stays green." Two integration tests now, modelled on
`test_a_retried_click_with_the_same_request_id_clicks_once`:
test_a_retried_type_with_the_same_request_id_types_once
`keyboard.type` of "ab" twice with request_id="retry-me".
Asserts `deduplicated`, chars == 2 on both, and that the sink
still has exactly 4 key events -- two characters, a down and an
up each -- so a replay that typed again is caught by the count
and not by the flag.
test_a_retried_unmappable_type_stays_refused_and_types_nothing
`café` twice with one id. Both refusals are `invalid_argument`,
the second carries `deduplicated` (a recorded failure is
replayed as the failure it was), and the sink is empty after
both -- there is no partial type on either call.
Mutation-checked rather than assumed: removing `keyboard.key` and
`keyboard.type` from MUTATING_VERBS fails both.
(B) KILL, THROUGH kill(). `test_killing_the_holder_lifts_its_keys` calls
`_drop_lease_for` directly, so it proves that helper lifts keys and
says nothing about whether `kill` still calls it. The integration
kill test now holds `Shift_L` before the kill and asserts the SINK
saw `("key", 42, 0)` and `("modifiers", 0, 0, 0, 0)` -- the lease
forgetting a key is not the compositor being told it came up, and
only the second matters to the application. Code 42 because `type`
never emits it, so the release cannot be a leftover.
Mutation-checked: stubbing out the `_drop_lease_for` call in
`kill()` fails it. Before this it stayed green.
(C) DOCS. The plan's stage table and risk paragraph still said acquire
is one warp and that `focuswindow` was unbuilt Stage 4 work. The
contract (v3 §4) describes what shipped; the plan did not. Rewritten
so they agree, and the plan now says outright that the contract wins
where they differ:
* risk 1 marked RESOLVED, describing the two warps, the pinned
`follow_mouse_threshold`, and `focuswindow` as the
nudge-failure fallback selecting on `address:` (not
`stable_id`, which is not a Hyprland selector)
* Stage 3 marked Done; Stage 4 struck as not existing -- the
answer to Stage 0 was the second warp, not a focus dispatch
* the top banner, the §5 VM assertion list and open question 2
no longer say "one warp"
* verification §B3 subtest 1 amended: it is a live assertion
rather than an expected red, and the check additionally requires
`focus == "warp"` so the fallback is not accepted as success
Also amended one sentence the review did not list, because leaving
it would contradict the edit above inside the same document:
verification §"Warp does not guarantee wl_keyboard.enter" predicted
`focuswindow` was "likely mandatory". It was not; the second warp
was.
Written down rather than smoothed over: the `focuswindow` branch
itself has no test, and if both mechanisms fail acquire still
returns ok with `focus="none"` -- a lease whose first key may go to
the previously focused window.
(D) The tap docstring claimed the `up` is sent even if the `down` was
refused after sending. The next lines return early on `not ok`, and
that early return is right: a refusal means the key was never
pressed, so an `up` would ask the compositor to release something it
never had. Sentence replaced with why the early return is correct
and what actually covers a lost reply (the broker's `release_all`,
not the CLI, which cannot know whether the request arrived).
Not done, and not claimed: findings 4, 6 and 7 (the broker chord test
checking first/last mask rather than the key; the at-cap test not
looking at the sink; the module-defaults test being a substring match).
The review rates all three as not holes in the claim, and the driver
tests are the locks for the first two.
nix develop -c python -m pytest tests -q
907 passed in 67.71s
nix develop -c python -m pytest tests/pointer tests/sessions/unit -q
605 passed in 27.16s
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GhNPM6rGcuzxocM1nATnuM
This commit is contained in:
1 parent
54dd109dde
commit
561e0c28f5
5 files changed
+321
-15
No files matched your search
@@ -517,14 +517,42 @@ def test_a_button_left_down_is_lifted_when_the_lease_is_released(rig: Rig):
|
||||
|
||||
|
||||
def test_killing_a_session_that_holds_the_cursor_gives_it_back(rig: Rig):
|
||||
"""Through `kill`, with a button AND a key down.
|
||||
|
||||
The key half is here rather than in a unit test on purpose. The unit test
|
||||
calls `_drop_lease_for` directly, so it proves that helper lifts keys and
|
||||
says nothing about whether `kill` still calls it -- removing the call would
|
||||
leave that test green. This goes through the verb, and it asserts on the
|
||||
SINK rather than on `pointer.state`: the lease forgetting a key is not the
|
||||
same as the compositor being told it came up, and only the second one
|
||||
matters to the application.
|
||||
"""
|
||||
|
||||
first = start(rig.daemon, "sleeper")
|
||||
second = start(rig.daemon, "sleeper")
|
||||
lease = rig.daemon.call("pointer.acquire", id=first)["lease_id"]
|
||||
rig.daemon.call("pointer.button", id=first, lease_id=lease, button="right", state="down")
|
||||
held = rig.daemon.call(
|
||||
"keyboard.key", id=first, lease_id=lease, key="Shift_L", state="down"
|
||||
)
|
||||
assert held["keys"] == ["Shift_L"], held
|
||||
rig.driver.sink.calls.clear()
|
||||
|
||||
rig.daemon.call("kill", id=first, grace_s=0)
|
||||
|
||||
# KEY_LEFTSHIFT, and `state=0`. Shift is the key to use because `type`
|
||||
# never emits code 42, so a release of it cannot be a leftover from
|
||||
# anything else this rig did.
|
||||
assert ("key", 42, 0) in rig.driver.sink.calls, (
|
||||
f"kill did not lift the held key: {rig.driver.sink.calls}. On this "
|
||||
"compositor a code left in the seat's m_pressed makes the NEXT press "
|
||||
"of it a no-op, so the key is dead rather than merely stuck."
|
||||
)
|
||||
# And the mask with it: a virtual key-up clears no modifier state, so
|
||||
# without this the next holder inherits Shift.
|
||||
assert ("modifiers", 0, 0, 0, 0) in rig.driver.sink.calls, rig.driver.sink.calls
|
||||
assert rig.driver.dispatcher._pressed == {}
|
||||
assert rig.driver.dispatcher._keys == {}
|
||||
assert rig.daemon.call("pointer.state")["holder"] is None
|
||||
assert rig.daemon.call("pointer.acquire", id=second)["ok"]
|
||||
|
||||
@@ -561,6 +589,81 @@ def test_a_retried_click_with_the_same_request_id_clicks_once(rig: Rig):
|
||||
assert len(rig.driver.sink.of("button")) == 2, "one press and one release, not two"
|
||||
|
||||
|
||||
def test_a_retried_type_with_the_same_request_id_types_once(rig: Rig):
|
||||
"""A retried `type` is the keyboard's version of a second click.
|
||||
|
||||
Asserted on the SINK and not on the `deduplicated` flag, because the flag
|
||||
alone is the false pass the verification doc names: a handler that typed
|
||||
the string and *then* set the flag would satisfy it. The thing that must
|
||||
not happen twice is the key events, so those are what is counted.
|
||||
|
||||
The cache is not keyboard-specific -- `_dispatch` looks the `request_id` up
|
||||
before the handler and remembers it after, keyed on the id alone -- so what
|
||||
this locks is that `keyboard.type` is in the mutating set and therefore
|
||||
reaches that path at all.
|
||||
"""
|
||||
|
||||
session_id = start(rig.daemon, "sleeper")
|
||||
lease = rig.daemon.call("pointer.acquire", id=session_id)["lease_id"]
|
||||
rig.driver.sink.calls.clear()
|
||||
|
||||
first = rig.daemon.call(
|
||||
"keyboard.type", id=session_id, lease_id=lease, text="ab", request_id="retry-me"
|
||||
)
|
||||
second = rig.daemon.call(
|
||||
"keyboard.type", id=session_id, lease_id=lease, text="ab", request_id="retry-me"
|
||||
)
|
||||
|
||||
assert first["ok"] and second["ok"]
|
||||
assert second.get("deduplicated") is True
|
||||
assert first["chars"] == 2 and second["chars"] == 2
|
||||
# Two characters, a down and an up each: four key events for one `type`,
|
||||
# and the replay must not add a fifth.
|
||||
assert len(rig.driver.sink.of("key")) == 4, (
|
||||
f"a replayed type sent {rig.driver.sink.of('key')}; the recorded answer "
|
||||
"must be returned without typing again"
|
||||
)
|
||||
|
||||
|
||||
def test_a_retried_unmappable_type_stays_refused_and_types_nothing(rig: Rig):
|
||||
"""The recorded answer includes a recorded refusal.
|
||||
|
||||
An agent that retries a `type` which was refused must see the refusal
|
||||
again, not a second attempt -- and the sink must still be untouched after
|
||||
both calls, because validation happens before the first event either time.
|
||||
"""
|
||||
|
||||
session_id = start(rig.daemon, "sleeper")
|
||||
lease = rig.daemon.call("pointer.acquire", id=session_id)["lease_id"]
|
||||
rig.driver.sink.calls.clear()
|
||||
|
||||
first = rig.daemon.call(
|
||||
"keyboard.type",
|
||||
id=session_id,
|
||||
lease_id=lease,
|
||||
text="caf\u00e9",
|
||||
request_id="refuse-me",
|
||||
)
|
||||
second = rig.daemon.call(
|
||||
"keyboard.type",
|
||||
id=session_id,
|
||||
lease_id=lease,
|
||||
text="caf\u00e9",
|
||||
request_id="refuse-me",
|
||||
)
|
||||
|
||||
assert first["ok"] is False and second["ok"] is False
|
||||
assert first["error"] == "invalid_argument", first
|
||||
assert second["error"] == "invalid_argument", second
|
||||
assert second.get("deduplicated") is True, (
|
||||
"a recorded failure must be replayed as the failure it was"
|
||||
)
|
||||
assert rig.driver.sink.of("key") == [], (
|
||||
f"an unmappable string typed something: {rig.driver.sink.calls}. There is "
|
||||
"no partial type, on the first call or the replay."
|
||||
)
|
||||
|
||||
|
||||
def test_a_restored_bookmark_survives_a_daemon_restart(short_tmpdir: Path):
|
||||
"""That is what putting it in the record, and not only in the lease, is for."""
|
||||
|
||||
|
||||
Reference in new issue
Block a user