Files
crewAI/lib/crewai/tests/cli/test_replay_from_task.py
Greyson Lalonde bada7fd909 chore: merge main into gl/chore/refactor-cli
Resolve conflicts from origin/main: relocate new CLI additions
(checkpoint_tui, deploy/validate, remote_template, content_crew
templates) into lib/cli, rewrite imports for the standalone
crewai-cli package, port main's trained_agents_file param and
predeploy validation, and bump python-dotenv/pydantic in
crewai-cli to match crewai's constraints. Add the new
mark_ephemeral_trace_batch_as_failed method to the relocated
crewai.plus_api. Update tests for the new payload field, deploy
--skip-validate kwarg, and crewai_cli import paths.
2026-05-05 02:00:39 +08:00

61 lines
1.9 KiB
Python

"""Tests for ``crewai replay`` and the trained-agents file plumbing."""
import subprocess
from unittest import mock
from click.testing import CliRunner
import pytest
from crewai_cli import replay_from_task
from crewai_cli.cli import replay
@pytest.fixture
def runner() -> CliRunner:
return CliRunner()
@mock.patch("crewai_cli.cli.replay_task_command")
def test_replay_passes_filename(replay_task_command_mock: mock.Mock, runner: CliRunner) -> None:
result = runner.invoke(replay, ["-t", "abc123", "-f", "my_custom.pkl"])
replay_task_command_mock.assert_called_once_with(
"abc123", trained_agents_file="my_custom.pkl"
)
assert result.exit_code == 0
@mock.patch("crewai_cli.cli.replay_task_command")
def test_replay_without_filename_passes_none(
replay_task_command_mock: mock.Mock, runner: CliRunner
) -> None:
result = runner.invoke(replay, ["-t", "abc123"])
replay_task_command_mock.assert_called_once_with(
"abc123", trained_agents_file=None
)
assert result.exit_code == 0
@mock.patch("crewai_cli.replay_from_task.subprocess.run")
def test_replay_task_command_sets_env_var(mock_subprocess_run: mock.Mock) -> None:
mock_subprocess_run.return_value = subprocess.CompletedProcess(
args=["uv", "run", "replay", "abc123"], returncode=0
)
replay_from_task.replay_task_command("abc123", trained_agents_file="my_custom.pkl")
_, kwargs = mock_subprocess_run.call_args
assert kwargs["env"]["CREWAI_TRAINED_AGENTS_FILE"] == "my_custom.pkl"
@mock.patch("crewai_cli.replay_from_task.subprocess.run")
def test_replay_task_command_omits_env_var_without_filename(
mock_subprocess_run: mock.Mock,
) -> None:
mock_subprocess_run.return_value = subprocess.CompletedProcess(
args=["uv", "run", "replay", "abc123"], returncode=0
)
replay_from_task.replay_task_command("abc123")
_, kwargs = mock_subprocess_run.call_args
assert "CREWAI_TRAINED_AGENTS_FILE" not in kwargs["env"]