@@ -37,7 +37,7 @@ def temp_server_dir(self) -> Generator[Path, None, None]:
3737 "logs.db" : "CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY)" ,
3838 "search_config.db" : "CREATE TABLE IF NOT EXISTS config (id INTEGER PRIMARY KEY)" ,
3939 "file_content_limits.db" : "CREATE TABLE IF NOT EXISTS limits (id INTEGER PRIMARY KEY)" ,
40- "scip_audit .db" : "CREATE TABLE IF NOT EXISTS audit (id INTEGER PRIMARY KEY)" ,
40+ "groups .db" : "CREATE TABLE IF NOT EXISTS groups (id INTEGER PRIMARY KEY)" ,
4141 "payload_cache.db" : "CREATE TABLE IF NOT EXISTS cache (id INTEGER PRIMARY KEY)" ,
4242 }
4343
@@ -80,7 +80,7 @@ def test_health_service_checks_all_8_databases(self, temp_server_dir: Path):
8080 "logs.db" ,
8181 "search_config.db" ,
8282 "file_content_limits.db" ,
83- "scip_audit .db" ,
83+ "groups .db" ,
8484 "payload_cache.db" ,
8585 }
8686 actual_files = {result .file_name for result in health_results }
@@ -110,7 +110,7 @@ def test_health_service_provides_display_names(self, temp_server_dir: Path):
110110 "logs.db" : "Logs" ,
111111 "search_config.db" : "Search Config" ,
112112 "file_content_limits.db" : "File Limits" ,
113- "scip_audit .db" : "SCIP Audit " ,
113+ "groups .db" : "Groups " ,
114114 "payload_cache.db" : "Payload Cache" ,
115115 }
116116
@@ -352,7 +352,7 @@ def healthy_db_path(self) -> Generator[Path, None, None]:
352352 yield db_path
353353
354354 def test_healthy_database_tooltip_shows_only_name (self , healthy_db_path : Path ):
355- """AC2: Healthy database tooltip shows only database name."""
355+ """AC2: Healthy database tooltip shows database name and path ."""
356356 from code_indexer .server .services .database_health_service import (
357357 DatabaseHealthService ,
358358 DatabaseHealthStatus ,
@@ -364,10 +364,15 @@ def test_healthy_database_tooltip_shows_only_name(self, healthy_db_path: Path):
364364
365365 assert result .status == DatabaseHealthStatus .HEALTHY
366366 tooltip = result .get_tooltip ()
367- assert tooltip == "Main Server"
367+ # Tooltip should contain display name and path (no error info for healthy DB)
368+ assert "Main Server" in tooltip
369+ assert str (healthy_db_path ) in tooltip
370+ # Should not contain error information for healthy database
371+ assert "Connect:" not in tooltip
372+ assert "failed" not in tooltip
368373
369374 def test_unhealthy_database_tooltip_shows_failure (self , healthy_db_path : Path ):
370- """AC3: Unhealthy database tooltip shows name AND failed condition."""
375+ """AC3: Unhealthy database tooltip shows name, path, AND failed condition."""
371376 from code_indexer .server .services .database_health_service import (
372377 DatabaseHealthService ,
373378 DatabaseHealthStatus ,
@@ -380,8 +385,11 @@ def test_unhealthy_database_tooltip_shows_failure(self, healthy_db_path: Path):
380385
381386 assert result .status == DatabaseHealthStatus .ERROR
382387 tooltip = result .get_tooltip ()
388+ # Tooltip should contain display name, path, and error info
383389 assert "OAuth" in tooltip
384- assert " - " in tooltip
390+ assert str (healthy_db_path ) in tooltip
391+ # Should contain error information (check name + error message)
392+ assert "Connect:" in tooltip or "failed" in tooltip
385393
386394
387395# =============================================================================
@@ -455,3 +463,130 @@ def test_get_stats_partial_passes_user_role_to_repo_counts(self):
455463 assert (
456464 "_get_repo_counts" in source and "user_role" in source
457465 ), "get_stats_partial must pass user_role to _get_repo_counts"
466+
467+
468+ # =============================================================================
469+ # Lazy-Loaded Database Tests
470+ # =============================================================================
471+
472+
473+ class TestLazyLoadedDatabases :
474+ """Tests for graceful handling of lazy-loaded databases."""
475+
476+ def test_lazy_loaded_database_not_initialized_status (self ):
477+ """
478+ Lazy-loaded database that doesn't exist yet gets NOT_INITIALIZED status.
479+
480+ Given a lazy-loaded database file (search_config.db or file_content_limits.db)
481+ When the database file doesn't exist yet
482+ Then the health check returns NOT_INITIALIZED status instead of ERROR
483+ """
484+ from code_indexer .server .services .database_health_service import (
485+ DatabaseHealthService ,
486+ DatabaseHealthStatus ,
487+ )
488+
489+ with tempfile .TemporaryDirectory (prefix = "cidx_lazy_test_" ) as tmp :
490+ # Create non-existent path for lazy-loaded database
491+ db_path = Path (tmp ) / "search_config.db"
492+
493+ result = DatabaseHealthService .check_database_health (
494+ str (db_path ), display_name = "Search Config"
495+ )
496+
497+ assert result .status == DatabaseHealthStatus .NOT_INITIALIZED
498+ assert result .checks ["connect" ].passed is False
499+ assert (
500+ result .checks ["connect" ].error_message == "Not initialized (optional)"
501+ )
502+
503+ def test_lazy_loaded_database_initialized_is_healthy (self ):
504+ """
505+ Lazy-loaded database that exists and is healthy gets HEALTHY status.
506+
507+ Given a lazy-loaded database file (search_config.db)
508+ When the database file exists and all checks pass
509+ Then the health check returns HEALTHY status
510+ """
511+ from code_indexer .server .services .database_health_service import (
512+ DatabaseHealthService ,
513+ DatabaseHealthStatus ,
514+ )
515+
516+ with tempfile .TemporaryDirectory (prefix = "cidx_lazy_test_" ) as tmp :
517+ # Create lazy-loaded database
518+ db_path = Path (tmp ) / "search_config.db"
519+ with sqlite3 .connect (str (db_path )) as conn :
520+ conn .execute ("CREATE TABLE config (id INTEGER PRIMARY KEY)" )
521+ conn .commit ()
522+
523+ result = DatabaseHealthService .check_database_health (
524+ str (db_path ), display_name = "Search Config"
525+ )
526+
527+ assert result .status == DatabaseHealthStatus .HEALTHY
528+ assert result .checks ["connect" ].passed is True
529+
530+ def test_non_lazy_database_missing_is_error (self ):
531+ """
532+ Non-lazy-loaded database that doesn't exist gets ERROR status.
533+
534+ Given a non-lazy-loaded database (e.g., oauth.db)
535+ When the database file doesn't exist
536+ Then the health check returns ERROR status (not NOT_INITIALIZED)
537+ """
538+ from code_indexer .server .services .database_health_service import (
539+ DatabaseHealthService ,
540+ DatabaseHealthStatus ,
541+ )
542+
543+ with tempfile .TemporaryDirectory (prefix = "cidx_lazy_test_" ) as tmp :
544+ # Create non-existent path for non-lazy database
545+ db_path = Path (tmp ) / "oauth.db"
546+
547+ result = DatabaseHealthService .check_database_health (
548+ str (db_path ), display_name = "OAuth"
549+ )
550+
551+ assert result .status == DatabaseHealthStatus .ERROR
552+ assert result .checks ["connect" ].passed is False
553+ assert "file not found" in result .checks ["connect" ].error_message
554+
555+ def test_lazy_loaded_database_tooltip (self ):
556+ """
557+ Lazy-loaded database tooltip shows 'Not initialized (optional)'.
558+
559+ Given a lazy-loaded database that doesn't exist yet
560+ When get_tooltip() is called
561+ Then it shows the display name, path, and 'Not initialized (optional)'
562+ """
563+ from code_indexer .server .services .database_health_service import (
564+ DatabaseHealthService ,
565+ )
566+
567+ with tempfile .TemporaryDirectory (prefix = "cidx_lazy_test_" ) as tmp :
568+ db_path = Path (tmp ) / "file_content_limits.db"
569+
570+ result = DatabaseHealthService .check_database_health (
571+ str (db_path ), display_name = "File Limits"
572+ )
573+
574+ tooltip = result .get_tooltip ()
575+ assert "File Limits" in tooltip
576+ assert str (db_path ) in tooltip
577+ assert "Not initialized (optional)" in tooltip
578+
579+ def test_both_lazy_databases_defined (self ):
580+ """
581+ Verify both lazy-loaded databases are defined in LAZY_LOADED_DATABASES.
582+
583+ This test documents which databases are lazy-loaded and ensures
584+ they're properly configured in the constant.
585+ """
586+ from code_indexer .server .services .database_health_service import (
587+ LAZY_LOADED_DATABASES ,
588+ )
589+
590+ assert "search_config.db" in LAZY_LOADED_DATABASES
591+ assert "file_content_limits.db" in LAZY_LOADED_DATABASES
592+ assert len (LAZY_LOADED_DATABASES ) == 2
0 commit comments