Skip to content

Commit 747a6b6

Browse files
ctrondlpclaude
andcommitted
fix: gate the start_emulating sequence assertion on libei 1.6, which is the only release that stores it
eis_queue_device_start_emulating_event() built the event and never copied the sequence into it, so eis_event_emulating_get_sequence() returned a zeroed struct field for every client -- upstream added the one missing assignment in libei 98cd152, released in 1.6.0 and in no earlier tag (measured 0 on 1.2.1, 1.3.901 and 1.5.0, 4242 on 1.6.0). requires_symbol is blind to this class of difference, where every version from the 1.0.0 floor up exports the symbol and only the answer changed, so conftest grew has_symbol() for a branch instead of a skip; the 0 is asserted rather than skipped, keeping the newly documented behaviour under test on an old library. Documented on the property and in the README beside touch_up_event, the other accessor that degrades rather than raising. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent fb9ebce commit 747a6b6

6 files changed

Lines changed: 117 additions & 20 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ All notable changes to python-libei are recorded here. The format follows
1616
`eis.Device.device_type`/`height` were all unexercised. Each is a ctypes
1717
binding to a separate C symbol, so an unexercised one is where a wrong
1818
symbol name or a wrong `restype` hides -- a mistake reading cannot catch,
19-
only letting the library answer. All of them were in fact correct: every
20-
value round-trips exactly (button 272, scroll 3.5/-2.0, discrete 120/-240,
21-
absolute 100/200, sequence 4242, modifiers 4/0/2/0). Driven in one
22-
negotiation rather than one test apiece, because the handshake is the
23-
expensive part and the values then have to agree within the same frame.
19+
only letting the library answer. Every binding was in fact correct, and
20+
on libei 1.6 every value round-trips exactly (button 272, scroll
21+
3.5/-2.0, discrete 120/-240, absolute 100/200, sequence 4242, modifiers
22+
4/0/2/0). Driven in one negotiation rather than one test apiece, because
23+
the handshake is the expensive part and the values then have to agree
24+
within the same frame.
2425

2526
The absolute leg needed a region to be configured on the device. libei
2627
1.0.0's `ei_device_pointer_motion_absolute` ends in
@@ -29,6 +30,29 @@ All notable changes to python-libei are recorded here. The format follows
2930
error, just an event that never arrived. Local libei 1.6 delivered it
3031
anyway, which is why this only showed up on the CI runners' 1.0.x.
3132

33+
### Documented
34+
35+
- **`eis.Event.emulating_sequence` reads 0 on every libei before 1.6, no
36+
matter what the client sent.** `eis_queue_device_start_emulating_event()`
37+
built the event and never copied the sequence into it, so the getter
38+
returned a zeroed struct field; upstream added the one missing
39+
assignment in libei 1.6.0 (commit `98cd152`) and in no earlier tag.
40+
Measured 0 on 1.2.1, 1.3.901 and 1.5.0, and 4242 on 1.6.0 -- which
41+
covers Ubuntu 24.04 and Debian 13, so it is what most users of this
42+
package will see. The accessor and its binding are correct; there is
43+
simply nothing in the event to read, and because the symbol is exported
44+
from the 1.0.0 floor up there is nothing to raise either, leaving a 0
45+
indistinguishable from a client that really sent 0. Now stated on the
46+
property and in the README beside `Event.touch_up_event`, the other
47+
accessor that degrades rather than raising. The client-side
48+
`ei.Event.emulating_sequence` is unaffected -- libei has always stored
49+
it -- so only the EIS leg of the new round-trip test is version-gated,
50+
and it asserts the 0 rather than skipping, which keeps the documented
51+
claim under test on an old library instead of merely unchallenged.
52+
`tests/conftest.py` grew `has_symbol()` for that branch: the existing
53+
`requires_symbol` mark cannot see this class of difference, where the
54+
symbol is present on every version and only its answer changed.
55+
3256
### Fixed
3357

3458
- **`ei_region_convert_point` was marked as needing libei 1.1, and does

‎README.md‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,20 @@ Exactly what was run, when, and against which versions:
195195

196196
Nothing is resolved until it is called, so a build without one of these
197197
costs you only that call — it raises `LibraryNotFoundError` naming the
198-
missing symbol, while the rest of the package keeps working. The one
199-
exception is `Event.touch_up_event`, which degrades instead of raising:
200-
on libei older than 1.4 it reports `is_cancel=False`, since a library
201-
with no notion of cancellation genuinely never sends one.
198+
missing symbol, while the rest of the package keeps working. Two
199+
accessors degrade instead of raising, because every supported version
200+
exports the symbol and only the answer changed — so there is nothing to
201+
resolve and nothing to report:
202+
203+
- `Event.touch_up_event` reports `is_cancel=False` on libei older than
204+
1.4, since a library with no notion of cancellation genuinely never
205+
sends one.
206+
- `eis.Event.emulating_sequence` reads 0 on libei older than 1.6
207+
whatever the client sent: libeis queued the start_emulating event
208+
without ever copying the sequence into it, until 1.6.0 added the
209+
missing assignment. A 0 on an older build is indistinguishable from a
210+
client that really sent 0. The client-side
211+
`ei.Event.emulating_sequence` is unaffected.
202212

203213
These versions were established by building libei 1.2.1 and diffing its
204214
exported symbols against every binding here, not by reading `@since`

‎src/libei/eis.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,18 @@ def seat_capabilities(self) -> tuple[DeviceCapability, ...]:
944944

945945
@property
946946
def emulating_sequence(self) -> int:
947-
"""Sequence number of the start_emulating transaction."""
947+
"""Sequence number of the start_emulating transaction.
948+
949+
Reads 0 on libei older than 1.6, whatever the client sent. libeis
950+
queued the event without ever copying the sequence into it, so the
951+
getter returned a zeroed struct field; upstream added the missing
952+
assignment in libei 1.6.0. Every version from this package's 1.0.0
953+
floor up exports the symbol, so there is nothing to raise and no
954+
way to tell an old library apart from a client that genuinely sent
955+
0 -- treat a 0 here as "unknown" unless you know both ends are on
956+
1.6. :attr:`libei.ei.Event.emulating_sequence`, the receiver side
957+
of the same transaction, is unaffected: libei has always stored it.
958+
"""
948959
self._require("emulating_sequence", EventType.DEVICE_START_EMULATING)
949960
return _capi.libeis.event_emulating_get_sequence(self)
950961

‎tests/conftest.py‎

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ def pytest_configure(config: pytest.Config) -> None:
3131
)
3232

3333

34+
def has_symbol(soname: str, symbol: str) -> bool:
35+
"""Whether the installed native library exports ``symbol``.
36+
37+
The boolean behind :func:`requires_symbol`, split out for the cases
38+
that must not skip. A test whose *subject* is present on every version
39+
but whose *expected value* changed with one needs to run either way and
40+
branch on the version -- see the sequence assertion in
41+
``test_integration_socketpair.py`` -- and for that a mark is no use.
42+
"""
43+
import ctypes
44+
45+
try:
46+
return hasattr(ctypes.CDLL(soname), symbol)
47+
except OSError:
48+
return False
49+
50+
3451
def requires_symbol(soname: str, symbol: str) -> pytest.MarkDecorator:
3552
"""Skip unless the installed native library exports ``symbol``.
3653
@@ -41,13 +58,12 @@ def requires_symbol(soname: str, symbol: str) -> pytest.MarkDecorator:
4158
and then silently produces no device, so a test waiting on one hangs
4259
until its timeout and fails rather than skipping. Checking the symbol
4360
up front decides before any negotiation starts.
44-
"""
45-
import ctypes
4661
47-
try:
48-
present = hasattr(ctypes.CDLL(soname), symbol)
49-
except OSError:
50-
present = False
62+
Only use this where the symbol's *absence* is the thing being handled.
63+
Where an older library exports the symbol and answers wrongly, this
64+
gate is blind -- reach for :func:`has_symbol` and a branch instead.
65+
"""
5166
return pytest.mark.skipif(
52-
not present, reason=f"{soname} does not export {symbol} (libei too old)"
67+
not has_symbol(soname, symbol),
68+
reason=f"{soname} does not export {symbol} (libei too old)",
5369
)

‎tests/test_documentation_shape.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ def test_readme_version_gated_features_are_named_with_their_versions() -> None:
224224
# claims it is. `region_at` genuinely arrives in 1.1 and keeps that
225225
# row pinned.
226226
("region_at", "1.1"),
227+
# Not in the table above it -- the table's entries raise
228+
# `LibraryNotFoundError` on an older build, and this one cannot,
229+
# since every supported version exports the symbol and the old
230+
# ones merely answer 0. It is documented alongside
231+
# `touch_up_event` as the other accessor that degrades silently,
232+
# which is the part a reader has to be told.
233+
("emulating_sequence", "1.6"),
227234
):
228235
assert feature in readme, f"{feature} is no longer documented"
229236
assert version in readme, f"README no longer states the {version} requirement"

‎tests/test_integration_socketpair.py‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,33 @@
1717

1818
import pytest
1919

20-
from conftest import requires_libei
20+
from conftest import has_symbol, requires_libei
2121
from libei import ei, eis
2222

2323
pytestmark = [pytest.mark.integration, requires_libei]
2424

25+
# What the client sends as its start_emulating sequence, and what the server
26+
# should read back for it. They are the same number only on libei 1.6+:
27+
# below that, libeis built the start_emulating event and never copied the
28+
# sequence into it, so the getter returned a zeroed struct field for every
29+
# client no matter what was sent. Upstream added the missing assignment in
30+
# libei commit 98cd152, released in 1.6.0 and in no earlier tag -- measured
31+
# 0 on 1.2.1, 1.3.901 and 1.5.0, 4242 on 1.6.0.
32+
#
33+
# `requires_symbol` cannot express this, which is why `has_symbol` exists:
34+
# every version from the 1.0.0 floor up exports
35+
# `eis_event_emulating_get_sequence`, the old ones just answer wrongly.
36+
# `eis_set_flag` is 1.6-only and stands in for the version -- and it is a
37+
# libeis symbol, so the library being asked is the one that answers.
38+
#
39+
# Decided here at import rather than in the test body both because that is
40+
# where the suite's other version gates live, and because a branch down in
41+
# that already-long negotiation costs more than it is worth.
42+
_SENT_EMULATING_SEQUENCE = 4242
43+
_READ_EMULATING_SEQUENCE = (
44+
_SENT_EMULATING_SEQUENCE if has_symbol("libeis.so.1", "eis_set_flag") else 0
45+
)
46+
2547

2648
def test_client_connects() -> None:
2749
server = eis.Eis.create_for_fd()
@@ -247,7 +269,7 @@ def test_the_accessors_no_other_test_reaches_round_trip() -> None:
247269
):
248270
emulated = True
249271
client_device = sender_event.device
250-
client_device.start_emulating(sequence=4242)
272+
client_device.start_emulating(sequence=_SENT_EMULATING_SEQUENCE)
251273
client_device.button(272, True)
252274
client_device.scroll_delta(3.5, -2.0)
253275
client_device.scroll_discrete(120, -240)
@@ -262,7 +284,14 @@ def test_the_accessors_no_other_test_reaches_round_trip() -> None:
262284
assert seen["scroll"] == eis.ScrollEvent(dx=3.5, dy=-2.0)
263285
assert seen["scroll_discrete"] == eis.ScrollDiscreteEvent(dx=120, dy=-240)
264286
assert seen["absolute"] == eis.PointerAbsoluteEvent(x=100.0, y=200.0)
265-
assert seen["sequence"] == 4242
287+
# The read itself stays unconditional -- calling the getter is what
288+
# proves its symbol name and restype, which is this test's whole point.
289+
# Only the expected value is version-dependent; see
290+
# `_READ_EMULATING_SEQUENCE` above for why. Asserting the 0 below 1.6
291+
# rather than skipping is deliberate: it is what
292+
# `eis.Event.emulating_sequence` documents, so an old library keeps
293+
# that claim under test instead of leaving it unchallenged.
294+
assert seen["sequence"] == _READ_EMULATING_SEQUENCE
266295
assert seen["modifiers"] == ei.XkbModifiersEvent(
267296
depressed=4, latched=0, locked=2, group=0
268297
)

0 commit comments

Comments
 (0)