fix: wait for stable native replacement target before submission

This commit is contained in:
阿白叔 committed 2026-10-17 14:10:27 +08:00
1 parent ea024da325
commit e13b4e295f
2 files changed
+93 -9

No files matched your search

@@ -0,0 +1,39 @@
from types import SimpleNamespace
import pytest
from dx_productivity.trial_task_center import native_helper as native
def clock(monkeypatch):
now = [0.0]
monkeypatch.setattr(native, 'time', SimpleNamespace(
monotonic=lambda: now[0], sleep=lambda seconds: now.__setitem__(0, now[0] + seconds)))
return now
def test_same_part_text_cannot_accept_stale_symbol_disabled_button_or_changing_gate(monkeypatch):
now = clock(monkeypatch)
states = iter([
('NEW', 'lib:OTHER.1', True),
('NEW', 'lib:RES.1', False),
('NEW', 'lib:RES.1', True),
('NEW', 'lib:RES', True),
('NEW', 'lib:RES.1', True),
])
read = lambda: next(states, ('NEW', 'lib:RES.1', True))
state = native.wait_for_native_target(read, 'NEW', 'lib:RES', 1,
timeout=2, stable_for=.3, poll_interval=.1)
assert state == ('NEW', 'lib:RES.1', True)
assert now[0] >= .7
@pytest.mark.parametrize('state', [
('OLD', 'lib:RES.1', True), ('NEW', 'lib:OTHER.1', True),
('NEW', 'lib:RES.2', True), ('NEW', 'lib:RES.1', False),
])
def test_unready_target_times_out_without_becoming_a_valid_selection(monkeypatch, state):
clock(monkeypatch)
with pytest.raises(TimeoutError, match='Native target'):
native.wait_for_native_target(lambda: state, 'NEW', 'lib:RES', 1,
timeout=.5, stable_for=.2, poll_interval=.1)