Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/specify_cli/extensions/command_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ def _print_extension_info(ext_info: dict, manager):

# Header
verified_badge = " [green]✓ Verified[/green]" if ext_info.get("verified") else ""
_commands.console.print(f"\n[bold]{_escape_markup(str(ext_info['name']))}[/bold] (v{_escape_markup(str(ext_info['version']))}){verified_badge}")
_commands.console.print(f"\n[bold]{_escape_markup(str(ext_info.get('name', ext_info['id'])))}[/bold] (v{_escape_markup(str(ext_info.get('version', 'unknown')))}){verified_badge}")
_commands.console.print(f"ID: {_escape_markup(str(ext_info['id']))}")
_commands.console.print()

# Description
_commands.console.print(f"{_escape_markup(str(ext_info['description']))}")
_commands.console.print(f"{_escape_markup(str(ext_info.get('description', '')))}")
_commands.console.print()

# Author and License
Expand Down
4 changes: 2 additions & 2 deletions src/specify_cli/extensions/command_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def extension_search(
for ext in results:
# Extension header
verified_badge = " [green]✓ Verified[/green]" if ext.get("verified") else ""
console.print(f"[bold]{_escape_markup(str(ext['name']))}[/bold] (v{_escape_markup(str(ext['version']))}){verified_badge}")
console.print(f" {_escape_markup(str(ext['description']))}")
console.print(f"[bold]{_escape_markup(str(ext.get('name', ext['id'])))}[/bold] (v{_escape_markup(str(ext.get('version', 'unknown')))}){verified_badge}")
console.print(f" {_escape_markup(str(ext.get('description', '')))}")

# Metadata
console.print(f"\n [dim]Author:[/dim] {_escape_markup(str(ext.get('author', 'Unknown')))}")
Expand Down
47 changes: 47 additions & 0 deletions tests/specify_cli/extensions/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Shared fixtures for the mirrored extension command tests."""
from __future__ import annotations

import json
import shutil
import tempfile
from datetime import datetime, timezone
from pathlib import Path

import pytest
Expand Down Expand Up @@ -87,3 +89,48 @@ def project_dir(temp_dir):
project.mkdir()
(project / ".specify").mkdir()
return project


@pytest.fixture(
params=[
({"name": "Example", "description": "No version"}, "Example (vunknown)"),
({"version": "1.2.3", "description": "No name"}, "example (v1.2.3)"),
({"name": "Example", "version": "1.2.3"}, "Example (v1.2.3)"),
({"name": "Example", "version": "[/red]", "description": "Markup"}, "Example (v[/red])"),
],
ids=["no-version", "no-name", "no-description", "markup"],
)
def incomplete_catalog_entry(request, tmp_path, monkeypatch):
"""Serve an incomplete entry and a healthy sibling from the real cache.

Returns the header expected for the incomplete entry.
"""
from specify_cli.extensions import ExtensionCatalog

entry, header = request.param

# tmp_path, not temp_dir: monkeypatch restores the cwd only after
# temp_dir's rmtree, which Windows refuses while the cwd is inside it.
project_dir = tmp_path / "project"
(project_dir / ".specify").mkdir(parents=True)
monkeypatch.chdir(project_dir)
monkeypatch.setenv("SPECKIT_CATALOG_URL", ExtensionCatalog.DEFAULT_CATALOG_URL)
catalog = ExtensionCatalog(project_dir)
catalog.cache_dir.mkdir(parents=True)
catalog.cache_file.write_text(json.dumps({
"schema_version": "1.0",
"extensions": {
"example": entry,
"healthy": {"name": "Healthy", "description": "Complete entry", "version": "2.0.0"},
},
}), encoding="utf-8")
catalog.cache_metadata_file.write_text(json.dumps({
"cached_at": datetime.now(timezone.utc).isoformat(),
"catalog_url": ExtensionCatalog.DEFAULT_CATALOG_URL,
}), encoding="utf-8")

def no_network(*args, **kwargs):
pytest.fail("The fresh catalog cache must be used")

monkeypatch.setattr(ExtensionCatalog, "_open_url", no_network)
return header
11 changes: 11 additions & 0 deletions tests/specify_cli/extensions/test_command_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ def test_info_renders_markup_bearing_stars(self):
class TestExtensionInfoCLI:
"""CLI tests for ``specify extension info``."""

def test_info_shows_incomplete_catalog_entry(self, incomplete_catalog_entry):
result = CliRunner().invoke(app, ["extension", "info", "example"])

assert result.exit_code == 0, result.output
assert incomplete_catalog_entry in result.output
assert "ID: example" in result.output

healthy = CliRunner().invoke(app, ["extension", "info", "healthy"])
assert healthy.exit_code == 0, healthy.output
assert "Healthy (v2.0.0)" in healthy.output

def test_info_discovery_only_shows_candidate_archive_url(self, tmp_path):
"""For a discovery-only entry that carries a ``download_url``, ``info``
surfaces the candidate archive URL (flagged for vetting) and the vetted
Expand Down
12 changes: 12 additions & 0 deletions tests/specify_cli/extensions/test_command_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
class TestExtensionSearchCLI:
"""CLI tests for ``specify extension search``."""

def test_search_shows_incomplete_catalog_entry(self, incomplete_catalog_entry):
result = CliRunner().invoke(app, ["extension", "search"])

assert result.exit_code == 0, result.output
assert incomplete_catalog_entry in result.output
assert "Healthy (v2.0.0)" in result.output

filtered = CliRunner().invoke(app, ["extension", "search", "Healthy"])
assert filtered.exit_code == 0, filtered.output
assert "Example" not in filtered.output
assert "Healthy (v2.0.0)" in filtered.output

@pytest.mark.parametrize("install_allowed", [True, False])
@pytest.mark.parametrize(
("extension_id", "command_id"),
Expand Down