Skip to content

Commit 1db2c46

Browse files
authored
Merge pull request #2 from workflowai/guillaume/e2e-tests
Feat add first e2e test
2 parents 62622e1 + 16087cb commit 1db2c46

File tree

16 files changed

+361
-42
lines changed

16 files changed

+361
-42
lines changed

.env.sample

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
WORKFLOWAI_API_URL=
22
WORKFLOWAI_API_KEY=
3+
4+
# Used when running e2e tests
5+
WORKFLOWAI_TEST_API_URL=
6+
WORKFLOWAI_TEST_API_KEY=

.github/workflows/e2e.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: E2E tests
2+
on:
3+
push:
4+
branches:
5+
- main
6+
schedule:
7+
# Every night at midnight
8+
- cron: "0 0 * * *"
9+
workflow_dispatch:
10+
11+
env:
12+
WORKFLOWAI_TEST_API_URL: https://api.workflowai.dev
13+
14+
jobs:
15+
e2e-tests:
16+
# TODO: we should run on multiple environments
17+
environment: staging
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- name: Install Poetry
23+
run: pipx install poetry==1.8.0
24+
25+
- name: Install dependencies
26+
run: |
27+
poetry config virtualenvs.in-project true
28+
poetry install --all-extras
29+
30+
- name: Run tests
31+
run: poetry run pytest tests/e2e
32+
env:
33+
WORKFLOWAI_TEST_API_KEY: ${{ secrets.WORKFLOWAI_TEST_API_KEY }}
34+
35+
- name: Send Slack Notification
36+
env:
37+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
38+
run: |
39+
curl -X POST -H 'Content-type: application/json' --data '{
40+
"blocks": [
41+
{
42+
"type": "section",
43+
"text": {
44+
"type": "mrkdwn",
45+
"text": "*:white_check_mark: Python E2E Tests Completed*"
46+
}
47+
}
48+
]
49+
}' $SLACK_WEBHOOK_URL
50+
51+
- name: Notify Slack on Failure
52+
if: failure()
53+
env:
54+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
55+
GITHUB_RUN_URL: ${{ github.server_url }}/{{ github.repository }}/actions/runs/{{ github.run_id }}
56+
run: |
57+
curl -X POST -H 'Content-type: application/json' --data '{
58+
"blocks": [
59+
{
60+
"type": "section",
61+
"text": {
62+
"type": "mrkdwn",
63+
"text": ":warning: *Python E2E Tests Failed!* \n <!channel>"
64+
}
65+
},
66+
{
67+
"type": "section",
68+
"fields": [
69+
{
70+
"type": "mrkdwn",
71+
"text": "*Job:* ${{ github.job }}"
72+
},
73+
{
74+
"type": "mrkdwn",
75+
"text": "*Run Number:* ${{ github.run_number }}"
76+
},
77+
{
78+
"type": "mrkdwn",
79+
"text": "*Repository:* ${{ github.repository }}"
80+
},
81+
{
82+
"type": "mrkdwn",
83+
"text": "*Branch:* ${{ github.ref }}"
84+
}
85+
]
86+
},
87+
{
88+
"type": "actions",
89+
"elements": [
90+
{
91+
"type": "button",
92+
"text": {
93+
"type": "plain_text",
94+
"text": "View Action"
95+
},
96+
"url": "${{ env.GITHUB_RUN_URL }}"
97+
}
98+
]
99+
}
100+
]
101+
}' $SLACK_WEBHOOK_URL

.github/workflows/quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ jobs:
4747
poetry install --all-extras
4848
4949
- name: Run tests
50-
run: poetry run pytest
50+
run: poetry run pytest --ignore=tests/e2e

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
hooks:
55
- id: poetry-lock
66
name: poetry lock
7-
entry: poetry check --lock
7+
entry: poetry check --lock
88
language: system
99
pass_filenames: false
1010
always_run: true
@@ -22,6 +22,6 @@ repos:
2222
types: [file, python]
2323
- id: pytest
2424
name: testing (pytest)
25-
entry: pytest .
25+
entry: pytest . --ignore tests/e2e
2626
language: system
2727
pass_filenames: false

poetry.lock

Lines changed: 43 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "workflowai"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
description = ""
55
authors = ["Guillaume Aquilina <guillaume@workflowai.com>"]
66
readme = "README.md"
@@ -22,6 +22,7 @@ ruff = "^0.4.9"
2222
freezegun = "^1.5.1"
2323
pre-commit = "^3.7.1"
2424
pytest-httpx = "^0.30.0"
25+
python-dotenv = "^1.0.1"
2526

2627
[tool.poetry.extras]
2728
cli = ["typer", "rich"]

tests/e2e/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
import pytest
4+
from dotenv import load_dotenv
5+
6+
from workflowai import Client, start
7+
8+
load_dotenv()
9+
10+
11+
@pytest.fixture(scope="session")
12+
def wai() -> Client:
13+
return start(
14+
url=os.environ["WORKFLOWAI_TEST_API_URL"],
15+
api_key=os.environ["WORKFLOWAI_TEST_API_KEY"],
16+
)

tests/e2e/deploy_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import uuid
2+
3+
import workflowai
4+
from examples.city_to_capital_task import CityToCapitalTask, CityToCapitalTaskInput
5+
from workflowai.core.domain.task_version_reference import TaskVersionReference
6+
7+
8+
async def test_deploy_task(wai: workflowai.Client):
9+
task = CityToCapitalTask(
10+
id=f"citytocapital-{uuid.uuid4()}",
11+
schema_id=0,
12+
version=TaskVersionReference.with_properties(model=""),
13+
)
14+
15+
await wai.register(task)
16+
17+
assert task.schema_id == 1
18+
19+
# Run task with input
20+
task_run = await wai.run(task, task_input=CityToCapitalTaskInput(city="Osaka"))
21+
assert task_run.task_output.capital == "Tokyo"
22+
assert task_run.version.iteration == 1
23+
24+
# Deploy group to dev environnment
25+
version = await wai.deploy_version(task, iteration=1, environment="dev")
26+
assert version.iteration == 1
27+
assert version.aliases == {"environment=dev"}
28+
29+
# Run using the environment and the same input
30+
task_run2 = await wai.run(
31+
task, task_input=CityToCapitalTaskInput(city="Osaka"), environment="dev"
32+
)
33+
# IDs will match since we are using cache
34+
assert task_run.id == task_run2.id
35+
36+
# Run using the environment and a different input
37+
task_run3 = await wai.run(
38+
task, task_input=CityToCapitalTaskInput(city="Toulouse"), environment="dev"
39+
)
40+
assert task_run3.task_output.capital == "Paris"
41+
assert task_run3.id != task_run2.id

tests/fixtures/task_version.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"id": "0a35fd2e55def802918880d094f634f9",
3+
"iteration": 1,
4+
"properties": {
5+
"model": "gpt-4o-2024-05-13",
6+
"provider": "openai",
7+
"temperature": 0,
8+
"instructions": "To complete the task 'AddSixToNumber', follow these steps: 1. Take an input object that contains a 'number' field. 2. Add 6 to the value of the 'number' field. 3. Return an output object that contains a 'result' field with the computed value. Ensure the input and output objects conform to their respective schemas.",
9+
"max_tokens": null,
10+
"runner_name": "WorkflowAI",
11+
"runner_version": "v0.1.0",
12+
"few_shot": null,
13+
"template_name": "v1",
14+
"task_variant_id": "216123bda0159257f03ed2723f59731f"
15+
},
16+
"tags": [
17+
"model=gpt-4o-2024-05-13",
18+
"provider=openai",
19+
"temperature=0",
20+
"template_name=v1"
21+
],
22+
"aliases": [
23+
"environment=dev"
24+
],
25+
"is_external": null
26+
}

workflowai/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22

3-
from workflowai.core import client
3+
from workflowai.core.client import Client as Client
44
from workflowai.core.domain.cache_usage import CacheUsage as CacheUsage
55
from workflowai.core.domain.errors import NotFoundError as NotFoundError
66
from workflowai.core.domain.llm_completion import LLMCompletion as LLMCompletion
@@ -14,7 +14,7 @@
1414
)
1515

1616

17-
def start(url: Optional[str] = None, api_key: Optional[str] = None) -> "client.Client":
17+
def start(url: Optional[str] = None, api_key: Optional[str] = None) -> Client:
1818
"""Create a new workflowai client
1919
2020
Args:

0 commit comments

Comments
 (0)