diff --git a/pyproject.toml b/pyproject.toml index b3cb7e8636..9d42c2fd86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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 =[ @@ -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 = [ diff --git a/tests/__snapshots__/test_vt_snapshots.ambr b/tests/__snapshots__/test_vt_snapshots.ambr index 69621add99..df8dbb34ae 100644 --- a/tests/__snapshots__/test_vt_snapshots.ambr +++ b/tests/__snapshots__/test_vt_snapshots.ambr @@ -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=[] ┌────────────────────────────────────────────────┐ diff --git a/tests/test_vt_snapshots.py b/tests/test_vt_snapshots.py index e70550ac84..efecd6ce2c 100644 --- a/tests/test_vt_snapshots.py +++ b/tests/test_vt_snapshots.py @@ -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") diff --git a/uv.lock b/uv.lock index d44ec925fe..f99a35b019 100644 --- a/uv.lock +++ b/uv.lock @@ -805,19 +805,15 @@ wheels = [ [[package]] name = "libtmux" version = "0.70.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/51/f1/a44043193fd4c212858cdca04b8e628ce557726bf81f04fdc9765d4c2ac7/libtmux-0.70.0.tar.gz", hash = "sha256:1496d6253aea98321a99b5e414f378154967a570ffd1f5dc9f1effaa01f782c3", size = 1491548, upload-time = "2026-11-28T23:17:25.409Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/c9/f6/9273ce6bba65485ad2c6d95eb287798913b463cfddd6c7737a01fb7587f6/libtmux-0.70.0-py3-none-any.whl", hash = "sha256:9fcdccc64bb354ca6e243e942484b58f4f950b4a14ff4a324ae2dc4005afe1b2", size = 188971, upload-time = "2026-11-28T23:17:23.977Z" }, -] +source = { git = "https://github.com/tmux-python/libtmux.git?rev=6fc46db371ac466a07135c4f1e29dabfd1daf9f4#6fc46db371ac466a07135c4f1e29dabfd1daf9f4" } [[package]] name = "libvt" -version = "0.0.1a4" +version = "0.0.1a5" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/2f/e3/2aef4116c9773807fa09e5bc716a18a2d449e3ae5c4c5767b1b524021330/libvt-0.0.1a4.tar.gz", hash = "sha256:35c879576ca71e65d55d246e62e212fe910fc4918ed0ba1783c713617fccabde", size = 355784, upload-time = "2026-11-29T22:17:39.524Z" } +sdist = { url = "https://files.pythonhosted.org/packages/bb/96/2eb9fb46534a28d767fe67c22df198e39f0634a09c90395f38f825754f8b/libvt-0.0.1a5.tar.gz", hash = "sha256:704af5c37012783a96203fdbf346b60ebe8e3792ee7d5abfc37e2e63cf83c088", size = 401839, upload-time = "2026-12-01T03:22:55.088Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/0f/3e/94566d78ca6923f4d8a8de31b64bfff9c9bc716c51e6a1ebd1f496d883bb/libvt-0.0.1a4-py3-none-any.whl", hash = "sha256:ede0a8484b3d617d8dd75f22ab3e0f479d1086ae5beebd63c68c77223f42ce90", size = 217260, upload-time = "2026-11-29T22:17:38.109Z" }, + { url = "https://files.pythonhosted.org/packages/86/f8/e7c31defff03fec80cc23f22a8d22d4483d3da5816a64954e9105d8ce803/libvt-0.0.1a5-py3-none-any.whl", hash = "sha256:c161e07791fb84acee3491f4b1e9646d15ba1dea8d2c285f1b9f6771799a0fe5", size = 253987, upload-time = "2026-12-01T03:22:53.849Z" }, ] [package.optional-dependencies] @@ -1824,7 +1820,7 @@ testing = [ [package.metadata] requires-dist = [ - { name = "libtmux", specifier = "~=0.70.0" }, + { name = "libtmux", git = "https://github.com/tmux-python/libtmux.git?rev=6fc46db371ac466a07135c4f1e29dabfd1daf9f4" }, { name = "pyyaml", specifier = ">=6.0" }, ] @@ -1842,7 +1838,7 @@ dev = [ { name = "gp-libs", specifier = ">=0.0.19" }, { name = "gp-sphinx", specifier = "==0.1.0a39" }, { name = "ipython" }, - { name = "libvt", extras = ["pytest", "syrupy"], marker = "python_full_version >= '3.12'", specifier = ">=0.0.1a4,<0.1" }, + { name = "libvt", extras = ["pytest", "syrupy"], marker = "python_full_version >= '3.12'", specifier = ">=0.0.1a5,<0.1" }, { name = "ptpython" }, { name = "pytest" }, { name = "pytest-cov" }, @@ -1881,7 +1877,7 @@ lint = [ ] testing = [ { name = "gp-libs", specifier = ">=0.0.19" }, - { name = "libvt", extras = ["pytest", "syrupy"], marker = "python_full_version >= '3.12'", specifier = ">=0.0.1a4,<0.1" }, + { name = "libvt", extras = ["pytest", "syrupy"], marker = "python_full_version >= '3.12'", specifier = ">=0.0.1a5,<0.1" }, { name = "pytest" }, { name = "pytest-mock" }, { name = "pytest-rerunfailures" },