diff --git a/src/specify_cli/_version.py b/src/specify_cli/_version.py index 0d88c271ca..c582b8e8ef 100644 --- a/src/specify_cli/_version.py +++ b/src/specify_cli/_version.py @@ -168,7 +168,14 @@ def _stable_release_tag_for_version(version_text: str) -> str | None: parsed = _parse_version_text(version_text) if parsed is None: return None - if parsed.pre or parsed.post or parsed.dev or parsed.local: + # `post` and `dev` are ints, so `.post0`/`.dev0` are 0 and falsy: compare + # against None instead of relying on truthiness. + if ( + parsed.pre is not None + or parsed.post is not None + or parsed.dev is not None + or parsed.local is not None + ): return None release = parsed.release if len(release) != 3: diff --git a/tests/specify_cli/test_version_execution.py b/tests/specify_cli/test_version_execution.py index d68ae11663..1553fead57 100644 --- a/tests/specify_cli/test_version_execution.py +++ b/tests/specify_cli/test_version_execution.py @@ -545,6 +545,43 @@ def test_prerelease_failure_degrades_rollback_hint_to_releases_page( assert "https://github.com/github/spec-kit/releases" in out assert "git+https://github.com/github/spec-kit.git@v1.0.0rc1" not in out + def test_dev0_failure_does_not_suggest_unreleased_tag_as_rollback( + self, uv_tool_argv0, clean_environ + ): + # `packaging` reports `.dev0` as `dev == 0`, which is falsy; a + # main-branch install (`1.3.4.dev0`) must not be pinned "back" to the + # very release that just failed to install. + 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") as mock_run, patch( + "specify_cli._version._get_installed_version", return_value="1.3.4.dev0" + ): + mock_urlopen.return_value = mock_urlopen_response({"tag_name": "v1.3.4"}) + mock_run.side_effect = [_completed_process(2)] + result = runner.invoke(app, ["self", "upgrade"]) + + assert result.exit_code == 2 + out = strip_ansi(result.output) + assert "Previous version was not an exact stable release tag" in out + assert "To pin back to the previous version" not in out + + def test_post0_failure_degrades_rollback_hint_to_releases_page( + self, uv_tool_argv0, clean_environ + ): + 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") as mock_run, patch( + "specify_cli._version._get_installed_version", return_value="1.3.3.post0" + ): + mock_urlopen.return_value = mock_urlopen_response({"tag_name": "v1.3.4"}) + mock_run.side_effect = [_completed_process(2)] + result = runner.invoke(app, ["self", "upgrade"]) + + assert result.exit_code == 2 + out = strip_ansi(result.output) + assert "Previous version was not an exact stable release tag" in out + assert "To pin back to the previous version" not in out + class TestWindowsUvToolEnvironment: """Windows uv-tool installs cannot reinstall the environment they run from."""