Skip to content

Use path.resolve() instead of path.normalize() for path comparisons on Windows #1181

@karthiknadig

Description

@karthiknadig

Problem

Per project learnings documented in .github/instructions/generic.instructions.md:

path.normalize() vs path.resolve(): On Windows, path.normalize('\test') keeps it as \test, but path.resolve('\test') adds the current drive → C:\test. When comparing paths, use path.resolve() on BOTH sides or they won't match.

Multiple manager implementations use path.normalize() for path comparisons, which can cause matching failures on Windows.

Affected Code

pyenvManager.ts L259:

private findEnvironmentByPath(fsPath: string): PythonEnvironment | undefined {
    const normalized = path.normalize(fsPath);
    return this.collection.find((e) => {
        const n = path.normalize(e.environmentPath.fsPath);
        return n === normalized || path.dirname(n) === normalized || path.dirname(path.dirname(n)) === normalized;
    });
}

poetryManager.ts L244:

private findEnvironmentByPath(fsPath: string): PythonEnvironment | undefined {
    const normalized = path.normalize(fsPath);
    return this.collection.find((e) => {
        const n = path.normalize(e.environmentPath.fsPath);
        return n === normalized || path.dirname(n) === normalized || path.dirname(path.dirname(n)) === normalized;
    });
}

Expected Behavior

Path comparisons should use path.resolve() on both sides to ensure drive letters are properly added on Windows.

Suggested Fix

private findEnvironmentByPath(fsPath: string): PythonEnvironment | undefined {
    const normalized = path.resolve(fsPath);
    return this.collection.find((e) => {
        const n = path.resolve(e.environmentPath.fsPath);
        return n === normalized || path.dirname(n) === normalized || path.dirname(path.dirname(n)) === normalized;
    });
}

Affected Files

  • src/managers/pyenv/pyenvManager.ts
  • src/managers/poetry/poetryManager.ts
  • Potentially other files using path.normalize() for path equality checks

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugneeds PR

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions