fix(paths): structurally resolve home dir to prevent Windows path bugs (#12125)

* fix(paths): structurally resolve home dir to prevent Windows path bugs

Extract resolveRawHomeDir as a private function and gate the public
resolveEffectiveHomeDir through a single path.resolve() exit point.
This makes it structurally impossible for unresolved paths (missing
drive letter on Windows) to escape the function, regardless of how
many return paths exist in the raw lookup logic.

Simplify resolveRequiredHomeDir to only resolve the process.cwd()
fallback, since resolveEffectiveHomeDir now returns resolved values.

Fix shortenMeta in tool-meta.ts: the colon-based split for file:line
patterns (e.g. file.txt:12) conflicts with Windows drive letters
(C:\...) because indexOf(":") matches the drive colon first.
shortenHomeInString already handles file:line patterns correctly via
split/join, so the colon split was both unnecessary and harmful.

Update test assertions across all affected files to use path.resolve()
in expected values and input strings so they match the now-correct
resolved output on both Unix and Windows.

Fixes #12119

* fix(changelog): add paths Windows fix entry (#12125)

---------

Co-authored-by: Sebastian <19554889+sebslight@users.noreply.github.com>
This commit is contained in:
Marcus Castro
2026-02-08 22:06:29 -03:00
committed by GitHub
parent 0244d521a1
commit 456bd58740
12 changed files with 94 additions and 63 deletions

View File

@@ -1,3 +1,4 @@
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
afterEach(() => {
@@ -13,6 +14,8 @@ describe("DEFAULT_AGENT_WORKSPACE_DIR", () => {
vi.resetModules();
const mod = await import("./workspace.js");
expect(mod.DEFAULT_AGENT_WORKSPACE_DIR).toBe("/srv/openclaw-home/.openclaw/workspace");
expect(mod.DEFAULT_AGENT_WORKSPACE_DIR).toBe(
path.join(path.resolve("/srv/openclaw-home"), ".openclaw", "workspace"),
);
});
});