Skip to content
Open
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
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dev = [
"pytest-rerunfailures",
"pytest-mock",
"pytest-watcher",
"libvt[pytest,syrupy]>=0.0.1a4,<0.1; python_version >= '3.12'",
"libvt[pytest,syrupy]>=0.0.1a5,<0.1; python_version >= '3.12'",
"syrupy>=7.0.3; python_version >= '3.12'",
# Coverage
"codecov",
Expand Down Expand Up @@ -105,7 +105,7 @@ testing = [
"pytest-rerunfailures",
"pytest-mock",
"pytest-watcher",
"libvt[pytest,syrupy]>=0.0.1a4,<0.1; python_version >= '3.12'",
"libvt[pytest,syrupy]>=0.0.1a5,<0.1; python_version >= '3.12'",
"syrupy>=7.0.3; python_version >= '3.12'",
]
coverage =[
Expand Down Expand Up @@ -164,6 +164,9 @@ sphinx-gp-theme = false
sphinx-ux-autodoc-layout = false
sphinx-ux-badges = false

[tool.uv.sources]
libtmux = { git = "https://github.com/tmux-python/libtmux.git", rev = "6fc46db371ac466a07135c4f1e29dabfd1daf9f4" }

[tool.coverage.run]
branch = true
source = [
Expand Down
85 changes: 85 additions & 0 deletions tests/__snapshots__/test_vt_snapshots.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,91 @@
r1[55..64]: fg=blue
r1[65..68]: fg=cyan
# ---
# name: test_cli_load_multipane_workspace_window_vt_snapshots[workspace_dashboard_split]
size=35x8 cursor=(6,24,vis=True) alt=False modes=[]
┌───────────────────────────────────┐
│── 0:api ────────┬── 1:db ─────────│
│200 OK /health │pg:primary │
│日本 rps=42 │conns=12 │
│uptime=99.9% │ │
│ ├── 2:worker ─────│
│ │queue:idle │
│ │jobs=0 │
│ │ │
└───────────────────────────────────┘
styles:
r0[0..35]: fg=blue
r1[0..6]: bold fg=green
r1[17..18]: fg=blue
r1[18..28]: fg=yellow
r2[0..4]: fg=cyan
r2[17..18]: fg=blue
r3[17..18]: fg=blue
r4[17..35]: fg=green
r5[17..18]: fg=green
r5[18..28]: bold fg=magenta
r6[17..18]: fg=green
r7[17..18]: fg=green
# ---
# name: test_cli_load_multipane_workspace_window_vt_snapshots[workspace_dashboard_zoom_delta]
header: size=35x8 cursor=(6,24,vis=True) alt=False modes=[] -> size=35x8 cursor=(2,6,vis=True) alt=False modes=[]
row 0 cols 3..26: '0:api ────────┬── 1:db ' -> '2:worker ──────────────'
row 1 cols 0..28: '200 OK /health │pg:primary' -> 'queue:idle '
row 2 cols 0..26: '日本 rps=42 │conns=12' -> 'jobs=0 '
styles: [' r0[0..35]: fg=blue', ' r1[0..6]: bold fg=green', ' r1[17..18]: fg=blue', ' r1[18..28]: fg=yellow', ' r2[0..4]: fg=cyan', ' r2[17..18]: fg=blue', ' r3[17..18]: fg=blue', ' r4[17..35]: fg=green', ' r5[17..18]: fg=green', ' r5[18..28]: bold fg=magenta', ' r6[17..18]: fg=green', ' r7[17..18]: fg=green'] -> [' r0[0..35]: fg=green', ' r1[0..10]: bold fg=magenta']
- size=35x8 cursor=(6,24,vis=True) alt=False modes=[]
+ size=35x8 cursor=(2,6,vis=True) alt=False modes=[]
┌───────────────────────────────────┐
- │── 0:api ────────┬── 1:db ─────────│
- │200 OK /health │pg:primary │
- │日本 rps=42 │conns=12 │
- │uptime=99.9% │ │
- │ ├── 2:worker ─────│
- │ │queue:idle │
- │ │jobs=0 │
- │ │ │
+ │── 2:worker ───────────────────────│
│^^ ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^│
+ │queue:idle │
+ │jobs=0 │
+ │ │
+ │ │
+ │ │
+ │ │
+ │ │
└───────────────────────────────────┘
styles:
- r0[0..35]: fg=blue
- r1[0..6]: bold fg=green
- r1[17..18]: fg=blue
- r1[18..28]: fg=yellow
- r2[0..4]: fg=cyan
- r2[17..18]: fg=blue
- r3[17..18]: fg=blue
- r4[17..35]: fg=green
+ r0[0..35]: fg=green
- r5[17..18]: fg=green
- r5[18..28]: bold fg=magenta
+ r1[0..10]: bold fg=magenta
- r6[17..18]: fg=green
- r7[17..18]: fg=green
# ---
# name: test_cli_load_multipane_workspace_window_vt_snapshots[workspace_dashboard_zoomed]
size=35x8 cursor=(2,6,vis=True) alt=False modes=[]
┌───────────────────────────────────┐
│── 2:worker ───────────────────────│
│queue:idle │
│jobs=0 │
│ │
│ │
│ │
│ │
│ │
└───────────────────────────────────┘
styles:
r0[0..35]: fg=green
r1[0..10]: bold fg=magenta
# ---
# name: test_cli_load_success_with_hook_output_pty[48-narrow][load_done_narrow]
size=48x10 cursor=(3,0,vis=True) alt=False modes=[]
┌────────────────────────────────────────────────┐
Expand Down
165 changes: 165 additions & 0 deletions tests/test_vt_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,168 @@ async def _exercise() -> None:

asyncio.run(_exercise())
assert server.has_session(session_name) is False


def test_cli_load_multipane_workspace_window_vt_snapshots(
server: Server,
tmp_path: pathlib.Path,
vt_pty: PtyFactory,
vt_snapshot: SnapshotAssertion,
) -> None:
"""``tmuxp load`` builds a multi-pane window captured via ``Window.capture_vt``."""
from libtmux.vt import assert_window_screen_box
from libvt.testing import serialize_vt_snapshot, vt_screen

assert server.socket_name is not None
session_name = "dash-vt"
fake_home = tmp_path / "home_dash"
cfg_dir = fake_home / ".tmuxp"
cfg_dir.mkdir(parents=True)

render_gate = tmp_path / "render_panes.gate"

def _pane_shell(script_name: str, title: str, body: str) -> str:
script_path = tmp_path / script_name
script_path.write_text(
"import pathlib, sys, time\n"
f"gate = pathlib.Path({str(render_gate)!r})\n"
"deadline = time.monotonic() + 8.0\n"
"while not gate.exists() and time.monotonic() < deadline:\n"
" time.sleep(0.01)\n"
f"sys.stdout.write({title!r} + '\\x1b[2J\\x1b[H' + {body!r})\n"
"sys.stdout.flush()\n"
"sys.stdin.read(1)\n",
encoding="utf-8",
)
return f"{shlex.quote(sys.executable)} -u {shlex.quote(str(script_path))}"

api_shell = _pane_shell(
"pane_api.py",
"\x1b]2;api\x07",
"\x1b[1;32m200 OK\x1b[0m /health\r\n\x1b[36m日本\x1b[0m rps=42\r\nuptime=99.9%",
)
db_shell = _pane_shell(
"pane_db.py",
"\x1b]2;db\x07",
"\x1b[33mpg:primary\x1b[0m\r\nconns=12",
)
worker_shell = _pane_shell(
"pane_worker.py",
"\x1b]2;worker\x07",
"\x1b[1;35mqueue:idle\x1b[0m\r\njobs=0",
)

ws_file = cfg_dir / "dashboard.yaml"
ws_file.write_text(
f"session_name: {json.dumps(session_name)}\n"
"global_options:\n"
" pane-base-index: 0\n"
"windows:\n"
" - window_name: dashboard\n"
" layout: main-vertical\n"
" options:\n"
" main-pane-width: '17'\n"
" pane-border-status: top\n"
" pane-border-format: ' #{pane_index}:#{pane_title} '\n"
" pane-border-style: fg=blue\n"
" pane-active-border-style: fg=green\n"
" panes:\n"
f" - shell: {json.dumps(api_shell)}\n"
" shell_command: []\n"
f" - shell: {json.dumps(db_shell)}\n"
" shell_command: []\n"
f" - shell: {json.dumps(worker_shell)}\n"
" shell_command: []\n"
" focus: true\n",
encoding="utf-8",
)

argv = [
sys.executable,
"-u",
"-c",
"from tmuxp.cli import cli; cli()",
"--color",
"always",
"load",
"-d",
"-L",
server.socket_name,
str(ws_file),
]
env = _pty_cli_env(fake_home)

async def _load_detached() -> None:
async with vt_pty(argv, rows=8, cols=35, env=env, tty_mode="cooked") as pty:
await pty.wait_for(lambda _: pty.eof, timeout=10.0)
rc = await pty.process.wait()
assert rc == 0

asyncio.run(_load_detached())

built = server.sessions.get(session_name=session_name)
assert built is not None
dashboard = built.windows.get(window_name="dashboard")
assert dashboard is not None
assert len(dashboard.panes) == 3

render_gate.write_text("render", encoding="utf-8")

def _all_panes_ready() -> bool:
txt = dashboard.capture_vt().snapshot.text
return (
"0:api" in txt
and "1:db" in txt
and "2:worker" in txt
and "uptime=99.9%" in txt
and "conns=12" in txt
and "jobs=0" in txt
)

retry_until(_all_panes_ready, seconds=5.0)

win_res = dashboard.capture_vt()
assert win_res.zoomed is False
assert win_res.layout_stable is True
assert len(win_res.panes) == 3
assert vt_screen(win_res.snapshot) == vt_snapshot(name="workspace_dashboard_split")

async def _verify_live_observer() -> None:
async with built.observe_vt(history_lines=0) as obs:
live_snap = await obs.snapshot_window(dashboard)
assert serialize_vt_snapshot(live_snap) == serialize_vt_snapshot(
win_res.snapshot
)

asyncio.run(_verify_live_observer())

dashboard.cmd("resize-pane", "-Z")
zoom_res = dashboard.capture_vt()
assert zoom_res.zoomed is True
assert vt_screen(zoom_res.snapshot) == vt_snapshot(
name="workspace_dashboard_zoomed"
)
assert vt_screen(zoom_res.snapshot, diff=win_res.snapshot) == vt_snapshot(
name="workspace_dashboard_zoom_delta"
)
dashboard.cmd("resize-pane", "-Z")

assert_window_screen_box(
dashboard,
"""
┌───────────────────────────────────┐
│── 0:api ────────┬── 1:db ─────────│
│200 OK /health │pg:primary │
│日本 rps=42 │conns=12 │
│uptime=99.9% │ │
│ ├── 2:worker ─────│
│ │queue:idle │
│ │jobs=0 │
│ │ │
└───────────────────────────────────┘
""",
cursor=(6, 24),
)

for pane in dashboard.panes:
pane.send_vt_input("enter")
18 changes: 7 additions & 11 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading