44import pytest
55
66from agent_memory_server .config import Settings
7- from agent_memory_server .long_term_memory import (
8- promote_working_memory_to_long_term ,
9- )
107from agent_memory_server .models import (
118 MemoryMessage ,
129 MemoryRecordResult ,
@@ -509,11 +506,8 @@ async def test_working_memory_reconstruction_from_long_term(
509506
510507 @pytest .mark .requires_api_keys
511508 @pytest .mark .asyncio
512- async def test_put_memory_stores_messages_in_long_term_memory (
513- self , client_with_mock_background_tasks , mock_background_tasks
514- ):
509+ async def test_put_memory_stores_messages_in_long_term_memory (self , client ):
515510 """Test the put_memory endpoint"""
516- client = client_with_mock_background_tasks
517511 payload = {
518512 "messages" : [
519513 {"role" : "user" , "content" : "Hello" },
@@ -526,7 +520,13 @@ async def test_put_memory_stores_messages_in_long_term_memory(
526520 }
527521 mock_settings = Settings (long_term_memory = True )
528522
529- with patch ("agent_memory_server.api.settings" , mock_settings ):
523+ # Mock the promote function to verify it's called
524+ with (
525+ patch ("agent_memory_server.api.settings" , mock_settings ),
526+ patch (
527+ "agent_memory_server.api.long_term_memory.promote_working_memory_to_long_term"
528+ ) as mock_promote ,
529+ ):
530530 response = await client .put ("/v1/working-memory/test-session" , json = payload )
531531
532532 assert response .status_code == 200
@@ -537,22 +537,15 @@ async def test_put_memory_stores_messages_in_long_term_memory(
537537 assert "context" in data
538538 assert data ["context" ] == "Previous context"
539539
540- # Check that background tasks were called
541- assert mock_background_tasks .add_task .call_count == 1
542-
543- # Check that the last call was for long-term memory promotion
544- assert (
545- mock_background_tasks .add_task .call_args_list [- 1 ][0 ][0 ]
546- == promote_working_memory_to_long_term
547- )
540+ # Check that the promotion function was called as a background task
541+ # In --no-worker mode, it runs inline, so it should have been called
542+ assert mock_promote .call_count == 1
543+ assert mock_promote .call_args [1 ]["session_id" ] == "test-session"
548544
549545 @pytest .mark .requires_api_keys
550546 @pytest .mark .asyncio
551- async def test_put_memory_with_structured_memories_triggers_promotion (
552- self , client_with_mock_background_tasks , mock_background_tasks
553- ):
547+ async def test_put_memory_with_structured_memories_triggers_promotion (self , client ):
554548 """Test that structured memories trigger background promotion task"""
555- client = client_with_mock_background_tasks
556549 payload = {
557550 "messages" : [],
558551 "memories" : [
@@ -569,7 +562,13 @@ async def test_put_memory_with_structured_memories_triggers_promotion(
569562 }
570563 mock_settings = Settings (long_term_memory = True )
571564
572- with patch ("agent_memory_server.api.settings" , mock_settings ):
565+ # Mock the promote function to verify it's called
566+ with (
567+ patch ("agent_memory_server.api.settings" , mock_settings ),
568+ patch (
569+ "agent_memory_server.api.long_term_memory.promote_working_memory_to_long_term"
570+ ) as mock_promote ,
571+ ):
573572 response = await client .put ("/v1/working-memory/test-session" , json = payload )
574573
575574 assert response .status_code == 200
@@ -579,20 +578,11 @@ async def test_put_memory_with_structured_memories_triggers_promotion(
579578 assert len (data ["memories" ]) == 1
580579 assert data ["memories" ][0 ]["text" ] == "User prefers dark mode"
581580
582- # Check that promotion background task was called
583- assert mock_background_tasks .add_task .call_count == 1
584-
585- # Check that it was the promotion task, not indexing
586- assert (
587- mock_background_tasks .add_task .call_args_list [0 ][0 ][0 ]
588- == promote_working_memory_to_long_term
589- )
590-
591- # Check the arguments passed to the promotion task
592- task_call = mock_background_tasks .add_task .call_args_list [0 ]
593- task_kwargs = task_call [1 ]
594- assert task_kwargs ["session_id" ] == "test-session"
595- assert task_kwargs ["namespace" ] == "test-namespace"
581+ # Check that the promotion function was called as a background task
582+ # In --no-worker mode, it runs inline, so it should have been called
583+ assert mock_promote .call_count == 1
584+ assert mock_promote .call_args [1 ]["session_id" ] == "test-session"
585+ assert mock_promote .call_args [1 ]["namespace" ] == "test-namespace"
596586
597587 @pytest .mark .requires_api_keys
598588 @pytest .mark .asyncio
0 commit comments