fix: resolve lint, type-check, and test failures

- B904: raise KeyboardInterrupt from err in cli_provider.py
- mypy: add TYPE_CHECKING import for SQLiteConversationStorage, annotate
  _initialized class var in TaskScheduler, fix Match type params and
  Returning Any in create_agent.py
- tests: mock aget_llm_response in 3 integration tests that fail when
  network is blocked but OPENAI_API_KEY is set
- flow.py: use asyncio.run_coroutine_threadsafe() instead of asyncio.run()
  when a loop is already running in ask() and say()
- cli.py: fix threshold=0.0 treated as falsy by using `is not None` check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
alex-clawd
2026-05-13 00:06:55 -07:00
parent 75651f962d
commit 2ddc348ad2
6 changed files with 53 additions and 31 deletions

View File

@@ -544,7 +544,7 @@ def test(
_relaunch_via_uv(uv_args)
config_threshold = _read_config("test", "threshold") or _read_config("test_threshold")
effective_threshold = threshold or (float(config_threshold) if config_threshold is not None else None) or 0.7
effective_threshold = threshold if threshold is not None else (float(config_threshold) if config_threshold is not None else 0.7)
_test_new_agents(agent_files, n_iterations, model, effective_threshold, effective_judge)
else:
@@ -642,12 +642,12 @@ class _BenchmarkLiveProgress:
self._live.update(self._render())
def _render(self):
from rich.table import Table
from rich.spinner import Spinner
from rich.text import Text
from rich import box
from rich.spinner import Spinner
from rich.table import Table
from rich.text import Text
from crewai_cli.benchmark import _score_color, _fmt_tokens, _fmt_cost
from crewai_cli.benchmark import _fmt_cost, _fmt_tokens, _score_color
has_cost = any(
info.get("cost") is not None
@@ -821,7 +821,7 @@ def _test_new_agents(
if agents_tested == 0:
click.secho("No agents completed successfully.", fg="yellow")
raise SystemExit(1)
elif all_passed:
if all_passed:
click.secho(f"All tests passed ({agents_tested} agent(s)).", fg="green", bold=True)
else:
click.secho("Some tests failed.", fg="red", bold=True)

View File

@@ -3,15 +3,14 @@
from __future__ import annotations
import json
from pathlib import Path
import re
import subprocess
import sys
from pathlib import Path
from typing import Any
import click
from crewai_cli.constants import ENV_VARS, MODELS
from crewai_cli.constants import ENV_VARS
from crewai_cli.utils import load_env_vars, write_env_file
@@ -278,8 +277,8 @@ def _maybe_add_provider_extra(pyproject_path: Path, provider: str) -> None:
return
import re as _re
suffix = "," + ",".join(missing)
def _add_extras(m: _re.Match) -> str:
bracket = m.group(0)
def _add_extras(m: _re.Match[str]) -> str:
bracket: str = m.group(0)
return bracket[:-1] + suffix + "]"
updated = _re.sub(r'crewai\[[^\]]+\]', _add_extras, content, count=1)
if updated != content:
@@ -573,7 +572,7 @@ def _select_model() -> str:
p_idx = _arrow_or_fallback(provider_labels)
if p_idx == len(_PROVIDERS):
custom = click.prompt(" Enter model (provider/model)", type=str)
custom: str = click.prompt(" Enter model (provider/model)", type=str)
return custom.strip()
provider_key, provider_name = _PROVIDERS[p_idx]
@@ -781,11 +780,11 @@ def _setup_env(base: Path, llm_model: str) -> None:
def _prompt_agent_name() -> str:
"""Prompt for a valid agent identifier."""
while True:
name = click.prompt(
raw: str = click.prompt(
" Agent identifier (lowercase, hyphens/underscores, no spaces)",
type=str,
)
name = name.strip().lower()
name = raw.strip().lower()
if _AGENT_NAME_RE.match(name):
return name
click.secho(