From d0564b63272872acc64fba74813e688f2785a29a Mon Sep 17 00:00:00 2001 From: OC Date: Thu, 28 Nov 2024 19:26:08 +0530 Subject: [PATCH 1/6] Added test for other commands --- tests/test_cli_loads.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_cli_loads.py b/tests/test_cli_loads.py index 98ff2318..f9ff71fb 100644 --- a/tests/test_cli_loads.py +++ b/tests/test_cli_loads.py @@ -43,6 +43,50 @@ def test_init_command(self): # Clean up shutil.rmtree(test_dir) + def test_generate_agent_command(self): + """Test the 'generate agent' command.""" + agent_name = "test_agent" + result = self.run_cli("generate", "agent", agent_name) + self.assertEqual(result.returncode, 0) + # Verify that the agent is added to agents.yaml + agents_config = Path("src/config/agents.yaml") + self.assertTrue(agents_config.exists()) + with open(agents_config, 'r') as f: + content = f.read() + self.assertIn(agent_name, content) + + def test_generate_task_command(self): + """Test the 'generate task' command.""" + task_name = "test_task" + result = self.run_cli("generate", "task", task_name) + self.assertEqual(result.returncode, 0) + # Verify that the task is added to tasks.yaml + tasks_config = Path("src/config/tasks.yaml") + self.assertTrue(tasks_config.exists()) + with open(tasks_config, 'r') as f: + content = f.read() + self.assertIn(task_name, content) + + def test_tools_list_command(self): + """Test the 'tools list' command.""" + result = self.run_cli("tools", "list") + self.assertEqual(result.returncode, 0) + self.assertIn("Available AgentStack Tools:", result.stdout) + + def test_tools_add_command(self): + """Test the 'tools add' command.""" + tool_name = "example_tool" + result = self.run_cli("tools", "add", tool_name) + self.assertEqual(result.returncode, 0) + self.assertIn(f"Tool {tool_name} added", result.stdout) + # Clean up: remove the tool + self.run_cli("tools", "remove", tool_name) + + def test_run_command(self): + """Test the 'run' command.""" + result = self.run_cli("run") + self.assertEqual(result.returncode, 0) + self.assertIn("Running your agent", result.stdout) if __name__ == "__main__": From a676794ecafa09038ba10d1dd18a1a4d3cc4bc93 Mon Sep 17 00:00:00 2001 From: OC Date: Thu, 28 Nov 2024 19:26:34 +0530 Subject: [PATCH 2/6] Added instructions to run the tests in CONTRIBUTING.md file --- CONTRIBUTING.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6d0c57fe..5c6c626c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,4 +36,13 @@ Adding tools is easy once you understand the project structure. A few things nee 4. Manually test your tool integration by running `agentstack tools add ` and ensure it behaves as expected. ## Tests -HAHAHAHAHAHAHA good one \ No newline at end of file +Tests are written in `tests` folder with the cli tests being in `tests/test_cli_loads.py`. + +Currently some of the tests will not work but you can run the tests by + +``` +cd tests +python -m unittest discover +``` + +and check the results \ No newline at end of file From 027286c38d46e06093ab42330e13dc5b00597d5b Mon Sep 17 00:00:00 2001 From: OC Date: Thu, 28 Nov 2024 19:27:54 +0530 Subject: [PATCH 3/6] Updated Contributing.md File --- CONTRIBUTING.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5c6c626c..196c15c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,6 +43,4 @@ Currently some of the tests will not work but you can run the tests by ``` cd tests python -m unittest discover -``` - -and check the results \ No newline at end of file +``` \ No newline at end of file From 75ce2a6cdcff3258c315ae9862edbeabdcb282e2 Mon Sep 17 00:00:00 2001 From: OC Date: Sun, 1 Dec 2024 13:58:15 +0530 Subject: [PATCH 4/6] Updated the test_cli_loads.py file for the requested changes --- tests/test_cli_loads.py | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/tests/test_cli_loads.py b/tests/test_cli_loads.py index f9ff71fb..47c3564b 100644 --- a/tests/test_cli_loads.py +++ b/tests/test_cli_loads.py @@ -43,50 +43,62 @@ def test_init_command(self): # Clean up shutil.rmtree(test_dir) - def test_generate_agent_command(self): + + # TODO: this is definitely not a clean way to test the CLI and + # TODO: should be done more elegantly. For now, this allows + # TODO: the tests to run sequentially and maintain state between + # TODO: them without creating conflicting projects. + def test_project_build_command(self): + """Test the 'init' command to create a project directory.""" + # Ensure the directory doesn't exist from previous runs + if self.TEST_DIR.exists(): + shutil.rmtree(self.TEST_DIR) + + result = self.run_cli("init", str(self.TEST_DIR), "--no-wizard") + self.assertEqual(result.returncode, 0) + self.assertTrue(self.TEST_DIR.exists()) + """Test the 'generate agent' command.""" agent_name = "test_agent" - result = self.run_cli("generate", "agent", agent_name) + result = self.run_cli("generate", "agent", agent_name, cwd=self.TEST_DIR) self.assertEqual(result.returncode, 0) # Verify that the agent is added to agents.yaml - agents_config = Path("src/config/agents.yaml") + agents_config = self.TEST_DIR / Path("src/config/agents.yaml") self.assertTrue(agents_config.exists()) with open(agents_config, 'r') as f: content = f.read() self.assertIn(agent_name, content) - def test_generate_task_command(self): """Test the 'generate task' command.""" task_name = "test_task" - result = self.run_cli("generate", "task", task_name) + result = self.run_cli("generate", "task", task_name, cwd=self.TEST_DIR) self.assertEqual(result.returncode, 0) # Verify that the task is added to tasks.yaml - tasks_config = Path("src/config/tasks.yaml") + tasks_config = self.TEST_DIR /Path("src/config/tasks.yaml") self.assertTrue(tasks_config.exists()) with open(tasks_config, 'r') as f: content = f.read() self.assertIn(task_name, content) - def test_tools_list_command(self): """Test the 'tools list' command.""" - result = self.run_cli("tools", "list") + result = self.run_cli("tools", "list", cwd=self.TEST_DIR) self.assertEqual(result.returncode, 0) self.assertIn("Available AgentStack Tools:", result.stdout) - def test_tools_add_command(self): """Test the 'tools add' command.""" - tool_name = "example_tool" - result = self.run_cli("tools", "add", tool_name) + tool_name = "ftp" + result = self.run_cli("tools", "add", tool_name, cwd=self.TEST_DIR) self.assertEqual(result.returncode, 0) self.assertIn(f"Tool {tool_name} added", result.stdout) # Clean up: remove the tool self.run_cli("tools", "remove", tool_name) - def test_run_command(self): """Test the 'run' command.""" - result = self.run_cli("run") + result = self.run_cli("run", cwd=self.TEST_DIR) self.assertEqual(result.returncode, 0) - self.assertIn("Running your agent", result.stdout) + + # Clean up + shutil.rmtree(self.TEST_DIR) if __name__ == "__main__": From d66b3f47ea423aacf2025abd74df7b905c0a68bc Mon Sep 17 00:00:00 2001 From: OC Date: Sun, 1 Dec 2024 13:58:46 +0530 Subject: [PATCH 5/6] Updated the CONTRIBUTING.md file with the test section --- CONTRIBUTING.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 196c15c2..58052c9f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,6 @@ # Contributing -First of all, __thank you__ for your interest in contributing to AgentStack! Even the smallest contributions help a _ton_. + +First of all, **thank you** for your interest in contributing to AgentStack! Even the smallest contributions help a _ton_. Our vision is to build the defacto CLI for quickly spinning up an AI Agent project. We want to be the [create-react-app](https://create-react-app.dev/) of agents. Our inspiration also includes the oh-so-convenient [Angular CLI](https://v17.angular.io/cli). @@ -17,9 +18,11 @@ The best place to engage in conversation about your contribution is in the Issue - This will install the CLI locally and in editable mode so you can use `agentstack ` to test your latest changes ## Project Structure + TODO ## Adding Tools + If you're reading this section, you probably have a product that AI agents can use as a tool. We're glad you're here! Adding tools is easy once you understand the project structure. A few things need to be done for a tool to be considered completely supported: @@ -36,11 +39,19 @@ Adding tools is easy once you understand the project structure. A few things nee 4. Manually test your tool integration by running `agentstack tools add ` and ensure it behaves as expected. ## Tests -Tests are written in `tests` folder with the cli tests being in `tests/test_cli_loads.py`. -Currently some of the tests will not work but you can run the tests by +Tests are written in `tests` folder with the cli tests being in `tests/test_cli_loads.py`. + +Testing is sparse at the moment but contributions are very welcome! 🙏 + +You can run tests by first installing test dependencies with + +```bash +pip install ".[test]" +``` + +Then running tox with +```bash +tox ``` -cd tests -python -m unittest discover -``` \ No newline at end of file From 678574a727ef5c2612ceae12fda4101d5904030b Mon Sep 17 00:00:00 2001 From: OC Date: Tue, 3 Dec 2024 15:23:43 +0530 Subject: [PATCH 6/6] Added the section and ran the tests --- tests/test_cli_loads.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_cli_loads.py b/tests/test_cli_loads.py index 47c3564b..d4d6d4d7 100644 --- a/tests/test_cli_loads.py +++ b/tests/test_cli_loads.py @@ -43,6 +43,19 @@ def test_init_command(self): # Clean up shutil.rmtree(test_dir) + + def setUp(self): + self.TEST_DIR = Path("test_project") + + def run_cli(self, *args, cwd=None): + """Helper method to run the CLI with arguments.""" + result = subprocess.run( + [*self.CLI_ENTRY, *args], + capture_output=True, + text=True, + cwd=cwd + ) + return result # TODO: this is definitely not a clean way to test the CLI and # TODO: should be done more elegantly. For now, this allows