Skip to content

Conversation

@groksrc
Copy link
Contributor

@groksrc groksrc commented Nov 12, 2025

Problem

Fixes #428

On Windows, the config.json file stores project paths using forward slashes (/) instead of platform-native backslashes (\). This causes issues when paths are used by Windows tools that expect backslash separators.

Example issue on Windows:

{
  "projects": {
    "main": "C:/Users/username/basic-memory"  // ❌ Wrong on Windows
  }
}

Expected on Windows:

{
  "projects": {
    "main": "C:\\Users\\username\\basic-memory"  // ✅ Correct
  }
}

Root Cause

The code used .as_posix() in three locations, which forces POSIX-style (Unix) forward slash separators regardless of platform:

  • Line 66: Default project initialization
  • Line 201: model_post_init method
  • Line 364: add_project method
# ❌ Before: Forced forward slashes
config.projects[name] = project_path.as_posix()

# ✅ After: Uses platform-native separators
config.projects[name] = str(project_path)

Solution

Replaced .as_posix() with str() to preserve platform-native path separators:

  • Windows: Uses backslashes (\)
  • Unix: Uses forward slashes (/)

Changes

  1. src/basic_memory/config.py

    • Fixed 3 locations using .as_posix()
    • Changed to use str(path) for platform-native separators
  2. tests/test_config.py

    • Added 3 new tests for platform-specific path handling
    • Tests verify correct separator usage on both Windows and Unix
    • All 27 tests pass (24 existing + 3 new)

Testing

uv run pytest tests/test_config.py -v
# 27 passed in 1.54s

Test Coverage:

  • test_project_paths_use_platform_native_separators_in_config - Verifies saved config uses correct separators
  • test_add_project_uses_platform_native_separators - Tests ConfigManager.add_project()
  • test_model_post_init_uses_platform_native_separators - Tests default project creation

Impact

This fix ensures:

  • ✅ Windows users get properly formatted paths in config.json
  • ✅ Unix systems continue to work as before
  • ✅ Paths work correctly with platform-native tools
  • ✅ No breaking changes for existing functionality

Related

groksrc and others added 3 commits November 12, 2025 10:45
- Add check_rclone_installed() helper function
- Call check before all rclone operations (bisync, sync, check, ls)
- Provide helpful error directing users to 'bm cloud setup'
- Improve Windows installation error message with detailed steps
- Add package manager installation instructions (winget, choco, scoop)

Fixes #426
- Add tests for check_rclone_installed() function
- Add tests verifying all command functions check for rclone
- Update existing tests to mock is_rclone_installed
- All 28 tests pass with 99% coverage for rclone_commands.py

New tests:
- test_check_rclone_installed_success
- test_check_rclone_installed_not_found
- test_project_sync_checks_rclone_installed
- test_project_bisync_checks_rclone_installed
- test_project_check_checks_rclone_installed
- test_project_ls_checks_rclone_installed
Fixes #428

- Replace .as_posix() with str() for platform-native separators
- Windows paths now use backslashes instead of forward slashes
- Unix paths continue to use forward slashes
- Add comprehensive tests for platform-specific path handling

Changes:
- config.py: Replace .as_posix() in 3 locations
- test_config.py: Add 3 new tests for path separator behavior

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@groksrc groksrc added the bug Something isn't working label Nov 12, 2025
Updated tests to compare Path objects instead of strings with hardcoded
forward slashes. This fixes 10 failing tests on Windows CI:

- tests/test_config.py (4 tests)
  - test_default_behavior_without_basic_memory_home
  - test_respects_basic_memory_home_environment_variable
  - test_model_post_init_respects_basic_memory_home_creates_main
  - test_basic_memory_home_with_relative_path

- tests/services/test_project_service.py (4 tests)
  - test_project_operations_sync_methods
  - test_add_project_async
  - test_move_project
  - test_move_project_db_mismatch

- tests/services/test_project_service_operations.py (1 test)
  - test_add_project_to_config

- tests/api/test_project_router.py (1 test)
  - test_update_project_path_endpoint

Changed:
- Removed .as_posix() calls when creating test paths
- Use Path() objects for comparison instead of string equality
- Updated mkdir/os.makedirs calls to use Path.mkdir()

This ensures tests work correctly with platform-native separators
(backslashes on Windows, forward slashes on Unix).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Drew Cain <[email protected]>
@groksrc groksrc force-pushed the fix/windows-config-path-separators branch from fbff5e2 to 5bb6715 Compare November 12, 2025 19:19
…parison

This test was failing on Windows CI because it was comparing string paths
directly. After the config.py fix to use platform-native path separators,
Windows correctly returns backslashes but the test expected forward slashes.

Changed to compare Path objects which handles path separator differences
correctly across platforms.

Signed-off-by: Drew Cain <[email protected]>
@groksrc groksrc requested a review from phernandez November 12, 2025 20:16
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")))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still using a forward slash between Path.home() and "basic-memory"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you use / between Path objects (or between a Path and a string), it creates a new path by joining them together. So Path.home() / "basic-memory" is equivalent to joining the user's home directory with the "basic-memory" subdirectory.

This is syntactic sugar that pathlib provides to make path construction more readable. It's roughly equivalent to:
pythonPath.home().joinpath("basic-memory")

@groksrc groksrc merged commit 6517e98 into main Nov 13, 2025
23 checks passed
@groksrc groksrc deleted the fix/windows-config-path-separators branch November 13, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: config.json writes paths with forward slashes instead of backslashes

3 participants