Compare commits

...

1 Commits

Author SHA1 Message Date
claude[bot] d5baf9544b fix: use platform-native path separators in config.json
Replace .as_posix() with str(path) to preserve platform-native
path separators in config.json. On Windows, paths now correctly
use backslashes (\) instead of forward slashes (/).

Changes:
- src/basic_memory/config.py: Updated 3 locations to use str(path)
  - Line 66: Default project initialization
  - Line 199: model_post_init method
  - Line 364: add_project method
- tests/test_config.py: Updated test assertions to match new behavior

Fixes #428

Co-authored-by: Drew Cain <groksrc@users.noreply.github.com>
2025-11-12 17:04:28 +00:00
2 changed files with 12 additions and 12 deletions
+4 -4
View File
@@ -63,7 +63,7 @@ class BasicMemoryConfig(BaseSettings):
projects: Dict[str, str] = Field(
default_factory=lambda: {
"main": Path(os.getenv("BASIC_MEMORY_HOME", Path.home() / "basic-memory")).as_posix()
"main": str(Path(os.getenv("BASIC_MEMORY_HOME", Path.home() / "basic-memory")))
}
if os.getenv("BASIC_MEMORY_HOME")
else {},
@@ -196,9 +196,9 @@ class BasicMemoryConfig(BaseSettings):
"""Ensure configuration is valid after initialization."""
# Ensure at least one project exists; if none exist then create main
if not self.projects: # pragma: no cover
self.projects["main"] = (
self.projects["main"] = str(
Path(os.getenv("BASIC_MEMORY_HOME", Path.home() / "basic-memory"))
).as_posix()
)
# Ensure default project is valid (i.e. points to an existing project)
if self.default_project not in self.projects: # pragma: no cover
@@ -361,7 +361,7 @@ class ConfigManager:
# Load config, modify it, and save it
config = self.load_config()
config.projects[name] = project_path.as_posix()
config.projects[name] = str(project_path)
self.save_config(config)
return ProjectConfig(name=name, home=project_path)
+8 -8
View File
@@ -19,12 +19,12 @@ class TestBasicMemoryConfig:
config = BasicMemoryConfig()
# Should use the default path (home/basic-memory)
expected_path = (config_home / "basic-memory").as_posix()
assert config.projects["main"] == Path(expected_path).as_posix()
expected_path = str(config_home / "basic-memory")
assert config.projects["main"] == expected_path
def test_respects_basic_memory_home_environment_variable(self, config_home, monkeypatch):
"""Test that config respects BASIC_MEMORY_HOME environment variable."""
custom_path = (config_home / "app" / "data").as_posix()
custom_path = str(config_home / "app" / "data")
monkeypatch.setenv("BASIC_MEMORY_HOME", custom_path)
config = BasicMemoryConfig()
@@ -44,7 +44,7 @@ class TestBasicMemoryConfig:
# model_post_init should have added main project with BASIC_MEMORY_HOME
assert "main" in config.projects
assert config.projects["main"] == Path(custom_path).as_posix()
assert config.projects["main"] == custom_path
def test_model_post_init_respects_basic_memory_home_sets_non_main_default(
self, config_home, monkeypatch
@@ -55,11 +55,11 @@ class TestBasicMemoryConfig:
# Create config without main project
other_path = str(config_home / "some" / "path")
config = BasicMemoryConfig(projects={"other": Path(other_path).as_posix()})
config = BasicMemoryConfig(projects={"other": other_path})
# model_post_init should not add main project with BASIC_MEMORY_HOME
assert "main" not in config.projects
assert config.projects["other"] == Path(other_path).as_posix()
assert config.projects["other"] == other_path
def test_model_post_init_fallback_without_basic_memory_home(self, config_home, monkeypatch):
"""Test that model_post_init can set a non-main default when BASIC_MEMORY_HOME is not set."""
@@ -67,12 +67,12 @@ class TestBasicMemoryConfig:
monkeypatch.delenv("BASIC_MEMORY_HOME", raising=False)
# Create config without main project
other_path = (config_home / "some" / "path").as_posix()
other_path = str(config_home / "some" / "path")
config = BasicMemoryConfig(projects={"other": other_path})
# model_post_init should not add main project, but "other" should now be the default
assert "main" not in config.projects
assert config.projects["other"] == Path(other_path).as_posix()
assert config.projects["other"] == other_path
def test_basic_memory_home_with_relative_path(self, config_home, monkeypatch):
"""Test that BASIC_MEMORY_HOME works with relative paths."""