fix: fix agent test, returns new data format (#6039)
fix conftest Co-authored-by: Ari Webb <ari@letta.com>
This commit is contained in:
@@ -136,7 +136,14 @@ def create_test_module(
|
||||
expected_values = processed_params | processed_extra_expected
|
||||
for key, value in expected_values.items():
|
||||
if hasattr(item, key):
|
||||
assert custom_model_dump(getattr(item, key)) == value
|
||||
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
|
||||
|
||||
@pytest.mark.order(1)
|
||||
def test_retrieve(handler):
|
||||
@@ -171,7 +178,14 @@ def create_test_module(
|
||||
expected_values = params | extra_expected_values
|
||||
for key, value in expected_values.items():
|
||||
if hasattr(item, key):
|
||||
assert custom_model_dump(getattr(item, key)) == value
|
||||
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
|
||||
|
||||
@pytest.mark.order(3)
|
||||
def test_modify(handler, caren_agent, name, params, extra_expected_values, expected_error):
|
||||
@@ -198,7 +212,14 @@ def create_test_module(
|
||||
expected_values = processed_params | processed_extra_expected
|
||||
for key, value in expected_values.items():
|
||||
if hasattr(item, key):
|
||||
assert custom_model_dump(getattr(item, key)) == value
|
||||
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
|
||||
|
||||
# Verify via retrieve as well
|
||||
retrieve_kwargs = {id_param_name: item.id}
|
||||
@@ -207,7 +228,14 @@ def create_test_module(
|
||||
expected_values = processed_params | processed_extra_expected
|
||||
for key, value in expected_values.items():
|
||||
if hasattr(retrieved_item, key):
|
||||
assert custom_model_dump(getattr(retrieved_item, key)) == value
|
||||
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
|
||||
|
||||
@pytest.mark.order(4)
|
||||
def test_list(handler, query_params, count):
|
||||
@@ -270,10 +298,56 @@ def custom_model_dump(model):
|
||||
return model
|
||||
if isinstance(model, list):
|
||||
return [custom_model_dump(item) for item in model]
|
||||
if isinstance(model, dict):
|
||||
return {key: custom_model_dump(value) for key, value in model.items()}
|
||||
else:
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user