Skip to content

Commit 18aa06f

Browse files
committed
Update test cases for thread_cache_test and sink tests
1 parent 1344621 commit 18aa06f

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

aikido_zen/sinks/tests/openai_test.py

Whitespace-only changes.

aikido_zen/thread/thread_cache_test.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,19 @@ def test_renew_called_with_correct_args(mock_get_comms, thread_cache: ThreadCach
243243
thread_cache.stats.on_detected_attack(blocked=False, operation="op2")
244244
thread_cache.routes.initialize_route({"method": "GET", "route": "/test"})
245245
thread_cache.routes.increment_route({"method": "GET", "route": "/test"})
246+
thread_cache.ai_stats.on_ai_call("openai", "gpt-4o", 6427, 200)
247+
thread_cache.ai_stats.on_ai_call("openai", "gpt-4o2", 424, 235)
248+
thread_cache.ai_stats.on_ai_call("openai", "gpt-4o2", 232, 932)
249+
thread_cache.ai_stats.on_ai_call("openai", "gpt-4o3", 8223, 173)
246250

247251
# Call renew
248252
with patch(
249253
"aikido_zen.helpers.get_current_unixtime_ms.get_unixtime_ms", return_value=-1
250254
):
251255
thread_cache.renew()
252256

257+
assert thread_cache.ai_stats.empty()
258+
253259
# Assert that send_data_to_bg_process was called with the correct arguments
254260
mock_comms.send_data_to_bg_process.assert_called_once_with(
255261
action="SYNC_DATA",
@@ -284,6 +290,26 @@ def test_renew_called_with_correct_args(mock_get_comms, thread_cache: ThreadCach
284290
},
285291
},
286292
},
293+
"ai_stats": [
294+
{
295+
"provider": "openai",
296+
"model": "gpt-4o",
297+
"calls": 1,
298+
"tokens": {"input": 6427, "output": 200, "total": 6627},
299+
},
300+
{
301+
"provider": "openai",
302+
"model": "gpt-4o2",
303+
"calls": 2,
304+
"tokens": {"input": 656, "output": 1167, "total": 1823},
305+
},
306+
{
307+
"provider": "openai",
308+
"model": "gpt-4o3",
309+
"calls": 1,
310+
"tokens": {"input": 8223, "output": 173, "total": 8396},
311+
},
312+
],
287313
"middleware_installed": False,
288314
"hostnames": [],
289315
"users": [],
@@ -331,6 +357,7 @@ def test_sync_data_for_users(mock_get_comms, thread_cache: ThreadCache):
331357
},
332358
"middleware_installed": False,
333359
"hostnames": [],
360+
"ai_stats": [],
334361
"users": [
335362
{
336363
"id": "123",
@@ -382,6 +409,7 @@ def test_renew_called_with_empty_routes(mock_get_comms, thread_cache: ThreadCach
382409
"middleware_installed": False,
383410
"hostnames": [],
384411
"users": [],
412+
"ai_stats": [],
385413
},
386414
receive=True,
387415
)
@@ -420,6 +448,7 @@ def test_renew_called_with_no_requests(mock_get_comms, thread_cache: ThreadCache
420448
"middleware_installed": False,
421449
"hostnames": [],
422450
"users": [],
451+
"ai_stats": [],
423452
},
424453
receive=True,
425454
)

0 commit comments

Comments
 (0)