💫 Toolkit to help you get started with SDD or any other process!
fix(cli): render the literal [suffix] in --tag help and rejection message (#3800)
Ali jawwadf4a9b890cc48
diff --git a/src/specify_cli/_version.py b/src/specify_cli/_version.pyindex 33dd0983e..962e3adff 100644--- a/src/specify_cli/_version.py+++ b/src/specify_cli/_version.py@@ -27,6 +27,7 @@ from pathlib import Pathimport typerfrom packaging.version import InvalidVersion, Version+from rich.markup import escape as _escape_markupfrom ._download_security import MAX_JSON_METADATA_BYTES, read_response_limitedfrom ._console import console@@ -1230,7 +1231,10 @@ def self_upgrade(tag: str | None = typer.Option(None,"--tag",- help="Pin the target version (vX.Y.Z[suffix]). Without --tag, the "+ # Typer renders help through Rich, so escape the literal bracket (\[)+ # or `[suffix]` is parsed as a style tag and dropped -- `--help` then+ # advertises only `(vX.Y.Z)`, contradicting docs/upgrade.md and README.+ help="Pin the target version (vX.Y.Z\\[suffix]). Without --tag, the ""latest stable release is resolved via GitHub Releases.",),) -> None:@@ -1270,7 +1274,14 @@ def self_upgrade(try:tag = _validate_tag(tag)except typer.BadParameter as exc:- console.print(str(exc), soft_wrap=True)+ # Escape at the print site rather than baking `\[` into+ # _INVALID_TAG_MESSAGE: the message is also raised through+ # typer.BadParameter, which Click renders without Rich, so the+ # constant must stay plain text. Unescaped, Rich parses the literal+ # `[suffix]` as a style tag and drops it, leaving the user with+ # "expected vMAJOR.MINOR.PATCH" -- implying a bare vX.Y.Z is the only+ # accepted form when -rc1 / .dev0 / +build.42 are all valid.+ console.print(_escape_markup(str(exc)), soft_wrap=True)raise typer.Exit(1) from excplan, failure_reason = _build_upgrade_plan(target_tag_override=tag)diff --git a/tests/test_self_upgrade_verification.py b/tests/test_self_upgrade_verification.pyindex c4e7eecf1..f320cfe73 100644--- a/tests/test_self_upgrade_verification.py+++ b/tests/test_self_upgrade_verification.py@@ -472,6 +472,26 @@ class TestTagValidation:output = strip_ansi(result.output)assert "Invalid --tag" in output or "expected vMAJOR.MINOR.PATCH" in output+ def test_rejection_message_keeps_the_suffix_token(+ self, uv_tool_argv0, clean_environ+ ):+ """Rich must not swallow the literal `[suffix]`.++ Unescaped it is parsed as a style tag and dropped, so the user is told+ only "expected vMAJOR.MINOR.PATCH" -- implying a bare vX.Y.Z is the only+ accepted form, when -rc1 / .dev0 / +build.42 are all valid and are+ documented as such in docs/upgrade.md and README.md.+ """+ result = runner.invoke(app, ["self", "upgrade", "--tag", "latest"])+ assert result.exit_code == 1+ assert "expected vMAJOR.MINOR.PATCH[suffix]" in strip_ansi(result.output)++ def test_tag_option_help_keeps_the_suffix_token(self):+ """Typer renders option help through Rich, so `--help` dropped it too."""+ result = runner.invoke(app, ["self", "upgrade", "--help"])+ assert result.exit_code == 0+ assert "[suffix]" in strip_ansi(result.output)+class TestUnknownCurrent:"""'unknown' current version renders literally in notice and success message."""