Skip to content

Commit 73d34d8

Browse files
committed
fix(load[spinner]): guard _emit_success against build failure
why: The spinner-enabled path called _emit_success() unconditionally after _dispatch_build(), showing a success checkmark even when the build failed and the user killed the session. The --no-progress path already had the correct guard. what: - Add `if result is not None:` guard before _emit_success() call - Add test verifying success message is not emitted on build failure
1 parent 789cca2 commit 73d34d8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/tmuxp/cli/load.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ def _emit_success() -> None:
672672
on_error_hook=spinner.stop,
673673
pre_prompt_hook=spinner.stop,
674674
)
675-
_emit_success()
675+
if result is not None:
676+
_emit_success()
676677
return result
677678

678679

tests/cli/test_progress.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
import atexit
66
import io
7+
import pathlib
78
import time
89
import typing as t
910

11+
import libtmux
1012
import pytest
1113

1214
from tmuxp.cli._colors import ColorMode
@@ -1386,3 +1388,38 @@ def test_success_template_value() -> None:
13861388
assert "{workspace_path}" in SUCCESS_TEMPLATE
13871389
assert "{summary}" in SUCCESS_TEMPLATE
13881390
assert "Loaded workspace:" in SUCCESS_TEMPLATE
1391+
1392+
1393+
def test_no_success_message_on_build_error(
1394+
server: libtmux.Server,
1395+
tmp_path: pathlib.Path,
1396+
monkeypatch: pytest.MonkeyPatch,
1397+
capfd: pytest.CaptureFixture[str],
1398+
) -> None:
1399+
"""Success message is not emitted when _dispatch_build returns None."""
1400+
import yaml
1401+
1402+
from tmuxp.cli._colors import Colors
1403+
from tmuxp.cli.load import load_workspace
1404+
1405+
monkeypatch.delenv("TMUX", raising=False)
1406+
1407+
config = {"session_name": "test-fail", "windows": [{"window_name": "main"}]}
1408+
config_file = tmp_path / "fail.yaml"
1409+
config_file.write_text(yaml.dump(config))
1410+
1411+
monkeypatch.setattr(
1412+
"tmuxp.cli.load._dispatch_build",
1413+
lambda *args, **kwargs: None,
1414+
)
1415+
1416+
result = load_workspace(
1417+
str(config_file),
1418+
socket_name=server.socket_name,
1419+
cli_colors=Colors(ColorMode.NEVER),
1420+
)
1421+
1422+
assert result is None
1423+
captured = capfd.readouterr()
1424+
assert "\u2713" not in captured.err
1425+
assert "Loaded workspace:" not in captured.err

0 commit comments

Comments
 (0)