Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions tests/__snapshots__/test_vt_snapshots.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,44 @@
# serializer version: 1
# name: test_cli_load_failure_recovery_prompt_pty[48-narrow-detach][load_error_detached_narrow]
size=48x10 cursor=(3,0,vis=True) alt=False modes=[]
┌────────────────────────────────────────────────┐
│[Error] Database port 5432 unreachable │
│Error loading workspace. (k)ill, (a)ttach, (d)et│W
│ach? - (k, a, d) [k]: d │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└────────────────────────────────────────────────┘
styles:
r0[0..7]: fg=red
r1[0..24]: fg=red
r2[7..16]: fg=blue
r2[17..20]: fg=cyan
# ---
# name: test_cli_load_failure_recovery_prompt_pty[48-narrow-detach][load_error_prompt_narrow]
size=48x10 cursor=(2,22,vis=True) alt=False modes=[]
┌────────────────────────────────────────────────┐
│[Error] Database port 5432 unreachable │
│Error loading workspace. (k)ill, (a)ttach, (d)et│W
│ach? - (k, a, d) [k]: │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└────────────────────────────────────────────────┘
styles:
r0[0..7]: fg=red
r1[0..24]: fg=red
r2[7..16]: fg=blue
r2[17..20]: fg=cyan
# ---
# name: test_cli_load_failure_recovery_prompt_pty[48-narrow][load_error_killed_narrow]
size=48x10 cursor=(4,0,vis=True) alt=False modes=[]
┌────────────────────────────────────────────────┐
Expand Down
28 changes: 19 additions & 9 deletions tests/test_vt_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def test_cli_spinner_panel_and_success_vt_snapshots(
"""``Spinner`` ``?2026`` frames and ``CURSOR_UP_1`` cleanup render cleanly."""
from libvt.testing import vt_screen

monkeypatch.delenv("NO_COLOR", raising=False)
monkeypatch.setattr(
shutil,
"get_terminal_size",
Expand Down Expand Up @@ -280,10 +281,11 @@ async def _exercise() -> None:


@pytest.mark.parametrize(
("cols", "width_label"),
("cols", "width_label", "choice"),
[
(76, "normal"),
(48, "narrow"),
pytest.param(76, "normal", "k", id="76-normal"),
pytest.param(48, "narrow", "k", id="48-narrow"),
pytest.param(48, "narrow", "d", id="48-narrow-detach"),
],
)
def test_cli_load_failure_recovery_prompt_pty(
Expand All @@ -293,8 +295,9 @@ def test_cli_load_failure_recovery_prompt_pty(
vt_snapshot: SnapshotAssertion,
cols: int,
width_label: str,
choice: t.Literal["k", "d"],
) -> None:
"""Failed ``tmuxp load`` stops spinner, prompts cleanly, and kills on ``k``."""
"""Failed ``tmuxp load`` clears progress before kill or detach."""
from libvt.testing import vt_screen

assert server.socket_name is not None
Expand Down Expand Up @@ -369,7 +372,7 @@ async def _exercise() -> None:
err_gate_file.write_text("fail", encoding="utf-8")

prompt_snap = await pty.wait_for(
lambda snap: "[k]:" in snap.text,
"Error loading workspace. (k)ill, (a)ttach, (d)etach? - (k, a, d) [k]:",
timeout=8.0,
)
assert server.has_session(session_name) is True
Expand All @@ -383,18 +386,25 @@ async def _exercise() -> None:
name=f"load_error_prompt_{width_label}"
)

pty.send(b"k\r")
pty.send(f"{choice}\r".encode())
final_snap = await pty.wait_for(lambda _: pty.eof, timeout=8.0)
rc = await pty.process.wait()
assert rc == 0
assert "Session killed." in final_snap.text
if choice == "k":
assert "Session killed." in final_snap.text
assert "Loaded" not in final_snap.text
assert "detached state" not in final_snap.text
assert final_snap.cursor.visible is True
assert pty.terminal.synchronized is False
outcome = "killed" if choice == "k" else "detached"
assert vt_screen(final_snap, scrubbers=_SPINNER_SCRUB) == vt_snapshot(
name=f"load_error_killed_{width_label}"
name=f"load_error_{outcome}_{width_label}"
)

asyncio.run(_exercise())
assert server.has_session(session_name) is False
if choice == "k":
assert server.has_session(session_name) is False
else:
built = server.sessions.get(session_name=session_name, default=None)
assert built is not None
assert [window.window_name for window in built.windows] == ["api"]
Loading