fix: agent create test + stage publish api (#6063)

* base

* fix

---------

Co-authored-by: Letta Bot <noreply@letta.com>
This commit is contained in:
jnjpng
2025-11-07 16:31:08 -08:00
committed by Caren Thomas
parent 9534ee23be
commit 5797b4162e
2 changed files with 23 additions and 78 deletions

View File

@@ -1,11 +1,28 @@
from conftest import create_test_module
AGENTS_CREATE_PARAMS = [
("caren_agent", {"name": "caren", "model": "openai/gpt-4o-mini", "embedding": "openai/text-embedding-3-small"}, {}, None),
(
"caren_agent",
{"name": "caren", "model": "openai/gpt-4o-mini", "embedding": "openai/text-embedding-3-small"},
{
# Verify model_settings is populated with config values
# Note: The 'model' field itself is separate from model_settings
"model_settings": {"max_output_tokens": 4096, "parallel_tool_calls": False}
},
None,
),
]
AGENTS_MODIFY_PARAMS = [
("caren_agent", {"name": "caren_updated"}, {}, None),
(
"caren_agent",
{"name": "caren_updated"},
{
# After modifying just the name, model_settings should still be present
"model_settings": {"max_output_tokens": 4096, "parallel_tool_calls": False}
},
None,
),
]
AGENTS_LIST_PARAMS = [

View File

@@ -136,14 +136,7 @@ def create_test_module(
expected_values = processed_params | processed_extra_expected
for key, value in expected_values.items():
if hasattr(item, key):
actual = getattr(item, key)
# Special handling for transformed fields (model, embedding)
if key in {"model", "embedding"}:
assert verify_model_or_embedding_field(actual, value), (
f"Field '{key}' mismatch: expected '{value}', got '{custom_model_dump(actual)}'"
)
else:
assert custom_model_dump(actual) == value
assert custom_model_dump(getattr(item, key)) == value
@pytest.mark.order(1)
def test_retrieve(handler):
@@ -178,14 +171,7 @@ def create_test_module(
expected_values = params | extra_expected_values
for key, value in expected_values.items():
if hasattr(item, key):
actual = getattr(item, key)
# Special handling for transformed fields (model, embedding)
if key in {"model", "embedding"}:
assert verify_model_or_embedding_field(actual, value), (
f"Field '{key}' mismatch: expected '{value}', got '{custom_model_dump(actual)}'"
)
else:
assert custom_model_dump(actual) == value
assert custom_model_dump(getattr(item, key)) == value
@pytest.mark.order(3)
def test_modify(handler, caren_agent, name, params, extra_expected_values, expected_error):
@@ -212,14 +198,7 @@ def create_test_module(
expected_values = processed_params | processed_extra_expected
for key, value in expected_values.items():
if hasattr(item, key):
actual = getattr(item, key)
# Special handling for transformed fields (model, embedding)
if key in {"model", "embedding"}:
assert verify_model_or_embedding_field(actual, value), (
f"Field '{key}' mismatch: expected '{value}', got '{custom_model_dump(actual)}'"
)
else:
assert custom_model_dump(actual) == value
assert custom_model_dump(getattr(item, key)) == value
# Verify via retrieve as well
retrieve_kwargs = {id_param_name: item.id}
@@ -228,14 +207,7 @@ def create_test_module(
expected_values = processed_params | processed_extra_expected
for key, value in expected_values.items():
if hasattr(retrieved_item, key):
actual = getattr(retrieved_item, key)
# Special handling for transformed fields (model, embedding)
if key in {"model", "embedding"}:
assert verify_model_or_embedding_field(actual, value), (
f"Field '{key}' mismatch: expected '{value}', got '{custom_model_dump(actual)}'"
)
else:
assert custom_model_dump(actual) == value
assert custom_model_dump(getattr(retrieved_item, key)) == value
@pytest.mark.order(4)
def test_list(handler, query_params, count):
@@ -304,50 +276,6 @@ def custom_model_dump(model):
return model.model_dump()
def verify_model_or_embedding_field(actual_value, expected_value):
"""
Verify that model or embedding fields match expected values.
These fields are transformed by the API:
- Input: "openai/gpt-4o-mini" (string)
- Output: {'model': 'gpt-4o-mini', 'max_output_tokens': 4096} (dict)
Note: Some fields like 'embedding' may return None in the new API response format,
which is acceptable and should not fail the test.
Args:
actual_value: The actual value from the API (dict, object, or None)
expected_value: The expected value from test params (string)
Returns:
True if values match or actual is None, False otherwise
"""
# If actual value is None, accept it (new API format may use None for some fields)
if actual_value is None:
return True
if not isinstance(expected_value, str):
# If expected value is not a string, do direct comparison
return custom_model_dump(actual_value) == expected_value
# Convert actual value to dict if it's an object
if hasattr(actual_value, "model_dump"):
actual_dict = actual_value.model_dump()
elif isinstance(actual_value, dict):
actual_dict = actual_value
else:
return False
# Extract model name from expected string (format: "provider/model-name" or "model-name")
expected_model_name = expected_value.split("/")[-1] if "/" in expected_value else expected_value
# Check if the model name matches
if "model" in actual_dict:
return actual_dict["model"] == expected_model_name
return False
def add_fixture_params(value, caren_agent):
"""
Replaces string values containing '.id' with their mapped values.