Skip to content

Commit f7dc4f9

Browse files
committed
fix(cli[load]): Only fire on_project_restart after user confirms
why: on_project_restart fired before the reattach prompt, so it ran even when the user declined. what: - on_project_restart was already moved inside the _confirmed/detached block by the previous commit's restructuring - Add test_load_on_project_restart_skipped_on_decline
1 parent d2dda5f commit f7dc4f9

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

tests/cli/test_load.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,52 @@ def test_load_on_project_restart_runs_hook(
11961196
session.kill()
11971197

11981198

1199+
def test_load_on_project_restart_skipped_on_decline(
1200+
tmp_path: pathlib.Path,
1201+
server: Server,
1202+
monkeypatch: pytest.MonkeyPatch,
1203+
) -> None:
1204+
"""Tmuxp load skips on_project_restart when user declines reattach."""
1205+
monkeypatch.delenv("TMUX", raising=False)
1206+
1207+
marker = tmp_path / "restart_hook_ran"
1208+
workspace_file = tmp_path / "hook_restart_decline.yaml"
1209+
workspace_file.write_text(
1210+
f"""\
1211+
session_name: hook-restart-decline
1212+
on_project_restart: "touch {marker}"
1213+
windows:
1214+
- window_name: main
1215+
panes:
1216+
- echo hello
1217+
""",
1218+
encoding="utf-8",
1219+
)
1220+
1221+
# First load creates the session
1222+
session = load_workspace(
1223+
workspace_file,
1224+
socket_name=server.socket_name,
1225+
detached=True,
1226+
)
1227+
assert session is not None
1228+
assert not marker.exists()
1229+
1230+
# Second load: session exists, user declines reattach
1231+
monkeypatch.setattr(
1232+
"tmuxp.cli.load.prompt_yes_no",
1233+
lambda *a, **kw: False,
1234+
)
1235+
load_workspace(
1236+
workspace_file,
1237+
socket_name=server.socket_name,
1238+
detached=False,
1239+
)
1240+
assert not marker.exists()
1241+
1242+
session.kill()
1243+
1244+
11991245
def test_load_on_project_start_skipped_on_decline(
12001246
tmp_path: pathlib.Path,
12011247
server: Server,

0 commit comments

Comments
 (0)