Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/specify_cli/presets/command_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def preset_add(
dev_path, speckit_version, priority
)
console.print(
f"[green]✓[/green] Preset '{manifest.name}' v{manifest.version} installed (priority {priority})"
f"[green]✓[/green] Preset '{_escape_markup(str(manifest.name))}' v{_escape_markup(str(manifest.version))} installed (priority {priority})"
)

elif from_url:
Expand Down Expand Up @@ -309,7 +309,7 @@ def _validate_download_redirect(old_url, new_url):
)

console.print(
f"[green]✓[/green] Preset '{manifest.name}' v{manifest.version} installed (priority {priority})"
f"[green]✓[/green] Preset '{_escape_markup(str(manifest.name))}' v{_escape_markup(str(manifest.version))} installed (priority {priority})"
)

elif preset_id:
Expand All @@ -321,7 +321,7 @@ def _validate_download_redirect(old_url, new_url):
bundled_path, speckit_version, priority
)
console.print(
f"[green]✓[/green] Preset '{manifest.name}' v{manifest.version} installed (priority {priority})"
f"[green]✓[/green] Preset '{_escape_markup(str(manifest.name))}' v{_escape_markup(str(manifest.version))} installed (priority {priority})"
)
else:
catalog = PresetCatalog(project_root)
Expand Down Expand Up @@ -368,7 +368,7 @@ def _validate_download_redirect(old_url, new_url):
packaged, speckit_version, priority
)
console.print(
f"[green]✓[/green] Preset '{manifest.name}' v{manifest.version} installed (priority {priority})"
f"[green]✓[/green] Preset '{_escape_markup(str(manifest.name))}' v{_escape_markup(str(manifest.version))} installed (priority {priority})"
)
_commands._warn_unmet_extension_dependencies(manager, manifest)
return
Expand Down Expand Up @@ -396,7 +396,7 @@ def _validate_download_redirect(old_url, new_url):
raise typer.Exit(1)

console.print(
f"Installing preset [cyan]{pack_info.get('name', preset_id)}[/cyan]..."
f"Installing preset [cyan]{_escape_markup(str(pack_info.get('name', preset_id)))}[/cyan]..."
)

try:
Expand All @@ -417,7 +417,7 @@ def _validate_download_redirect(old_url, new_url):
),
)
console.print(
f"[green]✓[/green] Preset '{manifest.name}' v{manifest.version} installed (priority {priority})"
f"[green]✓[/green] Preset '{_escape_markup(str(manifest.name))}' v{_escape_markup(str(manifest.version))} installed (priority {priority})"
)
finally:
if "archive_path" in locals() and archive_path.exists():
Expand Down
53 changes: 53 additions & 0 deletions tests/specify_cli/presets/test_command_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,59 @@ def test_preset_add_exception_handlers_escape_markup(
assert f"{label}:" in result.output
assert "bad [red]preset[/red]" in result.output

@pytest.mark.parametrize("name", ["Lean Kit [beta]", "Lean [/] Kit"])
def test_preset_add_success_escapes_manifest_name(
self, project_dir, pack_dir, valid_pack_data, name
):
"""The installed preset's name is printed literally, not parsed as markup."""
from unittest.mock import patch

from typer.testing import CliRunner

from specify_cli import app

valid_pack_data["preset"]["name"] = name
(pack_dir / "preset.yml").write_text(
yaml.safe_dump(valid_pack_data), encoding="utf-8"
)

with patch.object(Path, "cwd", return_value=project_dir):
result = CliRunner().invoke(
app, ["preset", "add", "--dev", str(pack_dir)], catch_exceptions=True
)

assert result.exit_code == 0, result.output
assert f"Preset '{name}' v1.0.0 installed" in strip_ansi(result.output)

def test_preset_add_catalog_status_escapes_pack_name(self, project_dir):
"""A catalog entry's name is printed literally before downloading."""
from unittest.mock import patch

from typer.testing import CliRunner

from specify_cli import app

catalog_data = {
"test-pack": {
"name": "Lean [/] Kit",
"version": "1.0.0",
"download_url": "https://example.com/test-pack.zip",
}
}

with (
patch.object(Path, "cwd", return_value=project_dir),
patch.object(PresetCatalog, "_get_merged_packs", return_value=catalog_data),
patch.object(PresetCatalog, "download_pack", side_effect=PresetError("offline")),
):
result = CliRunner().invoke(
app, ["preset", "add", "test-pack"], catch_exceptions=True
)

assert result.exit_code == 1, result.output
assert result.exception is None or isinstance(result.exception, SystemExit)
assert "Installing preset Lean [/] Kit..." in strip_ansi(result.output)

def test_preset_add_from_url_redirect_error_describes_disallowed_url(
self, project_dir, monkeypatch, capsys
):
Expand Down
Loading