Open History to see the last commit
1import { homedir } from "node:os";
2import { join } from "node:path";
3import { describe, expect, it } from "vitest";
4
5import { expandHomePath } from "./pathExpansion.ts";
6
7describe("expandHomePath", () => {
8 it("returns an empty string unchanged", () => {
9 expect(expandHomePath("")).toBe("");
10 });
11
12 it("returns paths without a leading tilde unchanged", () => {
13 expect(expandHomePath("/absolute/path")).toBe("/absolute/path");
14 expect(expandHomePath("relative/path")).toBe("relative/path");
15 expect(expandHomePath("some~weird~path")).toBe("some~weird~path");
16 });
17
18 it("expands a lone tilde to the home directory", () => {
19 expect(expandHomePath("~")).toBe(homedir());
20 });
21
22 it("expands ~/ to a subpath of the home directory", () => {
23 expect(expandHomePath("~/.codex-work")).toBe(join(homedir(), ".codex-work"));
24 });
25
26 it("expands a Windows-style ~\\ prefix", () => {
27 expect(expandHomePath("~\\.codex")).toBe(join(homedir(), ".codex"));
28 });
29
30 it("does not expand ~user paths", () => {
31 expect(expandHomePath("~alice/foo")).toBe("~alice/foo");
32 });
33});