From e722384ad91507e2baeb804a226ccd79859ce68d Mon Sep 17 00:00:00 2001 From: LeonSGP43 <154585401+LeonSGP43@users.noreply.github.com> Date: Wed, 22 Apr 2026 23:08:29 +0800 Subject: [PATCH] fix(claw): preserve dry-run preview in non-interactive cleanup --- hermes_cli/claw.py | 2 +- tests/hermes_cli/test_claw.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/hermes_cli/claw.py b/hermes_cli/claw.py index e62efe47ea..377609f401 100644 --- a/hermes_cli/claw.py +++ b/hermes_cli/claw.py @@ -541,7 +541,7 @@ def _cmd_cleanup(args): ) print_info("Stop OpenClaw first: systemctl --user stop openclaw-gateway.service") print() - if not auto_yes: + if not auto_yes and not dry_run: if not sys.stdin.isatty(): print_info("Non-interactive session — aborting. Stop OpenClaw and re-run.") return diff --git a/tests/hermes_cli/test_claw.py b/tests/hermes_cli/test_claw.py index e32c4a1df8..ee8558f49b 100644 --- a/tests/hermes_cli/test_claw.py +++ b/tests/hermes_cli/test_claw.py @@ -583,6 +583,33 @@ class TestCmdCleanup: assert not openclaw.exists() assert not clawdbot.exists() + def test_dry_run_still_shows_preview_when_running_in_non_interactive_session(self, tmp_path, capsys): + openclaw = tmp_path / ".openclaw" + openclaw.mkdir() + ws = openclaw / "workspace" + ws.mkdir() + (ws / "todo.json").write_text("{}") + + args = Namespace(source=None, dry_run=True, yes=False) + fake_stdin = MagicMock() + fake_stdin.isatty.return_value = False + + with ( + patch.object(claw_mod, "_find_openclaw_dirs", return_value=[openclaw]), + patch.object( + claw_mod, + "_detect_openclaw_processes", + return_value=["openclaw process(es) (PIDs: 1234)"], + ), + patch("sys.stdin", fake_stdin), + ): + claw_mod._cmd_cleanup(args) + + captured = capsys.readouterr() + assert "OpenClaw appears to be still running" in captured.out + assert "Non-interactive session — aborting" not in captured.out + assert "Would archive" in captured.out + # --------------------------------------------------------------------------- # _print_migration_report