Repository navigation
fix: Windows path handling - replace hardcoded forward slashes with Node.js path module - #2
Conversation
…ode.js path module
This commit fixes Windows compatibility issues caused by hardcoded forward slash (/) path separators. The changes ensure proper path handling across both Windows and Unix-like systems.
Changes:
- src/services/embedding.ts: Use path.join() for cache directory path
- src/services/sqlite/connection-manager.ts: Use path.dirname() instead of lastIndexOf('/')
- src/services/tags.ts: Use path.sep and path.normalize() for cross-platform path handling
- src/web/app.js: Normalize Windows backslashes before splitting paths
- tests/windows-path.test.ts: Add comprehensive tests for Windows path handling
All existing tests pass (13 tests), and new tests verify correct behavior on both Windows and Unix paths.
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows compatibility issues by replacing hardcoded forward slash path separators with Node.js path module functions. The changes ensure proper cross-platform path handling on both Windows and Unix-like systems.
Changes:
- Replaced hardcoded
/path concatenation withpath.join()for cache directory construction - Replaced string manipulation for directory extraction with
path.dirname() - Updated project name extraction to use
path.normalize()andpath.sepfor cross-platform compatibility - Added path normalization in the web UI to handle Windows backslashes
- Added comprehensive test suite covering Unix, Windows, and mixed path scenarios
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/windows-path.test.ts | New comprehensive test suite covering path handling scenarios for Unix, Windows, relative paths, and mixed separators |
| src/services/embedding.ts | Replaced string concatenation with path.join() for cache directory path |
| src/services/sqlite/connection-manager.ts | Replaced substring manipulation with path.dirname() for database path extraction |
| src/services/tags.ts | Updated getProjectName() to use path.normalize() and path.sep for cross-platform path splitting |
| src/web/app.js | Added backslash-to-forward-slash normalization before splitting project paths |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { getProjectName } from "../src/services/tags.js"; | ||
| import { dirname } from "node:path"; | ||
| import { join } from "node:path"; | ||
| import * as fs from "node:fs"; |
There was a problem hiding this comment.
The fs module is imported but never used in the test file. Consider removing this unused import.
| import * as fs from "node:fs"; |
| : ""; | ||
|
|
||
| let displayInfo = memory.displayName || memory.id; | ||
| let displayInfo = memory.displayName || memory.id; |
There was a problem hiding this comment.
Indentation inconsistency detected. The let keyword should be indented with 2 spaces to match the surrounding code, not be at the start of the line.
| let displayInfo = memory.displayName || memory.id; | |
| let displayInfo = memory.displayName || memory.id; |
| } | ||
|
|
||
| getConnection(dbPath: string): Database { | ||
| getConnection(dbPath: string): Database { |
There was a problem hiding this comment.
Indentation inconsistency detected. The method definition should be indented with 2 spaces to match the class structure, not be at the start of the line.
| getConnection(dbPath: string): Database { | |
| getConnection(dbPath: string): Database { |
- Remove unused fs import from tests/windows-path.test.ts - Fix indentation in src/web/app.js (let displayInfo) - Fix indentation in connection-manager.ts (getConnection method)
Summary
This PR fixes Windows compatibility issues caused by hardcoded forward slash (
/) path separators. The changes ensure proper path handling across both Windows and Unix-like systems.Changes Made
Core Fixes
src/services/embedding.ts
CONFIG.storagePath + "/.cache"join(CONFIG.storagePath, ".cache")path.join()for cross-platform path constructionsrc/services/sqlite/connection-manager.ts
dbPath.substring(0, dbPath.lastIndexOf("/"))dirname(dbPath)path.dirname()to extract directory path correctly on all platformssrc/services/tags.ts
directory.split("/")normalize(directory).split(sep)path.normalize()andpath.septo handle both Windows and Unix pathssrc/web/app.js
memory.projectPath.replace(/\/g, "/")Tests Added
/home/user/projects/my-project)C:\Users\user\projects\my-project)Testing
All tests pass (13 tests total):
Tested scenarios:
Impact
This fix resolves the following Windows-specific issues:
Breaking Changes
None. This is a pure bug fix that maintains backward compatibility with Unix systems.