Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Testing - Checkpoint 1 (SDK - management, routing, cli) #2382

Merged
merged 29 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7d2ad40
feat (sdk:tests): create pytest configuration
aybruhm Dec 18, 2024
f0441db
feat (sdk:tests): add fixtures for HTTP client and app setup, ensure …
aybruhm Dec 18, 2024
5637d9a
feat (sdk:tests): create variant manager test suite (in progress)
aybruhm Dec 18, 2024
56dd757
chore (sdk:tests): add bash script to run tests in sdk
aybruhm Dec 18, 2024
645a276
chore (deps): add mypy and pytest-xdist dev dependencies to agenta-cli
aybruhm Dec 19, 2024
1ab5da6
refactor (backend): add optional attribute field to AppVariantRevisio…
aybruhm Dec 19, 2024
72a876e
chore (tests): update pytest configuration
aybruhm Dec 19, 2024
8d43c12
refactor (sdk:tests): add saltiness to name generation for app from t…
aybruhm Dec 19, 2024
68e5924
refactor (sdk:tests): update marker to `variant_manager` and remove `…
aybruhm Dec 19, 2024
c125d03
feat (sdk:tests): add fixture for Deployment Manager test suites and …
aybruhm Dec 19, 2024
dc5db1b
feat (sdk:tests): add more test cases to VariantManager test suite.
aybruhm Dec 19, 2024
035c056
feat (sdk:tests): add fixture for Config Manager test suites and crea…
aybruhm Dec 19, 2024
a4ddab1
chore (backend): add variant_revision id in `app_variant_db_revisions…
aybruhm Dec 19, 2024
eec75b3
feat (sdk:tests): add fixture for SDK routing test suites and create …
aybruhm Dec 20, 2024
9f6271b
chore (sdk:tests): add markers for config_manager and sdk_routing tes…
aybruhm Dec 20, 2024
7b7d8f7
chore (deps): add uvicorn to dev dependencies in agenta-cli
aybruhm Dec 20, 2024
e741644
refactor (backend): retrieve api_key from headers properly
aybruhm Dec 20, 2024
b0a1948
refactor (sdk:tests): add command to run sdk_routing test suites
aybruhm Dec 20, 2024
e05a72a
style (backend): format backend
aybruhm Dec 20, 2024
afe804e
minor refactor (sdk:tests): rename fixture to get executable_python
aybruhm Dec 20, 2024
c862cbd
refactor (sdk:tests): update bash script to dynamically request for v…
aybruhm Dec 23, 2024
078cb64
refactor (sdk:tests): add marker for cli_testing
aybruhm Dec 23, 2024
8e8f9fa
feat (sdk:tests): add required fixtures required to run cli commands …
aybruhm Dec 23, 2024
d65f0fb
feat (sdk:tests): add assets required to run the cli tests
aybruhm Dec 23, 2024
97b1bb2
feat (sdk:tests): create TestAgentaInitCommand and TestAgentaVariantS…
aybruhm Dec 23, 2024
59829b8
Merge branch 'dev' into feature/sdk-management-checkpoint-1
aybruhm Dec 24, 2024
e492d70
refactor (sdk:tests): add and integrated fixtures for programmatic ac…
aybruhm Dec 25, 2024
9336875
refactor (sdk:tests): add test case for grumpy path --- serve variant…
aybruhm Dec 26, 2024
b633982
Merge 'dev' into feature/sdk-management-checkpoint-1 branch
aybruhm Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat (sdk:tests): add more test cases to VariantManager test suite.
  • Loading branch information
aybruhm committed Dec 19, 2024
commit dc5db1b94a6c072ed3c6140c807a15c9e4cea233
287 changes: 287 additions & 0 deletions agenta-cli/tests/management/variant/test_variant_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from tests.management.deployment.fixtures import *


@pytest.mark.usefixtures("create_app_from_template")
class TestVariantManager:
Expand Down Expand Up @@ -104,3 +106,288 @@ async def test_configs_add_invalid_data(self, http_client):

# ASSERT: Verify validation error
assert response.status_code == 422, "Expected 422 validation error"

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_commit_success(
self,
http_client,
get_variant_revisions,
get_completion_app_from_list,
):
# ARRANGE: Prepare test data
app_id = get_completion_app_from_list.get("app_id", None)
variant_revision = get_variant_revisions[0]
variant_revision_id = variant_revision.get("id", None)
variant_revision_config_name = variant_revision.get("config", {}).get(
"config_name", None
)
variant_revision_version = variant_revision.get("revision")

# ACT: Add configuration
response = await http_client.post(
"variants/configs/commit",
json={
"config": {
"params": {
"model": "gpt-4",
"top_p": 1,
"inputs": [{"name": "country"}],
"force_json": 0,
"max_tokens": 1000,
"prompt_user": "What is the capital of {country}?",
"temperature": 0.65,
"prompt_system": "You are an expert in geography.",
"presence_penalty": 0,
"frequence_penalty": 0,
},
"application_ref": {
"slug": None,
"version": None,
"id": app_id,
},
"service_ref": None,
"variant_ref": {
"slug": variant_revision_config_name,
"version": variant_revision_version,
"id": variant_revision_id,
},
"environment_ref": None,
}
},
)

# ASSERT: Verify response
assert response.status_code == 200
assert "params" and "url" in response.json()
assert "variant_lifecycle" in response.json()

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_commit_missing_data(
self, http_client, get_completion_app_from_list
):
# ARRANGE: Prepare test data
app_id = get_completion_app_from_list.get("app_id", None)

# ACT: Add configuration
response = await http_client.post(
"variants/configs/commit",
json={
"params": {},
"url": "",
"application_ref": {
"slug": "test",
"version": None,
"id": app_id,
},
},
)

# ASSERT: Verify response
assert response.status_code == 422

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_delete_success(
self, http_client, get_completion_app_from_list, list_app_variants
):
# ARRANGE: Prepare test data
app_name = get_completion_app_from_list.get("app_name", None)
app_variant = list_app_variants[0]

# ACT: Add configuration
variant_response = await http_client.post(
"variants/from-base",
json={
"base_id": app_variant.get("base_id"),
"new_variant_name": "from_pytest_for_deletion",
"new_config_name": "from_base_config",
"parameters": {},
},
)
variant_response.raise_for_status()

response = await http_client.post(
"variants/configs/delete",
json={
"variant_ref": {
"slug": "from_pytest_for_deletion",
"version": None,
"id": None,
},
"application_ref": {
"slug": app_name,
"version": None,
"id": None,
},
},
)

# ASSERT: Verify response
assert response.status_code == 200
assert 204 == response.json()

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_delete_not_found(
self, http_client, get_completion_app_from_list
):
# ARRANGE: Prepare test data
app_name = get_completion_app_from_list.get("app_name", None)

# ACT: Add configuration
response = await http_client.post(
"variants/configs/delete",
json={
"variant_ref": {
"slug": "non-existent-variant",
"version": None,
"id": None,
},
"application_ref": {
"slug": app_name,
"version": None,
"id": None,
},
},
)

# ASSERT: Verify response
assert 204 == response.json()

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_list_success(
self, http_client, get_completion_app_from_list
):
# ARRANGE: Prepare test data
app_name = get_completion_app_from_list.get("app_name", None)

# ACT: Add configuration
response = await http_client.post(
"variants/configs/list",
json={
"application_ref": {
"slug": app_name,
"version": None,
"id": None,
}
},
)

# ASSERT: Verify response
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) > 0

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_list_not_found(self, http_client):
# ACT: Add configuration
response = await http_client.post(
"variants/configs/list",
json={
"application_ref": {
"slug": "non_existent_app",
"version": None,
"id": None,
}
},
)

# ASSERT: Verify response
assert response.status_code == 200
assert [] == response.json()

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_history_by_slug_and_appid_success(
self,
http_client,
get_completion_app_from_list,
get_variant_revisions,
):
# ARRANGE: Prepare test data
app_id = get_completion_app_from_list.get("app_id", None)
variant_revision = get_variant_revisions[0]
variant_revision_config_name = variant_revision.get("config", {}).get(
"config_name", None
)

# ACT: Add configuration
response = await http_client.post(
"variants/configs/history",
json={
"application_ref": {
"slug": None,
"version": None,
"id": app_id,
},
"variant_ref": {
"slug": variant_revision_config_name,
"version": None,
"id": None,
},
},
)

# ASSERT: Verify response
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) >= 1

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_history_by_id_success(self, http_client, list_app_variants):
# ARRANGE: Prepare test data
app_variant = list_app_variants[0]

# ACT: Add configuration
response = await http_client.post(
"variants/configs/history",
json={
"variant_ref": {
"slug": None,
"version": None,
"id": app_variant.get("variant_id", None),
},
},
)

# ASSERT: Verify response
assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) > 0

@pytest.mark.asyncio
@pytest.mark.variant_manager
async def test_configs_history_not_found(self, http_client):
# ACT: Add configuration
app_not_found_response = await http_client.post(
"variants/configs/history",
json={
"variant_ref": {
"slug": "non_existent_app",
"version": None,
"id": None,
}
},
)
variant_not_found_response = await http_client.post(
"variants/configs/history",
json={
"variant_ref": {
"slug": None,
"version": None,
"id": str(uuid.uuid4()),
}
},
)

# ASSERT: Verify response
assert app_not_found_response.status_code == 200
assert variant_not_found_response.status_code == 200
assert [] == (
app_not_found_response.json() and variant_not_found_response.json()
)