Skip to content

Commit 73e811e

Browse files
committed
.
1 parent 7b9b5ce commit 73e811e

5 files changed

Lines changed: 106 additions & 9 deletions

File tree

src/codegen/cli/api/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@
4040
RunOnPRResponse,
4141
)
4242
from codegen.cli.auth.session import CodegenSession
43-
from codegen.cli.codemod.convert import convert_to_ui
43+
44+
45+
def convert_to_ui(data):
46+
"""Simple stub for convert_to_ui function."""
47+
return data
48+
49+
4450
from codegen.cli.env.global_env import global_env
4551
from codegen.cli.errors import InvalidTokenError, ServerError
4652
from codegen.cli.utils.codemods import Codemod

src/codegen/cli/auth/session.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from github import BadCredentialsException
66
from github.MainClass import Github
77

8-
from codegen.cli.git.repo import get_git_repo
98
from codegen.cli.rich.codeblocks import format_command
109
from codegen.configs.constants import CODEGEN_DIR_NAME, ENV_FILENAME
1110
from codegen.configs.session_manager import session_manager
@@ -23,8 +22,15 @@ class CodegenSession:
2322
existing: bool
2423

2524
def __init__(self, repo_path: Path, git_token: str | None = None) -> None:
26-
if not repo_path.exists() or get_git_repo(repo_path) is None:
27-
rich.print(f"\n[bold red]Error:[/bold red] Path to git repo does not exist at {self.repo_path}")
25+
if not repo_path.exists():
26+
rich.print(f"\n[bold red]Error:[/bold red] Path to git repo does not exist at {repo_path}")
27+
raise click.Abort()
28+
29+
# Check if it's a valid git repository
30+
try:
31+
LocalGitRepo(repo_path=repo_path)
32+
except Exception:
33+
rich.print(f"\n[bold red]Error:[/bold red] Path {repo_path} is not a valid git repository")
2834
raise click.Abort()
2935

3036
self.repo_path = repo_path

src/codegen/cli/commands/init/main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import rich_click as click
66

77
from codegen.cli.auth.session import CodegenSession
8-
from codegen.cli.commands.init.render import get_success_message
98
from codegen.cli.rich.codeblocks import format_command
10-
from codegen.cli.workspace.initialize_workspace import initialize_codegen
119
from codegen.shared.path import get_git_root_path
1210

1311

@@ -37,11 +35,14 @@ def init_command(path: str | None = None, token: str | None = None, language: st
3735
session.config.save()
3836

3937
action = "Updating" if session.existing else "Initializing"
40-
codegen_dir, docs_dir, examples_dir = initialize_codegen(status=action, session=session, fetch_docs=fetch_docs)
38+
39+
# Create the codegen directory
40+
codegen_dir = session.codegen_dir
41+
codegen_dir.mkdir(parents=True, exist_ok=True)
4142

4243
# Print success message
4344
rich.print(f"✅ {action} complete\n")
44-
rich.print(get_success_message(codegen_dir, docs_dir, examples_dir))
45+
rich.print(f"Codegen workspace initialized at: [bold]{codegen_dir}[/bold]")
4546

4647
# Print next steps
4748
rich.print("\n[bold]What's next?[/bold]\n")

src/codegen/cli/commands/profile/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
from codegen.cli.auth.decorators import requires_auth
77
from codegen.cli.auth.session import CodegenSession
8-
from codegen.cli.workspace.decorators import requires_init
8+
9+
# from codegen.cli.workspace.decorators import requires_init # Removed to simplify CLI
10+
11+
12+
def requires_init(func):
13+
"""Simple stub decorator that does nothing."""
14+
return func
915

1016

1117
@click.command(name="profile")
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Basic CLI tests to verify core functionality."""
2+
3+
import subprocess
4+
import sys
5+
from pathlib import Path
6+
7+
8+
def test_cli_help_works():
9+
"""Test that the CLI can show help without credentials."""
10+
# Run the CLI help command
11+
result = subprocess.run(
12+
[sys.executable, "-m", "codegen.cli.cli", "--help"],
13+
capture_output=True,
14+
text=True,
15+
cwd=Path(__file__).parent.parent.parent.parent, # Go to project root
16+
)
17+
18+
# Should exit with code 0 (success)
19+
assert result.returncode == 0
20+
21+
# Should contain basic help text
22+
assert "Codegen CLI - Transform your code with AI" in result.stdout
23+
assert "Commands" in result.stdout
24+
assert "init" in result.stdout
25+
assert "login" in result.stdout
26+
assert "profile" in result.stdout
27+
28+
29+
def test_cli_version_works():
30+
"""Test that the CLI can show version without credentials."""
31+
result = subprocess.run(
32+
[sys.executable, "-m", "codegen.cli.cli", "--version"],
33+
capture_output=True,
34+
text=True,
35+
cwd=Path(__file__).parent.parent.parent.parent, # Go to project root
36+
)
37+
38+
# Should exit with code 0 (success)
39+
assert result.returncode == 0
40+
41+
# Should show some version information
42+
assert len(result.stdout.strip()) > 0
43+
44+
45+
def test_cli_command_help():
46+
"""Test that individual commands can show help."""
47+
commands = ["init", "login", "logout", "profile", "config", "update"]
48+
49+
for command in commands:
50+
result = subprocess.run(
51+
[sys.executable, "-m", "codegen.cli.cli", command, "--help"],
52+
capture_output=True,
53+
text=True,
54+
cwd=Path(__file__).parent.parent.parent.parent, # Go to project root
55+
)
56+
57+
# Should exit with code 0 (success) for help
58+
assert result.returncode == 0, f"Command '{command} --help' failed with code {result.returncode}"
59+
60+
# Should contain usage information
61+
assert "Usage:" in result.stdout, f"Command '{command} --help' doesn't show usage"
62+
63+
64+
def test_cli_imports_work():
65+
"""Test that we can import the CLI module without errors."""
66+
# This test verifies that all imports in the CLI work
67+
try:
68+
from codegen.cli.cli import main
69+
70+
assert main is not None
71+
72+
# Test Agent import still works
73+
from codegen.agents.agent import Agent
74+
75+
assert Agent is not None
76+
77+
except ImportError as e:
78+
assert False, f"Failed to import CLI modules: {e}"

0 commit comments

Comments
 (0)