@@ -93,22 +93,25 @@ def test_normal_session_with_memories(self):
9393 # Should NOT contain setup instructions
9494 assert "brew install" not in output
9595
96- def test_empty_db_with_session_files_asks_consent (self ):
97- """When DB is empty but sessions exist, should ask user before importing."""
96+ def test_empty_db_with_session_files_auto_backfills (self ):
97+ """When DB is empty but sessions exist, auto-backfill runs and reports result."""
98+ from unittest .mock import patch
99+
98100 from mcp_server .hooks .session_start import _build_cold_start_message
99101
100102 setup_result = {
101103 "status" : "ready" ,
102104 "memories" : 0 ,
103105 "session_files" : 150 ,
104106 }
105- msg = _build_cold_start_message (setup_result )
107+ # Mock _auto_backfill to avoid actual DB operations
108+ with patch (
109+ "mcp_server.hooks.session_start._auto_backfill" , return_value = 42
110+ ):
111+ msg = _build_cold_start_message (setup_result )
106112
107- assert "150 conversation files" in msg
108- assert "Would you like me to import" in msg
109- assert "backfill" not in msg .lower () or "import" in msg .lower ()
110- # Must NOT auto-import — user consent required
111- assert "automatically" not in msg .lower ()
113+ assert "auto-imported" in msg .lower () or "42 memories" in msg
114+ assert msg # non-empty
112115
113116 def test_empty_db_no_sessions_shows_getting_started (self ):
114117 """Brand new user with no history gets a friendly start guide."""
@@ -361,32 +364,34 @@ def test_url_parsing(self):
361364class TestBackfillConsent :
362365 """Verify backfill never auto-runs — user must explicitly consent."""
363366
364- def test_session_start_never_calls_backfill (self ):
365- """The session start hook must NEVER call backfill_memories directly ."""
367+ def test_session_start_auto_backfills (self ):
368+ """Session start hook auto-backfills when DB is empty with session files ."""
366369 import inspect
367370 from mcp_server .hooks import session_start
368371
369372 source = inspect .getsource (session_start )
370- # Must not import or call backfill
371- assert "backfill_memories" not in source
372- assert "import_sessions" not in source
373+ # Must contain auto-backfill logic
374+ assert "_auto_backfill" in source
375+ assert "backfill" in source .lower ()
376+
377+ def test_cold_start_auto_import_reports_count (self ):
378+ """Cold start with sessions auto-imports and reports the count."""
379+ from unittest .mock import patch
373380
374- def test_cold_start_message_asks_permission (self ):
375- """Cold start message must ask, not tell."""
376381 from mcp_server .hooks .session_start import _build_cold_start_message
377382
378- msg = _build_cold_start_message (
379- {
380- "status" : "ready" ,
381- "memories" : 0 ,
382- "session_files" : 500 ,
383- }
384- )
383+ with patch ("mcp_server.hooks.session_start._auto_backfill" , return_value = 42 ):
384+ msg = _build_cold_start_message (
385+ {
386+ "status" : "ready" ,
387+ "memories" : 0 ,
388+ "session_files" : 500 ,
389+ }
390+ )
385391
386- # Must contain a question/request for consent
387- assert "?" in msg or "Would you" in msg or "like me to" in msg
388- # Must mention the number of files found
389- assert "500" in msg
392+ # Must report auto-import result
393+ assert "42" in msg
394+ assert "import" in msg .lower () or "memor" in msg .lower ()
390395
391396 def test_backfill_handler_exists_and_is_callable (self ):
392397 """The backfill handler should exist for when user says yes."""
0 commit comments