Skip to content

fix: Windows path handling - replace hardcoded forward slashes with Node.js path module - #2

Merged
tickernelz merged 2 commits into
tickernelz:mainfrom
cacaview:fix/windows-path-handling
Jan 15, 2026
Merged

tickernelz merged 2 commits into
tickernelz:mainfrom
cacaview:fix/windows-path-handling

Conversation

@cacaview

Copy link
Copy Markdown

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

  1. src/services/embedding.ts

    • Changed from: CONFIG.storagePath + "/.cache"
    • Changed to: join(CONFIG.storagePath, ".cache")
    • Uses path.join() for cross-platform path construction
  2. src/services/sqlite/connection-manager.ts

    • Changed from: dbPath.substring(0, dbPath.lastIndexOf("/"))
    • Changed to: dirname(dbPath)
    • Uses path.dirname() to extract directory path correctly on all platforms
  3. src/services/tags.ts

    • Changed from: directory.split("/")
    • Changed to: normalize(directory).split(sep)
    • Uses path.normalize() and path.sep to handle both Windows and Unix paths
  4. src/web/app.js

    • Added normalization: memory.projectPath.replace(/\/g, "/")
    • Ensures Windows backslashes are handled before splitting paths

Tests Added

  • tests/windows-path.test.ts: Comprehensive test suite covering:
    • Unix-style paths (/home/user/projects/my-project)
    • Windows-style paths (C:\Users\user\projects\my-project)
    • Mixed separators
    • Relative paths
    • Edge cases

Testing

All tests pass (13 tests total):

  • Existing tests: ✓ All pass
  • New Windows path tests: ✓ All pass

Tested scenarios:

$ bun test
bun test v1.3.5 (1e86cebd)
 13 pass
 0 fail
 15 expect() calls
Ran 13 tests across 1 file. [53.00ms]

Impact

This fix resolves the following Windows-specific issues:

  • Cache directory creation failures
  • Database path extraction errors
  • Project name extraction from Windows paths
  • Web UI display issues with Windows file paths

Breaking Changes

None. This is a pure bug fix that maintains backward compatibility with Unix systems.

…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.
Copilot AI review requested due to automatic review settings January 15, 2026 12:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 with path.join() for cache directory construction
  • Replaced string manipulation for directory extraction with path.dirname()
  • Updated project name extraction to use path.normalize() and path.sep for 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.

Comment thread tests/windows-path.test.ts Outdated
import { getProjectName } from "../src/services/tags.js";
import { dirname } from "node:path";
import { join } from "node:path";
import * as fs from "node:fs";

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

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

The fs module is imported but never used in the test file. Consider removing this unused import.

Suggested change
import * as fs from "node:fs";

Copilot uses AI. Check for mistakes.
Comment thread src/web/app.js Outdated
: "";

let displayInfo = memory.displayName || memory.id;
let displayInfo = memory.displayName || memory.id;

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
let displayInfo = memory.displayName || memory.id;
let displayInfo = memory.displayName || memory.id;

Copilot uses AI. Check for mistakes.
}

getConnection(dbPath: string): Database {
getConnection(dbPath: string): Database {

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
getConnection(dbPath: string): Database {
getConnection(dbPath: string): Database {

Copilot uses AI. Check for mistakes.
- 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants