From 64654057562de180a43a8140bea8da41d3c93628 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E6=BE=9C=E6=A1=A5-Luca?= <42632206+Lanqiao-Luca@users.noreply.github.com> Date: Thu, 3 Dec 2026 01:53:50 +0800 Subject: [PATCH] fix(cli): preserve the exact self-upgrade dry-run command Assisted-by: OpenAI Codex (model: GPT-6, autonomous) --- src/specify_cli/selfs/command_upgrade.py | 3 +-- tests/specify_cli/test_version_execution.py | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/specify_cli/selfs/command_upgrade.py b/src/specify_cli/selfs/command_upgrade.py index af024f9ea2..dc0994d42c 100644 --- a/src/specify_cli/selfs/command_upgrade.py +++ b/src/specify_cli/selfs/command_upgrade.py @@ -116,8 +116,7 @@ def self_upgrade( _emit_guidance(plan.method, plan.target_tag) raise typer.Exit(0) console.print("Dry run — no changes will be made.") - for line in plan.preview_summary.splitlines(): - console.print(line) + console.print(plan.preview_summary, soft_wrap=True, markup=False) if ( plan.method == _InstallMethod.UV_TOOL and plan.installer_argv is not None diff --git a/tests/specify_cli/test_version_execution.py b/tests/specify_cli/test_version_execution.py index 1553fead57..1957d99142 100644 --- a/tests/specify_cli/test_version_execution.py +++ b/tests/specify_cli/test_version_execution.py @@ -749,11 +749,19 @@ def test_windows_uv_tool_dry_run_matches_real_run_command( assert manual_steps in outputs[2] def test_non_windows_uv_tool_dry_run_still_previews_installer( - self, uv_tool_argv0, clean_environ + self, uv_tool_argv0, clean_environ, monkeypatch, tmp_path ): + installer_dir = tmp_path / "工具 [release] installer" + installer_dir.mkdir() + installer = installer_dir / ("uv.exe" if os.name == "nt" else "uv") + installer.write_text("#!/bin/sh\n", encoding="utf-8") + installer.chmod(0o755) + installer_path = str(installer.resolve()) + monkeypatch.setenv("COLUMNS", "64") + with patch("specify_cli.authentication.http.urllib.request.urlopen") as mock_urlopen, patch( - "specify_cli._version.shutil.which", return_value=sys.executable - ), patch("specify_cli._version.subprocess.run"), patch( + "specify_cli._version.shutil.which", return_value=installer_path + ), patch("specify_cli._version.subprocess.run") as mock_run, patch( "specify_cli._version._get_installed_version", return_value="1.2.2" ), patch( "specify_cli._version._runs_from_uv_tool_env_on_windows", return_value=False @@ -762,10 +770,11 @@ def test_non_windows_uv_tool_dry_run_still_previews_installer( result = runner.invoke(app, ["self", "upgrade", "--dry-run"]) assert result.exit_code == 0 + mock_run.assert_not_called() out = strip_ansi(result.output) expected_argv = _render_argv( [ - sys.executable, + installer_path, "tool", "install", "specify-cli", @@ -774,9 +783,7 @@ def test_non_windows_uv_tool_dry_run_still_previews_installer( "git+https://github.com/github/spec-kit.git@v1.2.4", ] ) - assert f"Command that would be executed: {expected_argv}" in " ".join( - out.split() - ) + assert f"Command that would be executed: {expected_argv}" in out.splitlines() assert "then run this once this command exits" not in out def test_windows_uv_tool_dry_run_without_uv_reports_missing_installer(