mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-28 10:09:21 +00:00
fix(cli): avoid auth retry for deploy exits
This commit is contained in:
@@ -13,6 +13,10 @@ from crewai_cli.plus_api import PlusAPI
|
|||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticationRequiredError(SystemExit):
|
||||||
|
"""Raised when a Plus API command needs the user to log in first."""
|
||||||
|
|
||||||
|
|
||||||
class BaseCommand:
|
class BaseCommand:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._telemetry = Telemetry()
|
self._telemetry = Telemetry()
|
||||||
@@ -31,7 +35,7 @@ class PlusAPIMixin:
|
|||||||
style="bold red",
|
style="bold red",
|
||||||
)
|
)
|
||||||
console.print("Run 'crewai login' to sign up/login.", style="bold green")
|
console.print("Run 'crewai login' to sign up/login.", style="bold green")
|
||||||
raise SystemExit from None
|
raise AuthenticationRequiredError from None
|
||||||
|
|
||||||
def _validate_response(self, response: httpx.Response) -> None:
|
def _validate_response(self, response: httpx.Response) -> None:
|
||||||
"""Handle and display error messages from API responses.
|
"""Handle and display error messages from API responses.
|
||||||
|
|||||||
@@ -364,20 +364,40 @@ def _chain_deploy() -> None:
|
|||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
def print_system_exit_failure(exc: SystemExit) -> None:
|
||||||
|
if isinstance(exc.code, int):
|
||||||
|
detail = f" with exit code {exc.code}"
|
||||||
|
elif exc.code:
|
||||||
|
detail = f": {exc.code}"
|
||||||
|
else:
|
||||||
|
detail = ""
|
||||||
|
console.print(f"\nDeploy failed{detail}\n", style="bold red")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
from crewai_cli.command import AuthenticationRequiredError
|
||||||
from crewai_cli.deploy.main import DeployCommand
|
from crewai_cli.deploy.main import DeployCommand
|
||||||
|
|
||||||
console.print("\nStarting deployment…\n", style="bold #FF5A50")
|
console.print("\nStarting deployment…\n", style="bold #FF5A50")
|
||||||
DeployCommand().create_crew(confirm=True, skip_validate=True)
|
DeployCommand().create_crew(confirm=True, skip_validate=True)
|
||||||
except SystemExit:
|
except AuthenticationRequiredError:
|
||||||
from crewai_cli.authentication.main import AuthenticationCommand
|
from crewai_cli.authentication.main import AuthenticationCommand
|
||||||
|
|
||||||
console.print()
|
console.print()
|
||||||
AuthenticationCommand().login()
|
AuthenticationCommand().login()
|
||||||
try:
|
try:
|
||||||
DeployCommand().create_crew(confirm=True, skip_validate=True)
|
DeployCommand().create_crew(confirm=True, skip_validate=True)
|
||||||
|
except AuthenticationRequiredError:
|
||||||
|
console.print(
|
||||||
|
"\nDeploy failed: authentication is still required.\n",
|
||||||
|
style="bold red",
|
||||||
|
)
|
||||||
|
except SystemExit as e:
|
||||||
|
print_system_exit_failure(e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"\nDeploy failed: {e}\n", style="bold red")
|
console.print(f"\nDeploy failed: {e}\n", style="bold red")
|
||||||
|
except SystemExit as e:
|
||||||
|
print_system_exit_failure(e)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"\nDeploy failed: {e}\n", style="bold red")
|
console.print(f"\nDeploy failed: {e}\n", style="bold red")
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from crewai.events.types.tool_usage_events import (
|
|||||||
ToolUsageFinishedEvent,
|
ToolUsageFinishedEvent,
|
||||||
ToolUsageStartedEvent,
|
ToolUsageStartedEvent,
|
||||||
)
|
)
|
||||||
|
from crewai_cli.command import AuthenticationRequiredError
|
||||||
from crewai_cli import run_crew
|
from crewai_cli import run_crew
|
||||||
from crewai_cli.crew_run_tui import CrewRunApp
|
from crewai_cli.crew_run_tui import CrewRunApp
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ def test_chain_deploy_skips_validation_after_auth_retry(monkeypatch) -> None:
|
|||||||
create_calls.append(kwargs)
|
create_calls.append(kwargs)
|
||||||
FakeDeployCommand.attempts += 1
|
FakeDeployCommand.attempts += 1
|
||||||
if FakeDeployCommand.attempts == 1:
|
if FakeDeployCommand.attempts == 1:
|
||||||
raise SystemExit(1)
|
raise AuthenticationRequiredError
|
||||||
|
|
||||||
class FakeAuthenticationCommand:
|
class FakeAuthenticationCommand:
|
||||||
def login(self) -> None:
|
def login(self) -> None:
|
||||||
@@ -89,6 +90,32 @@ def test_chain_deploy_skips_validation_after_auth_retry(monkeypatch) -> None:
|
|||||||
assert login_calls == [True]
|
assert login_calls == [True]
|
||||||
|
|
||||||
|
|
||||||
|
def test_chain_deploy_does_not_login_for_deploy_exit(monkeypatch, capsys) -> None:
|
||||||
|
create_calls: list[dict[str, object]] = []
|
||||||
|
login_calls: list[bool] = []
|
||||||
|
|
||||||
|
class FakeDeployCommand:
|
||||||
|
def create_crew(self, **kwargs) -> None:
|
||||||
|
create_calls.append(kwargs)
|
||||||
|
raise SystemExit(42)
|
||||||
|
|
||||||
|
class FakeAuthenticationCommand:
|
||||||
|
def login(self) -> None:
|
||||||
|
login_calls.append(True)
|
||||||
|
|
||||||
|
monkeypatch.setattr("crewai_cli.deploy.main.DeployCommand", FakeDeployCommand)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"crewai_cli.authentication.main.AuthenticationCommand",
|
||||||
|
FakeAuthenticationCommand,
|
||||||
|
)
|
||||||
|
|
||||||
|
run_crew._chain_deploy()
|
||||||
|
|
||||||
|
assert create_calls == [{"confirm": True, "skip_validate": True}]
|
||||||
|
assert login_calls == []
|
||||||
|
assert "Deploy failed with exit code 42" in capsys.readouterr().out
|
||||||
|
|
||||||
|
|
||||||
def test_plan_step_status_updates_only_the_explicit_step() -> None:
|
def test_plan_step_status_updates_only_the_explicit_step() -> None:
|
||||||
app = _app_with_plan()
|
app = _app_with_plan()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user