Skip to content

Commit

Permalink
improve inegration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Aug 28, 2024
1 parent 48fb846 commit 74adf65
Show file tree
Hide file tree
Showing 38 changed files with 470 additions and 252 deletions.
29 changes: 27 additions & 2 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
python-version: ${{ fromJson(inputs.python-versions || '["3.10", "3.11", "3.12"]' ) }}
splitCount: [5]
group: [1, 2, 3, 4, 5]
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -59,6 +57,33 @@ jobs:
timeout_minutes: 12
max_attempts: 2
command: make unit_tests async=false args="--splits ${{ matrix.splitCount }} --group ${{ matrix.group }}"
integration-tests:
name: Integration Tests - Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ${{ fromJson(inputs.python-versions || '["3.10", "3.11", "3.12"]' ) }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch || github.ref }}
- name: Setup Node.js
uses: actions/setup-node@v4
id: setup-node
with:
node-version: ${{ env.NODE_VERSION }}
- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_caching"
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
cache-key: ${{ runner.os }}-poetry-${{ env.POETRY_VERSION }}-${{ hashFiles('**/poetry.lock') }}
- name: Install Python dependencies
run: |
poetry env use ${{ matrix.python-version }}
poetry install
- name: Run integration tests
run: make integration_tests

test-cli:
name: Test CLI - Python ${{ matrix.python-version }}
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/scheduled_integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ jobs:
run: |
poetry env use ${{ matrix.python-version }}
poetry install
- name: Run integration tests
- name: Run unit tests with api keys
timeout-minutes: 12
run: |
make integration_tests
make unit_tests_api_keys
- name: Run integration tests with api keys
timeout-minutes: 20
run: |
make integration_tests_api_keys
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,20 @@ else
$(args)
endif

unit_tests_api_keys: ## run unit tests only with api key tests
poetry run pytest src/backend/tests \
--ignore=src/backend/tests/integration \
--instafail -n auto -ra -m "api_key_required" \
$(args)

integration_tests: ## run integration tests
poetry run pytest src/backend/tests/integration \
--instafail -ra \
--instafail -ra -m "not api_key_required" \
$(args)

integration_tests_api_keys: ## run integration tests only with api key tests
poetry run pytest src/backend/tests/integration \
--instafail -ra -m "api_key_required" \
$(args)

tests: ## run unit, integration, coverage tests
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ wolframalpha = "^5.1.3"
astra-assistants = "^2.1.0.10"
composio-langchain = "^0.5.8"
spider-client = "^0.0.27"
pytest = "^8.3.2"


[tool.poetry.group.dev.dependencies]
Expand Down
1 change: 1 addition & 0 deletions src/backend/base/langflow/components/inputs/ChatInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ChatInput(ChatComponent):
]

def message_response(self) -> Message:
print("running", self.input_value)
message = Message(
text=self.input_value,
sender=self.sender,
Expand Down
5 changes: 5 additions & 0 deletions src/backend/base/langflow/components/prompts/Prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class PromptComponent(Component):
async def build_prompt(
self,
) -> Message:
print("build_prompt")
prompt = await Message.from_template_and_variables(**self._attributes)
self.status = prompt.text

return prompt

def _update_template(self, frontend_node: dict):
Expand All @@ -41,6 +43,9 @@ def _update_template(self, frontend_node: dict):
return frontend_node

def post_code_processing(self, new_frontend_node: dict, current_frontend_node: dict):
print("post code..")
import traceback
traceback.print_stack()
"""
This function is called after the code validation is done.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def map_inputs(self, inputs: list["InputTypes"]):
for input_ in inputs:
if input_.name is None:
raise ValueError("Input name cannot be None.")
self._inputs[input_.name] = input_
self._inputs[input_.name] = deepcopy(input_)

def validate(self, params: dict):
"""
Expand Down Expand Up @@ -473,6 +473,8 @@ def _map_parameters_on_template(self, template: dict):
for name, value in self._parameters.items():
try:
template[name]["value"] = value
if value and "load_from_db" in template[name]:
template[name]["load_from_db"] = False
except KeyError:
close_match = find_closest_match(name, list(template.keys()))
if close_match:
Expand Down
48 changes: 30 additions & 18 deletions src/backend/base/langflow/graph/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from langflow.graph.vertex.base import Vertex, VertexStates
from langflow.graph.vertex.schema import NodeData
from langflow.graph.vertex.types import ComponentVertex, InterfaceVertex, StateVertex
from langflow.interface import initialize
from langflow.logging.logger import LogConfig, configure
from langflow.schema import Data
from langflow.schema.schema import INPUT_FIELD_NAME, InputType
Expand Down Expand Up @@ -195,33 +196,30 @@ def add_nodes_and_edges(self, nodes: list[NodeData], edges: list[EdgeData]):
self._edges = self._graph_data["edges"]
self.initialize()

def add_component(self, _id: str, component: "Component"):
if _id in self.vertex_map:
return

async def add_component(self, component: "Component", component_id: Optional[str] = None) -> str:
component_id = component_id or str(component.name + "-" + str(uuid.uuid4()))
if component_id in self.vertex_map:
raise ValueError(f"Component ID {component_id} already exists")
if not component_id.startswith(component.name):
raise ValueError(f"Component ID {component_id} does not match component name {component.name}")
frontend_node = component.to_frontend_node()
frontend_node["data"]["id"] = _id
frontend_node["id"] = _id
frontend_node["data"]["id"] = component_id
frontend_node["id"] = component_id
self._vertices.append(frontend_node)
vertex = self._create_vertex(frontend_node)
vertex.add_component_instance(component)
self.vertices.append(vertex)
self.vertex_map[_id] = vertex

if component._edges:
for edge in component._edges:
self._add_edge(edge)

if component._components:
for _component in component._components:
self.add_component(_component._id, _component)
self.vertex_map[component_id] = vertex
return component_id

def _set_start_and_end(self, start: "Component", end: "Component"):
if not hasattr(start, "to_frontend_node"):
raise TypeError(f"start must be a Component. Got {type(start)}")
if not hasattr(end, "to_frontend_node"):
raise TypeError(f"end must be a Component. Got {type(end)}")
self.add_component(start._id, start)
self.add_component(end._id, end)
self.add_component(start, start._id)
self.add_component(end, end._id)

def add_component_edge(self, source_id: str, output_input_tuple: tuple[str, str], target_id: str):
source_vertex = self.get_vertex(source_id)
Expand All @@ -235,6 +233,20 @@ def add_component_edge(self, source_id: str, output_input_tuple: tuple[str, str]
raise ValueError(f"Source vertex {source_id} does not have a custom component.")
if target_vertex._custom_component is None:
raise ValueError(f"Target vertex {target_id} does not have a custom component.")

try:
input_field = target_vertex.get_input(input_name)
input_types = input_field.input_types
input_field_type = str(input_field.field_type)
except ValueError:
input_field = target_vertex.data.get("node", {}).get("template", {}).get(input_name)
if not input_field:
raise ValueError(f"Input field {input_name} not found in target vertex {target_id}")
input_types = input_field.get("input_types", [])
input_field_type = input_field.get("type", "")



edge_data: EdgeData = {
"source": source_id,
"target": target_id,
Expand All @@ -249,8 +261,8 @@ def add_component_edge(self, source_id: str, output_input_tuple: tuple[str, str]
"targetHandle": {
"fieldName": input_name,
"id": target_vertex.id,
"inputTypes": target_vertex.get_input(input_name).input_types,
"type": str(target_vertex.get_input(input_name).field_type),
"inputTypes": input_types,
"type": input_field_type,
},
},
}
Expand Down
Loading

0 comments on commit 74adf65

Please sign in to comment.