Skip to content

Commit 6517e98

Browse files
groksrcclaude
andauthored
fix: Use platform-native path separators in config.json (#429)
Signed-off-by: Drew Cain <groksrc@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1af0539 commit 6517e98

File tree

5 files changed

+160
-64
lines changed

5 files changed

+160
-64
lines changed

src/basic_memory/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class BasicMemoryConfig(BaseSettings):
6363

6464
projects: Dict[str, str] = Field(
6565
default_factory=lambda: {
66-
"main": Path(os.getenv("BASIC_MEMORY_HOME", Path.home() / "basic-memory")).as_posix()
66+
"main": str(Path(os.getenv("BASIC_MEMORY_HOME", Path.home() / "basic-memory")))
6767
}
6868
if os.getenv("BASIC_MEMORY_HOME")
6969
else {},
@@ -196,9 +196,9 @@ def model_post_init(self, __context: Any) -> None:
196196
"""Ensure configuration is valid after initialization."""
197197
# Ensure at least one project exists; if none exist then create main
198198
if not self.projects: # pragma: no cover
199-
self.projects["main"] = (
199+
self.projects["main"] = str(
200200
Path(os.getenv("BASIC_MEMORY_HOME", Path.home() / "basic-memory"))
201-
).as_posix()
201+
)
202202

203203
# Ensure default project is valid (i.e. points to an existing project)
204204
if self.default_project not in self.projects: # pragma: no cover
@@ -361,7 +361,7 @@ def add_project(self, name: str, path: str) -> ProjectConfig:
361361

362362
# Load config, modify it, and save it
363363
config = self.load_config()
364-
config.projects[name] = project_path.as_posix()
364+
config.projects[name] = str(project_path)
365365
self.save_config(config)
366366
return ProjectConfig(name=name, home=project_path)
367367

tests/api/test_project_router.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,20 @@ async def test_update_project_path_endpoint(test_config, client, project_service
219219
test_project_name = "test-update-project"
220220
with tempfile.TemporaryDirectory() as temp_dir:
221221
test_root = Path(temp_dir)
222-
old_path = (test_root / "old-location").as_posix()
223-
new_path = (test_root / "new-location").as_posix()
222+
old_path = test_root / "old-location"
223+
new_path = test_root / "new-location"
224224

225-
await project_service.add_project(test_project_name, old_path)
225+
await project_service.add_project(test_project_name, str(old_path))
226226

227227
try:
228228
# Verify initial state
229229
project = await project_service.get_project(test_project_name)
230230
assert project is not None
231-
assert project.path == old_path
231+
assert Path(project.path) == old_path
232232

233233
# Update the project path
234234
response = await client.patch(
235-
f"{project_url}/project/{test_project_name}", json={"path": new_path}
235+
f"{project_url}/project/{test_project_name}", json={"path": str(new_path)}
236236
)
237237

238238
# Verify response
@@ -248,16 +248,16 @@ async def test_update_project_path_endpoint(test_config, client, project_service
248248

249249
# Check old project data
250250
assert data["old_project"]["name"] == test_project_name
251-
assert data["old_project"]["path"] == old_path
251+
assert Path(data["old_project"]["path"]) == old_path
252252

253253
# Check new project data
254254
assert data["new_project"]["name"] == test_project_name
255-
assert data["new_project"]["path"] == new_path
255+
assert Path(data["new_project"]["path"]) == new_path
256256

257257
# Verify project was actually updated in database
258258
updated_project = await project_service.get_project(test_project_name)
259259
assert updated_project is not None
260-
assert updated_project.path == new_path
260+
assert Path(updated_project.path) == new_path
261261

262262
finally:
263263
# Clean up

tests/services/test_project_service.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ async def test_project_operations_sync_methods(
7777
test_project_name = f"test-project-{os.urandom(4).hex()}"
7878
with tempfile.TemporaryDirectory() as temp_dir:
7979
test_root = Path(temp_dir)
80-
test_project_path = (test_root / "test-project").as_posix()
80+
test_project_path = test_root / "test-project"
8181

8282
# Make sure the test directory exists
83-
os.makedirs(test_project_path, exist_ok=True)
83+
test_project_path.mkdir(parents=True, exist_ok=True)
8484

8585
try:
8686
# Test adding a project (using ConfigManager directly)
87-
config_manager.add_project(test_project_name, test_project_path)
87+
config_manager.add_project(test_project_name, str(test_project_path))
8888

8989
# Verify it was added
9090
assert test_project_name in project_service.projects
91-
assert project_service.projects[test_project_name] == test_project_path
91+
assert Path(project_service.projects[test_project_name]) == test_project_path
9292

9393
# Test setting as default
9494
original_default = project_service.default_project
@@ -173,24 +173,24 @@ async def test_add_project_async(project_service: ProjectService):
173173
test_project_name = f"test-async-project-{os.urandom(4).hex()}"
174174
with tempfile.TemporaryDirectory() as temp_dir:
175175
test_root = Path(temp_dir)
176-
test_project_path = (test_root / "test-async-project").as_posix()
176+
test_project_path = test_root / "test-async-project"
177177

178178
# Make sure the test directory exists
179-
os.makedirs(test_project_path, exist_ok=True)
179+
test_project_path.mkdir(parents=True, exist_ok=True)
180180

181181
try:
182182
# Test adding a project
183-
await project_service.add_project(test_project_name, test_project_path)
183+
await project_service.add_project(test_project_name, str(test_project_path))
184184

185185
# Verify it was added to config
186186
assert test_project_name in project_service.projects
187-
assert project_service.projects[test_project_name] == test_project_path
187+
assert Path(project_service.projects[test_project_name]) == test_project_path
188188

189189
# Verify it was added to the database
190190
project = await project_service.repository.get_by_name(test_project_name)
191191
assert project is not None
192192
assert project.name == test_project_name
193-
assert project.path == test_project_path
193+
assert Path(project.path) == test_project_path
194194

195195
finally:
196196
# Clean up
@@ -569,34 +569,34 @@ async def test_move_project(project_service: ProjectService):
569569
test_project_name = f"test-move-project-{os.urandom(4).hex()}"
570570
with tempfile.TemporaryDirectory() as temp_dir:
571571
test_root = Path(temp_dir)
572-
old_path = (test_root / "old-location").as_posix()
573-
new_path = (test_root / "new-location").as_posix()
572+
old_path = test_root / "old-location"
573+
new_path = test_root / "new-location"
574574

575575
# Create old directory
576-
os.makedirs(old_path, exist_ok=True)
576+
old_path.mkdir(parents=True, exist_ok=True)
577577

578578
try:
579579
# Add project with initial path
580-
await project_service.add_project(test_project_name, old_path)
580+
await project_service.add_project(test_project_name, str(old_path))
581581

582582
# Verify initial state
583583
assert test_project_name in project_service.projects
584-
assert project_service.projects[test_project_name] == old_path
584+
assert Path(project_service.projects[test_project_name]) == old_path
585585

586586
project = await project_service.repository.get_by_name(test_project_name)
587587
assert project is not None
588-
assert project.path == old_path
588+
assert Path(project.path) == old_path
589589

590590
# Move project to new location
591-
await project_service.move_project(test_project_name, new_path)
591+
await project_service.move_project(test_project_name, str(new_path))
592592

593593
# Verify config was updated
594-
assert project_service.projects[test_project_name] == new_path
594+
assert Path(project_service.projects[test_project_name]) == new_path
595595

596596
# Verify database was updated
597597
updated_project = await project_service.repository.get_by_name(test_project_name)
598598
assert updated_project is not None
599-
assert updated_project.path == new_path
599+
assert Path(updated_project.path) == new_path
600600

601601
# Verify new directory was created
602602
assert os.path.exists(new_path)
@@ -624,17 +624,17 @@ async def test_move_project_db_mismatch(project_service: ProjectService):
624624
test_project_name = f"test-move-mismatch-{os.urandom(4).hex()}"
625625
with tempfile.TemporaryDirectory() as temp_dir:
626626
test_root = Path(temp_dir)
627-
old_path = (test_root / "old-location").as_posix()
628-
new_path = (test_root / "new-location").as_posix()
627+
old_path = test_root / "old-location"
628+
new_path = test_root / "new-location"
629629

630630
# Create directories
631-
os.makedirs(old_path, exist_ok=True)
631+
old_path.mkdir(parents=True, exist_ok=True)
632632

633633
config_manager = project_service.config_manager
634634

635635
try:
636636
# Add project to config only (not to database)
637-
config_manager.add_project(test_project_name, old_path)
637+
config_manager.add_project(test_project_name, str(old_path))
638638

639639
# Verify it's in config but not in database
640640
assert test_project_name in project_service.projects
@@ -643,10 +643,10 @@ async def test_move_project_db_mismatch(project_service: ProjectService):
643643

644644
# Try to move project - should fail and restore config
645645
with pytest.raises(ValueError, match="not found in database"):
646-
await project_service.move_project(test_project_name, new_path)
646+
await project_service.move_project(test_project_name, str(new_path))
647647

648648
# Verify config was restored to original path
649-
assert project_service.projects[test_project_name] == old_path
649+
assert Path(project_service.projects[test_project_name]) == old_path
650650

651651
finally:
652652
# Clean up

tests/services/test_project_service_operations.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,18 @@ async def test_add_project_to_config(project_service: ProjectService, config_man
5353
test_project_name = f"config-project-{os.urandom(4).hex()}"
5454
with tempfile.TemporaryDirectory() as temp_dir:
5555
test_root = Path(temp_dir)
56-
test_path = (test_root / "config-project").as_posix()
56+
test_path = test_root / "config-project"
5757

5858
# Make sure directory exists
59-
os.makedirs(test_path, exist_ok=True)
59+
test_path.mkdir(parents=True, exist_ok=True)
6060

6161
try:
6262
# Add a project to config only (using ConfigManager directly)
63-
config_manager.add_project(test_project_name, test_path)
63+
config_manager.add_project(test_project_name, str(test_path))
6464

6565
# Verify it's in the config
6666
assert test_project_name in project_service.projects
67-
assert project_service.projects[test_project_name] == test_path
67+
assert Path(project_service.projects[test_project_name]) == test_path
6868

6969
finally:
7070
# Clean up
@@ -79,23 +79,23 @@ async def test_update_project_path(project_service: ProjectService, config_manag
7979
test_project = f"path-update-test-project-{os.urandom(4).hex()}"
8080
with tempfile.TemporaryDirectory() as temp_dir:
8181
test_root = Path(temp_dir)
82-
original_path = (test_root / "original-path").as_posix()
83-
new_path = (test_root / "new-path").as_posix()
82+
original_path = test_root / "original-path"
83+
new_path = test_root / "new-path"
8484

8585
# Make sure directories exist
86-
os.makedirs(original_path, exist_ok=True)
87-
os.makedirs(new_path, exist_ok=True)
86+
original_path.mkdir(parents=True, exist_ok=True)
87+
new_path.mkdir(parents=True, exist_ok=True)
8888

8989
try:
9090
# Add the project
91-
await project_service.add_project(test_project, original_path)
91+
await project_service.add_project(test_project, str(original_path))
9292

9393
# Mock the update_project method to avoid issues with complex DB updates
9494
with patch.object(project_service, "update_project"):
9595
# Just check if the project exists
9696
project = await project_service.repository.get_by_name(test_project)
9797
assert project is not None
98-
assert project.path == original_path
98+
assert Path(project.path) == original_path
9999

100100
# Since we mock the update_project method, we skip verifying path updates
101101

0 commit comments

Comments
 (0)