|
| 1 | +"""Tests for uipath init command with openai-agents.""" |
| 2 | + |
| 3 | +import json |
| 4 | +import os |
| 5 | + |
| 6 | +from click.testing import CliRunner |
| 7 | +from uipath._cli.cli_init import init |
| 8 | + |
| 9 | + |
| 10 | +class TestInit: |
| 11 | + """Test init command for OpenAI agents.""" |
| 12 | + |
| 13 | + def test_init_basic_config_generation( |
| 14 | + self, |
| 15 | + runner: CliRunner, |
| 16 | + temp_dir: str, |
| 17 | + simple_agent_basic: str, |
| 18 | + simple_agent_translation: str, |
| 19 | + openai_agents_config: str, |
| 20 | + ) -> None: |
| 21 | + """Test configuration file generation with basic agent.""" |
| 22 | + with runner.isolated_filesystem(temp_dir=temp_dir): |
| 23 | + # Create agent scripts (config references both) |
| 24 | + with open("main.py", "w") as f: |
| 25 | + f.write(simple_agent_basic) |
| 26 | + |
| 27 | + with open("translation.py", "w") as f: |
| 28 | + f.write(simple_agent_translation) |
| 29 | + |
| 30 | + with open("openai_agents.json", "w") as f: |
| 31 | + f.write(openai_agents_config) |
| 32 | + |
| 33 | + result = runner.invoke(init) |
| 34 | + assert result.exit_code == 0 |
| 35 | + assert os.path.exists("entry-points.json") |
| 36 | + |
| 37 | + with open("entry-points.json", "r") as f: |
| 38 | + config = json.load(f) |
| 39 | + |
| 40 | + # Verify config structure |
| 41 | + assert "entryPoints" in config |
| 42 | + |
| 43 | + # Verify entryPoints properties |
| 44 | + entry = config["entryPoints"][0] |
| 45 | + assert entry["filePath"] == "basic" |
| 46 | + assert entry["type"] == "agent" |
| 47 | + |
| 48 | + # Verify input schema |
| 49 | + assert "input" in entry |
| 50 | + input_schema = entry["input"] |
| 51 | + assert input_schema["type"] == "object" |
| 52 | + assert "properties" in input_schema |
| 53 | + assert "required" in input_schema |
| 54 | + assert isinstance(input_schema["properties"], dict) |
| 55 | + assert isinstance(input_schema["required"], list) |
| 56 | + |
| 57 | + # OpenAI agents use default message input |
| 58 | + assert "message" in input_schema["properties"] |
| 59 | + assert "message" in input_schema["required"] |
| 60 | + |
| 61 | + # Verify output schema (default since no output_type specified) |
| 62 | + assert "output" in entry |
| 63 | + output_schema = entry["output"] |
| 64 | + assert "properties" in output_schema |
| 65 | + # Default output schema has "result" field |
| 66 | + assert "result" in output_schema["properties"] |
| 67 | + assert "required" in output_schema |
| 68 | + assert output_schema["type"] == "object" |
| 69 | + |
| 70 | + def test_init_translation_agent_config_generation( |
| 71 | + self, |
| 72 | + runner: CliRunner, |
| 73 | + temp_dir: str, |
| 74 | + simple_agent_basic: str, |
| 75 | + simple_agent_translation: str, |
| 76 | + openai_agents_config: str, |
| 77 | + ) -> None: |
| 78 | + """Test configuration file generation with translation agent.""" |
| 79 | + with runner.isolated_filesystem(temp_dir=temp_dir): |
| 80 | + # Create agent scripts |
| 81 | + with open("main.py", "w") as f: |
| 82 | + f.write(simple_agent_basic) |
| 83 | + |
| 84 | + with open("translation.py", "w") as f: |
| 85 | + f.write(simple_agent_translation) |
| 86 | + |
| 87 | + with open("openai_agents.json", "w") as f: |
| 88 | + f.write(openai_agents_config) |
| 89 | + |
| 90 | + result = runner.invoke(init) |
| 91 | + assert result.exit_code == 0 |
| 92 | + assert os.path.exists("entry-points.json") |
| 93 | + |
| 94 | + with open("entry-points.json", "r") as f: |
| 95 | + config = json.load(f) |
| 96 | + |
| 97 | + # Verify config structure |
| 98 | + assert "entryPoints" in config |
| 99 | + |
| 100 | + # Find the translation entry point |
| 101 | + translation_entry = None |
| 102 | + for entry in config["entryPoints"]: |
| 103 | + if entry["filePath"] == "translation": |
| 104 | + translation_entry = entry |
| 105 | + break |
| 106 | + |
| 107 | + assert translation_entry is not None |
| 108 | + assert translation_entry["type"] == "agent" |
| 109 | + |
| 110 | + # Verify input schema - should use default messages |
| 111 | + assert "input" in translation_entry |
| 112 | + input_schema = translation_entry["input"] |
| 113 | + assert input_schema["type"] == "object" |
| 114 | + assert "properties" in input_schema |
| 115 | + assert "message" in input_schema["properties"] |
| 116 | + assert "message" in input_schema["required"] |
| 117 | + |
| 118 | + # Verify output schema from agent's output_type |
| 119 | + assert "output" in translation_entry |
| 120 | + output_schema = translation_entry["output"] |
| 121 | + assert "properties" in output_schema |
| 122 | + |
| 123 | + # Verify output properties from TranslationOutput |
| 124 | + out_props = output_schema["properties"] |
| 125 | + assert "original_text" in out_props |
| 126 | + assert out_props["original_text"]["type"] == "string" |
| 127 | + assert out_props["original_text"]["description"] == "The original text" |
| 128 | + |
| 129 | + assert "translated_text" in out_props |
| 130 | + assert out_props["translated_text"]["type"] == "string" |
| 131 | + assert ( |
| 132 | + out_props["translated_text"]["description"] == "The translated text" |
| 133 | + ) |
| 134 | + |
| 135 | + assert "target_language" in out_props |
| 136 | + assert out_props["target_language"]["type"] == "string" |
| 137 | + assert ( |
| 138 | + out_props["target_language"]["description"] == "The target language" |
| 139 | + ) |
| 140 | + |
| 141 | + # Verify required fields in output |
| 142 | + assert "required" in output_schema |
| 143 | + assert "original_text" in output_schema["required"] |
| 144 | + assert "translated_text" in output_schema["required"] |
| 145 | + assert "target_language" in output_schema["required"] |
| 146 | + assert output_schema["type"] == "object" |
0 commit comments