@@ -638,6 +638,119 @@ def test_set_active_profile_updates_last_used(self, mock_settings) -> None:
638638 assert updated_store is not None
639639 assert updated_store .profiles ["profile-1" ].last_used is not None
640640
641+
642+ class TestDesktopDefaultProfile :
643+ """Tests for Desktop app default profile detection."""
644+
645+ def test_get_all_profiles_with_desktop_default (self , mock_settings ) -> None :
646+ """Test that virtual default is not included when Desktop default exists."""
647+ # Create a Desktop-created default profile
648+ desktop_default = AuthProfile (
649+ id = "random-desktop-id" ,
650+ name = "Desktop Default" ,
651+ email = "admin@localhost" ,
652+ apiUrl = f"http://{ mock_settings .host } :{ mock_settings .port } " ,
653+ isActive = True ,
654+ createdAt = datetime .now (),
655+ metadata = ProfileMetadata (
656+ description = "Desktop default profile" ,
657+ environment = "local" ,
658+ is_internal = True ,
659+ ),
660+ )
661+
662+ store = ProfileStore (
663+ profiles = {"random-desktop-id" : desktop_default },
664+ activeProfileId = "random-desktop-id" ,
665+ )
666+ save_profile_store (store )
667+
668+ profiles = get_all_profiles ()
669+
670+ # Should only have the Desktop default, not the virtual default
671+ assert len (profiles ) == 1
672+ assert profiles [0 ].id == "random-desktop-id"
673+ assert profiles [0 ].metadata .is_internal is True
674+ assert not any (p .id == DEFAULT_PROFILE_ID for p in profiles )
675+
676+ def test_get_all_profiles_without_desktop_default (self , mock_settings ) -> None :
677+ """Test that virtual default is included when no Desktop default exists."""
678+ # Create a non-default profile
679+ profile = AuthProfile (
680+ id = "profile-1" ,
681+ name = "Custom Profile" ,
682+ email = "user@example.com" ,
683+ apiUrl = "https://api.example.com" ,
684+ isActive = True ,
685+ createdAt = datetime .now (),
686+ )
687+
688+ store = ProfileStore (
689+ profiles = {"profile-1" : profile },
690+ activeProfileId = "profile-1" ,
691+ )
692+ save_profile_store (store )
693+
694+ profiles = get_all_profiles ()
695+
696+ # Should have both the custom profile and virtual default
697+ assert len (profiles ) == 2
698+ assert any (p .id == "profile-1" for p in profiles )
699+ assert any (p .id == DEFAULT_PROFILE_ID for p in profiles )
700+
701+ def test_get_active_profile_with_desktop_default_inactive (self , mock_settings ) -> None :
702+ """Test that None is returned when Desktop default exists but is not active."""
703+ # Create a Desktop-created default profile that is NOT active
704+ desktop_default = AuthProfile (
705+ id = "random-desktop-id" ,
706+ name = "Desktop Default" ,
707+ email = "admin@localhost" ,
708+ apiUrl = f"http://{ mock_settings .host } :{ mock_settings .port } " ,
709+ isActive = False ,
710+ createdAt = datetime .now (),
711+ metadata = ProfileMetadata (
712+ description = "Desktop default profile" ,
713+ environment = "local" ,
714+ is_internal = True ,
715+ ),
716+ )
717+
718+ store = ProfileStore (
719+ profiles = {"random-desktop-id" : desktop_default },
720+ activeProfileId = None ,
721+ )
722+ save_profile_store (store )
723+
724+ result = get_active_profile ()
725+
726+ # Should return None because Desktop default exists (even if not active)
727+ assert result is None
728+
729+ def test_get_active_profile_without_desktop_default (self , mock_settings ) -> None :
730+ """Test that virtual default is returned when no Desktop default exists."""
731+ # Create a non-default profile that is NOT active
732+ profile = AuthProfile (
733+ id = "profile-1" ,
734+ name = "Custom Profile" ,
735+ email = "user@example.com" ,
736+ apiUrl = "https://api.example.com" ,
737+ isActive = False ,
738+ createdAt = datetime .now (),
739+ )
740+
741+ store = ProfileStore (
742+ profiles = {"profile-1" : profile },
743+ activeProfileId = None ,
744+ )
745+ save_profile_store (store )
746+
747+ result = get_active_profile ()
748+
749+ # Should return virtual default
750+ assert result is not None
751+ assert result .id == DEFAULT_PROFILE_ID
752+ assert result .name == "Local Default"
753+
641754 def test_set_active_profile_default_no_store (self , mock_settings ) -> None :
642755 """Test setting active profile to the default with no store passes"""
643756 result = set_active_profile (DEFAULT_PROFILE_ID )
0 commit comments