Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

wslPaths.test.ts

199 lines6.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 applyWslEnvironmentConfiguration,
5 parseWslUncPath,
6 resolveProjectPickerTarget,
7 resolveWslProjectSelection,
8} from "./wslPaths";
9​
10describe("parseWslUncPath", () => {
11 it("parses wsl.localhost UNC paths into distro and POSIX path", () => {
12 expect(parseWslUncPath("\\\\wsl.localhost\\Ubuntu-22.04\\home\\josh\\repo")).toEqual({
13 distro: "Ubuntu-22.04",
14 linuxPath: "/home/josh/repo",
15 });
16 expect(parseWslUncPath("\\\\wsl$\\Debian Dev\\tmp\\demo")).toEqual({
17 distro: "Debian Dev",
18 linuxPath: "/tmp/demo",
19 });
20 });
21​
22 it("rejects non-WSL paths and invalid distro names", () => {
23 expect(parseWslUncPath("C:\\Users\\Josh\\repo")).toBeNull();
24 expect(parseWslUncPath("\\\\wsl.localhost\\bad!name\\home")).toBeNull();
25 expect(parseWslUncPath("\\\\wsl.localhost\\ \\home")).toBeNull();
26 expect(parseWslUncPath("\\\\wsl.localhost\\..\\home")).toBeNull();
27 });
28});
29​
30describe("resolveWslProjectSelection", () => {
31 it("routes a UNC path to the matching WSL backend", () => {
32 expect(
33 resolveWslProjectSelection("\\\\wsl.localhost\\Ubuntu\\home\\theo\\repo", [
34 { environmentId: "env-debian", backendId: "wsl:Debian", runningDistro: null },
35 { environmentId: "env-ubuntu", backendId: "wsl:Ubuntu", runningDistro: null },
36 ]),
37 ).toEqual({
38 distro: "Ubuntu",
39 environmentId: "env-ubuntu",
40 linuxPath: "/home/theo/repo",
41 });
42 });
43​
44 it("does not route to a sole WSL backend for a different distro", () => {
45 expect(
46 resolveWslProjectSelection("\\\\wsl.localhost\\Debian\\home\\theo\\repo", [
47 { environmentId: "env-ubuntu", backendId: "wsl:Ubuntu", runningDistro: null },
48 ]),
49 ).toBeNull();
50 });
51​
52 it("routes a default backend only to the distro used by its running process", () => {
53 const candidates = [
54 { environmentId: "env-wsl", backendId: "wsl:default", runningDistro: "Debian" },
55 ];
56​
57 expect(
58 resolveWslProjectSelection("\\\\wsl.localhost\\Debian\\home\\theo\\repo", candidates),
59 ).toEqual({
60 distro: "Debian",
61 environmentId: "env-wsl",
62 linuxPath: "/home/theo/repo",
63 });
64 expect(
65 resolveWslProjectSelection("\\\\wsl.localhost\\Ubuntu\\home\\theo\\repo", candidates),
66 ).toBeNull();
67 });
68});
69​
70describe("applyWslEnvironmentConfiguration", () => {
71 const ubuntuConfiguration = {
72 enabled: true,
73 wslOnly: false,
74 distro: null,
75 distros: [
76 { name: "Debian", isDefault: false },
77 { name: "Ubuntu", isDefault: true },
78 ],
79 };
80​
81 it("does not replace a live default backend's running distro from current configuration", () => {
82 const candidates = applyWslEnvironmentConfiguration(
83 [{ environmentId: "env-wsl", backendId: "wsl:default", runningDistro: "Debian" }],
84 "env-primary",
85 ubuntuConfiguration,
86 );
87​
88 expect(
89 resolveWslProjectSelection("\\\\wsl.localhost\\Ubuntu\\home\\theo\\repo", candidates),
90 ).toBeNull();
91 expect(
92 resolveWslProjectSelection("\\\\wsl.localhost\\Debian\\home\\theo\\repo", candidates),
93 ).toEqual({
94 distro: "Debian",
95 environmentId: "env-wsl",
96 linuxPath: "/home/theo/repo",
97 });
98 });
99​
100 it("represents an explicitly configured WSL-only primary by its distro", () => {
101 expect(
102 applyWslEnvironmentConfiguration([], "env-primary", {
103 ...ubuntuConfiguration,
104 wslOnly: true,
105 distro: "ubuntu",
106 }),
107 ).toEqual([{ environmentId: "env-primary", backendId: "wsl:Ubuntu", runningDistro: "Ubuntu" }]);
108 });
109​
110 it("uses the live primary distro for a default-tracking WSL-only primary", () => {
111 const candidates = applyWslEnvironmentConfiguration(
112 [],
113 "env-primary",
114 {
115 ...ubuntuConfiguration,
116 wslOnly: true,
117 distros: [],
118 },
119 "Ubuntu",
120 );
121​
122 expect(candidates).toEqual([
123 { environmentId: "env-primary", backendId: "wsl:default", runningDistro: "Ubuntu" },
124 ]);
125 expect(
126 resolveWslProjectSelection("\\\\wsl.localhost\\Ubuntu\\home\\theo\\repo", candidates),
127 ).toEqual({
128 distro: "Ubuntu",
129 environmentId: "env-primary",
130 linuxPath: "/home/theo/repo",
131 });
132 });
133});
134​
135describe("resolveProjectPickerTarget", () => {
136 const ubuntuConfiguration = {
137 enabled: true,
138 wslOnly: true,
139 distro: "Ubuntu-22.04",
140 distros: [
141 { name: "Debian", isDefault: true },
142 { name: "Ubuntu-22.04", isDefault: false },
143 ],
144 };
145​
146 it("routes a WSL-only primary picker to its configured distro", () => {
147 expect(
148 resolveProjectPickerTarget({
149 browseEnvironmentId: "env-primary",
150 primaryEnvironmentId: "env-primary",
151 desktopInstanceId: null,
152 wslConfiguration: ubuntuConfiguration,
153 }),
154 ).toBe("wsl:Ubuntu-22.04");
155 });
156​
157 it("uses installed casing when discovery finds the configured distro", () => {
158 expect(
159 resolveProjectPickerTarget({
160 browseEnvironmentId: "env-primary",
161 primaryEnvironmentId: "env-primary",
162 desktopInstanceId: null,
163 wslConfiguration: { ...ubuntuConfiguration, distro: "ubuntu-22.04" },
164 }),
165 ).toBe("wsl:Ubuntu-22.04");
166 });
167​
168 it("routes a default-tracking WSL-only primary picker through the live sentinel", () => {
169 expect(
170 resolveProjectPickerTarget({
171 browseEnvironmentId: "env-primary",
172 primaryEnvironmentId: "env-primary",
173 desktopInstanceId: null,
174 wslConfiguration: { ...ubuntuConfiguration, distro: null },
175 }),
176 ).toBe("wsl:default");
177 });
178​
179 it("preserves combo-mode routing for primary and WSL backends", () => {
180 const comboConfiguration = { ...ubuntuConfiguration, wslOnly: false };
181​
182 expect(
183 resolveProjectPickerTarget({
184 browseEnvironmentId: "env-primary",
185 primaryEnvironmentId: "env-primary",
186 desktopInstanceId: null,
187 wslConfiguration: comboConfiguration,
188 }),
189 ).toBeNull();
190 expect(
191 resolveProjectPickerTarget({
192 browseEnvironmentId: "env-wsl",
193 primaryEnvironmentId: "env-primary",
194 desktopInstanceId: "wsl:Ubuntu-22.04",
195 wslConfiguration: comboConfiguration,
196 }),
197 ).toBe("wsl:Ubuntu-22.04");
198 });
199});