refactor: update CLI initialization and prompt handling for improved user experience
Some checks failed
CI / test (3.13) (push) Failing after 32s

This commit is contained in:
Alexander Kalinovsky
2025-08-27 19:37:52 +03:00
parent 62b12690c8
commit e76e6eed85
4 changed files with 72 additions and 20 deletions

View File

@@ -630,6 +630,41 @@ post_tasks:
assert (out3 / "alembic").exists()
assert not (out3 / "locales").exists()
def test_init_command_project_name_fallback(self, temp_dir: Path) -> None:
"""Test that project_name falls back to output directory name when not provided."""
with patch("quickbot_cli.cli.TEMPLATES_DIR", temp_dir / "templates"):
# Create template structure
template_dir = temp_dir / "templates" / "basic"
template_dir.mkdir(parents=True)
# Create template spec WITHOUT project_name variable
spec_file = template_dir / "__template__.yaml"
spec_file.write_text("variables:\n description:\n prompt: Description\n default: A test project")
# Create template files
(template_dir / "app").mkdir()
(template_dir / "app" / "main.py.j2").write_text("app = FastAPI(title='{{ project_name }}')")
# Test with output directory that has a name (to test the fallback)
output_path = temp_dir / "my_project_output"
_init_project(
output=output_path,
template="basic",
project_name=None, # Explicitly set to None to trigger fallback
description="A test project",
author="Test Author",
license_name="MIT",
include_alembic=False,
include_i18n=False,
overwrite=False,
interactive=False, # Disable interactive mode to avoid prompting
)
# Verify that project_name was set to the output directory name
# This tests the fallback logic in line 297
assert output_path.exists()
# The project_name should be "my_project_output" (the directory name)
class TestCLIHelp:
"""Test CLI help and argument parsing."""
@@ -637,7 +672,7 @@ class TestCLIHelp:
def test_cli_help(self, cli_runner: CliRunner) -> None:
"""Test that CLI shows help information."""
# Test the actual CLI interface
result = cli_runner.invoke(app, ["--help"])
result = cli_runner.invoke(app, ["--help"], env={"NO_COLOR": "1", "COLUMNS": "120"})
assert result.exit_code == 0
# Check for the actual help text that appears
assert "init" in result.output
@@ -646,7 +681,7 @@ class TestCLIHelp:
def test_init_command_help(self, cli_runner: CliRunner) -> None:
"""Test that init command shows help information."""
# Test the actual CLI interface
result = cli_runner.invoke(app, ["init", "--help"])
result = cli_runner.invoke(app, ["init", "--help"], env={"NO_COLOR": "1", "COLUMNS": "120"})
assert result.exit_code == 0
# Check for the actual help text that appears
assert "--output" in result.output
@@ -655,7 +690,7 @@ class TestCLIHelp:
def test_init_command_arguments(self, cli_runner: CliRunner) -> None:
"""Test that init command accepts required arguments."""
# Test the actual CLI interface
result = cli_runner.invoke(app, ["init", "--help"])
result = cli_runner.invoke(app, ["init", "--help"], env={"NO_COLOR": "1", "COLUMNS": "120"})
assert result.exit_code == 0
assert "--output" in result.output
@@ -702,6 +737,14 @@ class TestCLIHelp:
assert hasattr(init, "__name__")
assert init.__name__ == "init"
def test_version_command(self, cli_runner: CliRunner) -> None:
"""Test that version command works and shows version information."""
# Test the actual CLI interface
result = cli_runner.invoke(app, ["version"], env={"NO_COLOR": "1", "COLUMNS": "120"})
assert result.exit_code == 0
# Check that it shows version information
assert "quickbot-cli version" in result.output
class TestCLIOverwriteParsing:
"""Test overwrite string parsing through the init function (covers conversion)."""