mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
* refactor: extract _console.py from __init__.py Move Rich UI primitives (BANNER, TAGLINE, StepTracker, get_key, select_with_arrows, console, BannerGroup, show_banner) into a new src/specify_cli/_console.py module. Re-export all symbols from __init__.py to preserve the public API. Add regression guard tests. * refactor(console): improve type annotations and add guard for empty options - Add module-level docstring documenting the console layer's purpose and the dependency-layering rule (no imports from other specify_cli modules) - Tighten select_with_arrows() signature: options typed as dict[str, str] and default_key as str | None to align with repo typing style - Add early ValueError guard when options is empty, preventing downstream ZeroDivisionError / IndexError inside the Live loop * refactor(console): improve type safety and code quality in _console.py - Add Callable import from collections.abc for precise callback typing - Annotate StepTracker._refresh_cb as Callable[[], None] | None - Add parameter/return types to attach_refresh() - Use explicit keyword form typer.Exit(code=1) across all error exits - Add blank line between StepTracker class and get_key() (PEP 8) - Add regression test for select_with_arrows() raising ValueError on empty options dict * style(cli): add __all__ declaration to fix Ruff F401 lint warnings - Add explicit __all__ for intentional re-exports (BANNER, TAGLINE, get_key) - Prevent F401 unused import errors in CI lint checks - Maintain backward compatibility for external imports * Preserve public console imports The CLI package intentionally re-exports console helpers for compatibility, so __all__ must track that public surface instead of narrowing star imports to a partial set. Constraint: Existing tests import console helpers directly from specify_cli Rejected: Remove __all__ entirely | keeping an explicit export list documents the intended compatibility surface Confidence: high Scope-risk: narrow Directive: Keep __all__ synchronized when adding or removing specify_cli public re-exports Tested: uv run pytest tests/test_console_imports.py -q * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * style(cli): use explicit re-export syntax to fix ruff F401 warnings Use `X as X` form for BANNER, TAGLINE, and get_key imports to mark them as intentional public re-exports and silence ruff F401 lint errors. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""Regression guard: console symbols must remain importable from specify_cli."""
|
|
from specify_cli import (
|
|
console,
|
|
StepTracker,
|
|
get_key,
|
|
select_with_arrows,
|
|
BannerGroup,
|
|
show_banner,
|
|
BANNER,
|
|
TAGLINE,
|
|
)
|
|
|
|
|
|
def test_console_symbols_importable():
|
|
from rich.console import Console
|
|
assert isinstance(console, Console)
|
|
|
|
|
|
def test_console_symbols_available_from_star_import():
|
|
namespace = {}
|
|
exec("from specify_cli import *", namespace)
|
|
|
|
for symbol in (
|
|
"console",
|
|
"StepTracker",
|
|
"get_key",
|
|
"select_with_arrows",
|
|
"BannerGroup",
|
|
"show_banner",
|
|
"BANNER",
|
|
"TAGLINE",
|
|
):
|
|
assert symbol in namespace
|
|
|
|
|
|
def test_step_tracker_instantiable():
|
|
tracker = StepTracker("test")
|
|
tracker.add("step1", "Step One")
|
|
tracker.complete("step1", "done")
|
|
assert tracker.steps[0]["status"] == "done"
|
|
|
|
|
|
def test_select_with_arrows_raises_on_empty_options():
|
|
import pytest
|
|
with pytest.raises(ValueError, match="at least one option"):
|
|
select_with_arrows({})
|