import contextlib from typing import Generator import pytest import yaml from autogpt.commands.file_operations import read_file from tests.integration.agent_utils import run_interaction_loop from tests.integration.challenges.utils import run_multiple_times from tests.utils import requires_api_key def input_generator(input_sequence: list) -> Generator[str, None, None]: """ Creates a generator that yields input strings from the given sequence. :param input_sequence: A list of input strings. :return: A generator that yields input strings. """ yield from input_sequence @pytest.mark.skip("This challenge hasn't been beaten yet.") @pytest.mark.vcr @requires_api_key("OPENAI_API_KEY") @run_multiple_times(3) def test_information_retrieval_challenge_a(kubernetes_agent, monkeypatch) -> None: """ Test the challenge_a function in a given agent by mocking user inputs and checking the output file content. :param get_company_revenue_agent: The agent to test. :param monkeypatch: pytest's monkeypatch utility for modifying builtins. """ input_sequence = ["s", "s", "s", "s", "s", "EXIT"] gen = input_generator(input_sequence) monkeypatch.setattr("builtins.input", lambda _: next(gen)) with contextlib.suppress(SystemExit): run_interaction_loop(kubernetes_agent, None) file_path = str(kubernetes_agent.workspace.get_path("kube.yaml")) content = read_file(file_path) for word in ["apiVersion", "kind", "metadata", "spec"]: assert word in content, f"Expected the file to contain {word}" content = yaml.safe_load(content) for word in ["Service", "Deployment", "Pod"]: assert word in content["kind"], f"Expected the file to contain {word}"