55intact in ~/.basic-memory/config.json.
66
77The test verifies that the reset command now:
8- 1. Removes the SQLite database
8+ 1. Removes the SQLite database
992. Resets project configuration to default state (main project only)
10103. Recreates empty database
1111"""
2020@pytest .mark .asyncio
2121async def test_reset_config_file_behavior (config_manager ):
2222 """Test that reset command properly updates the config.json file."""
23-
23+
2424 # Step 1: Set up initial state with multiple projects in config
2525 original_projects = {
2626 "project1" : "/path/to/project1" ,
27- "project2" : "/path/to/project2" ,
28- "user-project" : "/home/user/documents"
27+ "project2" : "/path/to/project2" ,
28+ "user-project" : "/home/user/documents" ,
2929 }
3030 config_manager .config .projects = original_projects .copy ()
3131 config_manager .config .default_project = "user-project"
32-
32+
3333 # Step 2: Save the config to a temporary file to simulate the real config file
3434 with tempfile .TemporaryDirectory () as temp_dir :
3535 temp_config_file = Path (temp_dir ) / "config.json"
3636 config_manager .config_file = temp_config_file
3737 config_manager .save_config (config_manager .config )
38-
38+
3939 # Step 3: Verify the config file contains the multiple projects
4040 config_json = json .loads (temp_config_file .read_text ())
4141 assert len (config_json ["projects" ]) == 3
4242 assert config_json ["default_project" ] == "user-project"
4343 assert "project1" in config_json ["projects" ]
4444 assert "project2" in config_json ["projects" ]
4545 assert "user-project" in config_json ["projects" ]
46-
46+
4747 # Step 4: Simulate the reset command's configuration reset behavior
4848 # This is the exact fix for issue #151
4949 with patch ("pathlib.Path.home" ) as mock_home :
5050 mock_home .return_value = Path ("/home/testuser" )
51-
51+
5252 # Apply the reset logic from the reset command
5353 config_manager .config .projects = {"main" : str (Path .home () / "basic-memory" )}
5454 config_manager .config .default_project = "main"
5555 config_manager .save_config (config_manager .config )
56-
56+
5757 # Step 5: Read the config file and verify it was properly reset
5858 updated_config_json = json .loads (temp_config_file .read_text ())
59-
59+
6060 # Should now only have the main project
6161 assert len (updated_config_json ["projects" ]) == 1
6262 assert "main" in updated_config_json ["projects" ]
6363 assert updated_config_json ["projects" ]["main" ] == "/home/testuser/basic-memory"
6464 assert updated_config_json ["default_project" ] == "main"
65-
65+
6666 # All original projects should be gone from the file
6767 assert "project1" not in updated_config_json ["projects" ]
6868 assert "project2" not in updated_config_json ["projects" ]
6969 assert "user-project" not in updated_config_json ["projects" ]
70-
70+
7171 # This validates that issue #151 is fixed:
7272 # Before the fix, these projects would persist in config.json after reset
7373 # After the fix, only the default "main" project remains
7474
7575
76- @pytest .mark .asyncio
76+ @pytest .mark .asyncio
7777async def test_reset_command_source_code_validation ():
7878 """Validate that the reset command source contains the required fix."""
7979 # This test ensures the fix for issue #151 is present in the source code
80- reset_source_path = Path (__file__ ).parent .parent .parent / "src" / "basic_memory" / "cli" / "commands" / "db.py"
80+ reset_source_path = (
81+ Path (__file__ ).parent .parent .parent / "src" / "basic_memory" / "cli" / "commands" / "db.py"
82+ )
8183 reset_source = reset_source_path .read_text ()
82-
84+
8385 # Verify the key components of the fix are present
8486 required_lines = [
85- ' # Reset project configuration' ,
87+ " # Reset project configuration" ,
8688 'config_manager.config.projects = {"main": str(Path.home() / "basic-memory")}' ,
8789 'config_manager.config.default_project = "main"' ,
88- ' config_manager.save_config(config_manager.config)' ,
89- 'logger.info("Project configuration reset to default")'
90+ " config_manager.save_config(config_manager.config)" ,
91+ 'logger.info("Project configuration reset to default")' ,
9092 ]
91-
93+
9294 for line in required_lines :
9395 assert line in reset_source , f"Required fix line not found: { line } "
94-
96+
9597 # Verify the fix is in the correct location (after database deletion, before recreation)
96- lines = reset_source .split (' \n ' )
97-
98+ lines = reset_source .split (" \n " )
99+
98100 # Find key markers
99101 db_deletion_line = None
100102 config_reset_line = None
101103 db_recreation_line = None
102-
104+
103105 for i , line in enumerate (lines ):
104- if ' db_path.unlink()' in line :
106+ if " db_path.unlink()" in line :
105107 db_deletion_line = i
106- elif ' config_manager.config.projects = {' in line :
108+ elif " config_manager.config.projects = {" in line :
107109 config_reset_line = i
108- elif ' asyncio.run(db.run_migrations' in line :
110+ elif " asyncio.run(db.run_migrations" in line :
109111 db_recreation_line = i
110-
112+
111113 # Verify the order is correct
112114 assert db_deletion_line is not None , "Database deletion code not found"
113- assert config_reset_line is not None , "Config reset code not found"
115+ assert config_reset_line is not None , "Config reset code not found"
114116 assert db_recreation_line is not None , "Database recreation code not found"
115-
117+
116118 # Config reset should be after db deletion and before db recreation
117- assert db_deletion_line < config_reset_line < db_recreation_line , \
119+ assert db_deletion_line < config_reset_line < db_recreation_line , (
118120 "Config reset is not in the correct order in the reset command"
121+ )
119122
120123
121124@pytest .mark .asyncio
122125async def test_config_reset_behavior_simulation (config_manager ):
123126 """Test the specific configuration reset behavior that fixes issue #151."""
124-
127+
125128 # Step 1: Set up the problem state (multiple projects in config)
126129 original_projects = {
127130 "project1" : "/path/to/project1" ,
128131 "project2" : "/path/to/project2" ,
129- "user-project" : "/home/user/documents"
132+ "user-project" : "/home/user/documents" ,
130133 }
131134 config_manager .config .projects = original_projects .copy ()
132135 config_manager .config .default_project = "user-project"
133-
136+
134137 # Verify the problem state
135138 assert len (config_manager .config .projects ) == 3
136139 assert config_manager .config .default_project == "user-project"
137-
140+
138141 # Step 2: Apply the reset fix (simulate what reset command does)
139142 with patch ("pathlib.Path.home" ) as mock_home :
140143 mock_home .return_value = Path ("/home/testuser" )
141-
144+
142145 # This is the exact code from the reset command that fixes issue #151
143146 config_manager .config .projects = {"main" : str (Path .home () / "basic-memory" )}
144147 config_manager .config .default_project = "main"
145148 # Note: We don't call save_config in test to avoid file operations
146-
149+
147150 # Step 3: Verify the fix worked
148151 assert len (config_manager .config .projects ) == 1
149152 assert "main" in config_manager .config .projects
150153 assert config_manager .config .projects ["main" ] == "/home/testuser/basic-memory"
151154 assert config_manager .config .default_project == "main"
152-
155+
153156 # Step 4: Verify original projects are gone
154157 for project_name in original_projects :
155- assert project_name not in config_manager .config .projects
158+ assert project_name not in config_manager .config .projects
0 commit comments