@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 146 lines 7.48 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2 import {
3 isWslSharePath,
4 workspaceRelativeFilePath,
5 newProjectFolderName,
6 normalizeProjectPathForComparison,
7 normalizeProjectPathForDispatch,
8 resolvePastedPath,
9 resolveWorkspaceFilePath,
10 } from "./path.ts";
11
12 describe("path helpers", () => {
13 it("recognizes WSL shares and nothing else", () => {
14 expect(isWslSharePath("\\\\wsl.localhost\\Ubuntu\\home")).toBe(true);
15 expect(isWslSharePath("\\\\wsl$\\Ubuntu")).toBe(true);
16 expect(isWslSharePath(" //WSL.LOCALHOST/Ubuntu/home")).toBe(true);
17 expect(isWslSharePath("\\\\?\\UNC\\wsl.localhost\\Ubuntu\\repo")).toBe(true);
18 expect(isWslSharePath("\\\\.\\UNC\\wsl$\\Ubuntu\\repo")).toBe(true);
19 expect(isWslSharePath("\\\\?\\C:\\work\\repo")).toBe(false);
20 expect(isWslSharePath("\\\\wslserver\\share")).toBe(false);
21 expect(isWslSharePath("\\\\fileserver\\wsl.localhost")).toBe(false);
22 expect(isWslSharePath("C:\\work\\repo")).toBe(false);
23 });
24
25 // regression: #17923 literal colons in names are kept, not parsed as positions
26 it.each([
27 ["report:123", "/workspace", "/workspace/report:123"],
28 ["src/file", "C:\\Workspace\\", "C:\\Workspace\\src\\file"],
29 ["~/report:123", "/workspace", "~/report:123"],
30 ])("resolves literal path %s within %s", (path, root, expected) => {
31 expect(resolveWorkspaceFilePath(path, root)).toBe(expected);
32 });
33
34 it("normalizes a bare Windows drive root the same as one with a trailing separator", () => {
35 expect(normalizeProjectPathForDispatch("C:")).toBe("C:\\");
36 expect(normalizeProjectPathForComparison("C:")).toBe("c:\\");
37 expect(normalizeProjectPathForComparison("C:")).toBe(normalizeProjectPathForComparison("C:\\"));
38 expect(normalizeProjectPathForComparison("C:")).toBe(normalizeProjectPathForComparison("C:/"));
39 expect(normalizeProjectPathForDispatch("C:\\repo\\")).toBe("C:\\repo");
40 });
41
42 it("names a new project's folder from any typed name", () => {
43 expect(newProjectFolderName("Pinball Stats")).toBe("pinball-stats");
44 expect(newProjectFolderName(" Café & Crème! ")).toBe("cafe-creme");
45 expect(newProjectFolderName("Đặt tên dự án")).toBe("dat-ten-du-an");
46 expect(newProjectFolderName("Straßenbahn GROẞ")).toBe("strassenbahn-gross");
47 expect(newProjectFolderName("Łódź sklep")).toBe("lodz-sklep");
48 expect(newProjectFolderName("Øl på Þingvellir ı")).toBe("ol-pa-thingvellir-i");
49 expect(newProjectFolderName("Aʼna")).toBe("ana");
50 expect(newProjectFolderName("../../etc")).toBe("etc");
51 expect(newProjectFolderName("🎱🎱")).toBe("project");
52 expect(newProjectFolderName(`${"a".repeat(63)} b`)).toBe("a".repeat(63));
53 expect(newProjectFolderName("Con")).toBe("con-project");
54 expect(newProjectFolderName("LPT1")).toBe("lpt1-project");
55 expect(newProjectFolderName("console")).toBe("console");
56 });
57 });
58
59 describe("resolvePastedPath", () => {
60 it.each([
61 ["Finder, a space", "", "'/Users/me/Monarch Money'", "/Users/me/Monarch Money"],
62 ["Finder, an apostrophe", "", "/Users/me/Bob\\'s\\ Stuff", "/Users/me/Bob's Stuff"],
63 ["Finder, a backslash", "", "/Users/me/a\\\\\\ b", "/Users/me/a\\ b"],
64 [
65 "Finder, apostrophes around a name",
66 "",
67 "/Users/me/\\'My\\ Folder\\'",
68 "/Users/me/'My Folder'",
69 ],
70 ["Explorer, a drive", "", '"C:\\Users\\me\\My Code"', "C:\\Users\\me\\My Code"],
71 ["Explorer, a share", "", '"\\\\host\\share\\My Code"', "\\\\host\\share\\My Code"],
72 ["an apostrophe in double quotes", "", '"/Users/me/Bob\'s Stuff"', "/Users/me/Bob's Stuff"],
73 ["a shell, home-relative", "", "~/Bob\\'s\\ Stuff", "~/Bob's Stuff"],
74 ["surrounding whitespace", "", " '/Users/me/My Code'\n", "/Users/me/My Code"],
75 ["over a selection", "/Users/me/old", "'/Users/me/My Code'", "/Users/me/My Code"],
76 ["after a prefilled folder", "~/", "~/'/Users/me/My Code'", "/Users/me/My Code"],
77 ["plain, after a prefilled folder", "~/", "~//Users/me/code", "/Users/me/code"],
78 ["backslash home, after a folder", "~/", "~/~\\folder\\ child", "~/~\\folder\\ child"],
79 ["after a Windows folder", "C:\\Users\\", 'C:\\Users\\"D:\\My Code"', "D:\\My Code"],
80 ["a shell's quoted apostrophe", "", "'/Users/me/Bob'\\''s Work'", "/Users/me/Bob's Work"],
81 ["after a clone destination", "~/code/repo", "~/code/repo'/a b'", "/a b"],
82 ["over part of the box", "~/code/old", "~/code/'/a b'", "/a b"],
83 ])("reads the path copied from %s", (_source, previous, next, expected) => {
84 expect(resolvePastedPath(previous, next)).toBe(expected);
85 });
86
87 it.each([
88 ["typing a separator", "/Users/me", "/Users/me/"],
89 ["typing a separator after a folder", "~/", "~//"],
90 ["typing a trailing space", "/Users/My", "/Users/My "],
91 ["deleting", "/Users/me/", "/Users/me"],
92 ["pasting a relative folder", "~/", "~/Documents/code"],
93 ["a longer path over a selection", "/Users/me", "/Users/me/code"],
94 ["a longer path after a folder", "/Users/me/", "/Users/me/code"],
95 ["quoted text that is no path", "", "'hello world'"],
96 ["a quoted relative path", "", "'code/my app'"],
97 ["a search ending in a quoted path", "", "find '/tmp/repo'"],
98 ["a quote left open", "", "'/Users/me/My Code"],
99 ["a quote inside the quotes", "", "'/Users/me/it's here'"],
100 ["Windows separators", "", "C:\\Users\\me\\code"],
101 ["a Windows dot folder", "", "C:\\Users\\me\\.config"],
102 ["a Windows dot folder below home", "", "~/code\\.vscode"],
103 ["a share", "", "\\\\host\\share\\code"],
104 ["a backslash before a letter", "", "/Users/me/a\\b"],
105 ])("keeps %s", (_case, previous, next) => {
106 expect(resolvePastedPath(previous, next)).toBe(next);
107 });
108
109 it.each(["/Users/me/a\\ b", "~/code\\.vscode", "'/Users/me/My Code'"])(
110 "leaves %s typed one character at a time",
111 (typed) => {
112 const box = [...typed].reduce((text, char) => resolvePastedPath(text, text + char), "");
113 expect(box).toBe(typed);
114 },
115 );
116 });
117
118 describe("workspaceRelativeFilePath", () => {
119 // regression: #9309 POSIX paths compare case-sensitively, Windows paths do not
120 it.each([
121 ["/Repo/Project/src/main.ts", "/repo/project", null],
122 ["C:/USERS/mike/t3code/main.ts", "c:/users/MIKE/t3code", "main.ts"],
123 ["/repo/project-two/a.ts", "/repo/project", null],
124 // regression: #16354 a `..` that leaves the root is a host path, not a workspace path
125 ["/repo/project/../other/notes.md", "/repo/project", null],
126 ["C:\\repo\\project\\src\\..\\..\\notes.md", "C:\\repo\\project", null],
127 ["/repo/project/docs/a/../b.md", "/repo/project", "docs/a/../b.md"],
128 ["/repo/a\\b.txt", "/repo", "a\\b.txt"],
129 ["/repo/a/b.txt", "/repo", "a/b.txt"],
130 ["/repo/a\\", "/repo", "a\\"],
131 ["/repo/..\\notes.md", "/repo", "..\\notes.md"],
132 ["/repo/a\\/../../notes.md", "/repo", null],
133 ["/repo\\project/a.txt", "/repo\\project/", "a.txt"],
134 ["/repo/project/a.txt", "/repo\\project", null],
135 ["/repo\\project/a.txt", "/repo/project", null],
136 ["C:\\Repo\\src\\main.ts", "c:/repo/", "src/main.ts"],
137 ["/C:/Repo/src/main.ts", "c:\\repo", "src/main.ts"],
138 ["C:\\Repo\\src\\main.ts", "/c:/repo", "src/main.ts"],
139 ["\\\\SERVER\\Share\\Repo\\src\\main.ts", "\\\\server\\share\\repo", "src/main.ts"],
140 ["\\\\SERVER\\Share\\Repo\\src\\main.ts", "//server/share/repo", "src/main.ts"],
141 ["//server/share/a\\b.txt", "//server/share", "a\\b.txt"],
142 ["\\\\server\\share\\repo\\..\\notes.md", "\\\\server\\share\\repo", null],
143 ])("relates %s to %s", (path, workspaceRoot, relativePath) => {
144 expect(workspaceRelativeFilePath(path, workspaceRoot)).toBe(relativePath);
145 });
146 });