Skip to content

Commit

Permalink
Merge pull request #11 from vishwamartur/add-unit-tests-ci
Browse files Browse the repository at this point in the history
Add unit tests and CI workflow using GitHub Actions
  • Loading branch information
alanalanlu authored Nov 21, 2024
2 parents d3c1403 + 0090e7b commit 036ef11
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.12

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry install
- name: Run tests
run: poetry run pytest
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,29 @@ Options:
--help Show this message and exit.
```


## Running Unit Tests

To run unit tests using `pytest`, use the following command:

```
poetry run pytest
```

## Continuous Integration (CI) Workflow

This repository includes a CI workflow using GitHub Actions. The workflow is defined in the `.github/workflows/ci.yml` file and is triggered on each push and pull request to the `main` branch. The workflow performs the following steps:

1. Checks out the code.
2. Sets up Python 3.12.
3. Installs dependencies using `poetry`.
4. Runs tests using `pytest`.

## Note on 2FA

When the destination site uses two-factor authentication (2FA), the workflow remains the same. Ensure that you complete the 2FA process and obtain the cookies/auth tokens/session tokens after 2FA. These tokens will be used in the workflow.


## Demo

[![Demo Video](http://markdown-videos-api.jorgenkh.no/youtube/7OJ4w5BCpQ0)](https://www.youtube.com/watch?v=7OJ4w5BCpQ0)
Expand Down
71 changes: 71 additions & 0 deletions tests/test_integration_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import unittest
from integuru.agent import IntegrationAgent
from integuru.models.agent_state import AgentState
from unittest.mock import patch, MagicMock

class TestIntegrationAgent(unittest.TestCase):

def setUp(self):
self.prompt = "Test prompt"
self.har_file_path = "test.har"
self.cookie_path = "test_cookies.json"
self.agent = IntegrationAgent(self.prompt, self.har_file_path, self.cookie_path)
self.state = AgentState(
master_node=None,
in_process_node=None,
to_be_processed_nodes=[],
in_process_node_dynamic_parts=[],
action_url="",
input_variables={}
)

@patch('integuru.agent.llm.get_instance')
def test_end_url_identify_agent(self, mock_llm_instance):
mock_response = MagicMock()
mock_response.additional_kwargs = {
'function_call': {
'arguments': '{"url": "http://example.com/action"}'
}
}
mock_llm_instance.return_value.invoke.return_value = mock_response

updated_state = self.agent.end_url_identify_agent(self.state)
self.assertEqual(updated_state[self.agent.ACTION_URL_KEY], "http://example.com/action")

@patch('integuru.agent.llm.get_instance')
def test_input_variables_identifying_agent(self, mock_llm_instance):
self.state[self.agent.IN_PROCESS_NODE_KEY] = "node_1"
self.state[self.agent.INPUT_VARIABLES_KEY] = {"var1": "value1"}
self.agent.dag_manager.graph.add_node("node_1", content={"key": MagicMock()})
self.agent.dag_manager.graph.nodes["node_1"]["content"]["key"].to_curl_command.return_value = "curl command"

mock_response = MagicMock()
mock_response.additional_kwargs = {
'function_call': {
'arguments': '{"identified_variables": [{"variable_name": "var1", "variable_value": "value1"}]}'
}
}
mock_llm_instance.return_value.invoke.return_value = mock_response

updated_state = self.agent.input_variables_identifying_agent(self.state)
self.assertEqual(updated_state[self.agent.INPUT_VARIABLES_KEY], {"var1": "value1"})

@patch('integuru.agent.llm.get_instance')
def test_dynamic_part_identifying_agent(self, mock_llm_instance):
self.state[self.agent.TO_BE_PROCESSED_NODES_KEY] = ["node_1"]
self.agent.dag_manager.graph.add_node("node_1", content={"key": MagicMock()})
self.agent.dag_manager.graph.nodes["node_1"]["content"]["key"].to_minified_curl_command.return_value = "curl command"

mock_response = MagicMock()
mock_response.additional_kwargs = {
'function_call': {
'arguments': '{"dynamic_parts": ["dynamic_part1"]}'
}
}
mock_llm_instance.return_value.invoke.return_value = mock_response

updated_state = self.agent.dynamic_part_identifying_agent(self.state)
self.assertEqual(updated_state[self.agent.IN_PROCESS_NODE_DYNAMIC_PARTS_KEY], ["dynamic_part1"])

if __name__ == '__main__':
unittest.main()

0 comments on commit 036ef11

Please sign in to comment.