test(palette): use deterministic close in 3 test functions
3 tests fail because _toggle_command_palette is non-deterministic AND the
tests depend on prior fixture state. The toggle only flips the boolean,
so the test's behavior depends on whether palette starts open or closed.
Fixed all 3 tests by adding a force-close preamble that:
if client.get_value("show_command_palette") is True:
client.push_event("custom_callback", {"callback": "_toggle_command_palette", "args": []})
poll for False with 2s deadline
Tests fixed:
- test_palette_starts_hidden: replaced unconditional toggle (which opened
the palette from default-closed state) with conditional force-close
- test_palette_toggles_via_callback: added force-close preamble before
the "assert initial state is False" check
- test_palette_query_state_resets_on_open: added force-close preamble
before the 3-toggle sequence (so toggle sequence starts from closed
state and ends open, matching the assertion)
Verification: 7 of 7 tests pass in tests/test_command_palette_sim.py
(was 3 failed, 4 passed). Also passes in batch with other live_gui
tests (12 of 12 pass) - no isolation-pass fallacy.
This commit is contained in:
@@ -24,15 +24,16 @@ def test_palette_starts_hidden(live_gui: Any) -> None:
|
||||
# palette IS closable via the callback, not that it happens to be
|
||||
# closed at this moment. Resetting here makes the assertion meaningful
|
||||
# without depending on test ordering.
|
||||
client.push_event("custom_callback", {
|
||||
"callback": "_toggle_command_palette",
|
||||
"args": [],
|
||||
})
|
||||
deadline = time.time() + 2.0
|
||||
while time.time() < deadline:
|
||||
if client.get_value("show_command_palette") is False:
|
||||
break
|
||||
time.sleep(0.05)
|
||||
# Two toggles from default-closed state = closed. Two toggles from
|
||||
# open state = open. So we MUST check state and toggle only if open.
|
||||
if client.get_value("show_command_palette") is True:
|
||||
client.push_event("custom_callback", {
|
||||
"callback": "_toggle_command_palette",
|
||||
"args": [],
|
||||
})
|
||||
deadline = time.time() + 2.0
|
||||
while client.get_value("show_command_palette") is not False and time.time() < deadline:
|
||||
time.sleep(0.05)
|
||||
state = client.get_value("show_command_palette")
|
||||
assert state is not None, "show_command_palette should be a gettable field"
|
||||
assert state is False, f"Palette should be closable, got {state}"
|
||||
@@ -41,6 +42,14 @@ def test_palette_starts_hidden(live_gui: Any) -> None:
|
||||
def test_palette_toggles_via_callback(live_gui: Any) -> None:
|
||||
"""The _toggle_command_palette callback should open and close the palette."""
|
||||
client = ApiHookClient()
|
||||
# Force-close palette first (live_gui is session-scoped; prior tests may leave it open).
|
||||
# Two toggles from default-closed state = closed. Two toggles from open state = open.
|
||||
# So we MUST check state and toggle only if open. Then poll to verify closure.
|
||||
if client.get_value("show_command_palette") is True:
|
||||
client.push_event("custom_callback", {"callback": "_toggle_command_palette", "args": []})
|
||||
deadline = time.time() + 2.0
|
||||
while client.get_value("show_command_palette") is not False and time.time() < deadline:
|
||||
time.sleep(0.05)
|
||||
assert client.get_value("show_command_palette") is False
|
||||
|
||||
# Open via custom callback
|
||||
@@ -86,6 +95,14 @@ def test_palette_query_state_resets_on_open(live_gui: Any) -> None:
|
||||
This ensures a fresh state every time the user opens the palette.
|
||||
"""
|
||||
client = ApiHookClient()
|
||||
# Force-close palette first (live_gui is session-scoped; prior tests may leave it open).
|
||||
# Two toggles from default-closed state = closed. Two toggles from open state = open.
|
||||
# So we MUST check state and toggle only if open. Then poll to verify closure.
|
||||
if client.get_value("show_command_palette") is True:
|
||||
client.push_event("custom_callback", {"callback": "_toggle_command_palette", "args": []})
|
||||
deadline = time.time() + 2.0
|
||||
while client.get_value("show_command_palette") is not False and time.time() < deadline:
|
||||
time.sleep(0.05)
|
||||
|
||||
# Open once, set some state (simulate user typing)
|
||||
client.push_event("custom_callback", {
|
||||
|
||||
Reference in New Issue
Block a user