|
3 | 3 | compareSourcePaths, |
4 | 4 | getShebangFileExtension, |
5 | 5 | getSourceProximityRank, |
| 6 | + resolveConfiguredBinPath, |
6 | 7 | } from "./fileUtils"; |
7 | 8 |
|
8 | 9 | describe("getSourceProximityRank", () => { |
@@ -103,3 +104,102 @@ describe("getShebangFileExtension", () => { |
103 | 104 | expect(getShebangFileExtension("#!/usr/bin/env made-up\n")).toBeUndefined(); |
104 | 105 | }); |
105 | 106 | }); |
| 107 | + |
| 108 | +describe("resolveConfiguredBinPath", () => { |
| 109 | + const folders = [ |
| 110 | + { name: "frontend", fsPath: "/repo/frontend" }, |
| 111 | + { name: "backend", fsPath: "/repo/backend" }, |
| 112 | + ]; |
| 113 | + const existsIn = (...paths: string[]) => { |
| 114 | + return (filePath: string) => paths.includes(filePath); |
| 115 | + }; |
| 116 | + // biome-ignore lint/suspicious/noTemplateCurlyInString: literal VS Code variable |
| 117 | + const workspaceFolderVar = "${workspaceFolder}"; |
| 118 | + |
| 119 | + it("leaves bare command names untouched for PATH lookup", () => { |
| 120 | + expect(resolveConfiguredBinPath("mise", folders, existsIn())).toBe("mise"); |
| 121 | + expect(resolveConfiguredBinPath("mise.exe", folders, existsIn())).toBe( |
| 122 | + "mise.exe", |
| 123 | + ); |
| 124 | + }); |
| 125 | + |
| 126 | + it("leaves absolute paths untouched", () => { |
| 127 | + expect( |
| 128 | + resolveConfiguredBinPath("/usr/local/bin/mise", folders, existsIn()), |
| 129 | + ).toBe("/usr/local/bin/mise"); |
| 130 | + }); |
| 131 | + |
| 132 | + it("resolves relative paths against the first workspace folder containing the file", () => { |
| 133 | + expect( |
| 134 | + resolveConfiguredBinPath( |
| 135 | + "./bin/mise", |
| 136 | + folders, |
| 137 | + existsIn("/repo/backend/bin/mise"), |
| 138 | + ), |
| 139 | + ).toBe("/repo/backend/bin/mise"); |
| 140 | + expect( |
| 141 | + resolveConfiguredBinPath( |
| 142 | + "bin/mise", |
| 143 | + folders, |
| 144 | + existsIn("/repo/frontend/bin/mise", "/repo/backend/bin/mise"), |
| 145 | + ), |
| 146 | + ).toBe("/repo/frontend/bin/mise"); |
| 147 | + }); |
| 148 | + |
| 149 | + it("falls back to the first workspace folder when the file does not exist", () => { |
| 150 | + expect(resolveConfiguredBinPath("./bin/mise", folders, existsIn())).toBe( |
| 151 | + "/repo/frontend/bin/mise", |
| 152 | + ); |
| 153 | + }); |
| 154 | + |
| 155 | + it("resolves workspaceFolder variables", () => { |
| 156 | + expect( |
| 157 | + resolveConfiguredBinPath( |
| 158 | + `${workspaceFolderVar}/bin/mise`, |
| 159 | + folders, |
| 160 | + existsIn("/repo/backend/bin/mise"), |
| 161 | + ), |
| 162 | + ).toBe("/repo/backend/bin/mise"); |
| 163 | + expect( |
| 164 | + resolveConfiguredBinPath( |
| 165 | + `${workspaceFolderVar}/bin/mise`, |
| 166 | + folders, |
| 167 | + existsIn(), |
| 168 | + ), |
| 169 | + ).toBe("/repo/frontend/bin/mise"); |
| 170 | + }); |
| 171 | + |
| 172 | + it("resolves named workspaceFolder variables against the named folder", () => { |
| 173 | + expect( |
| 174 | + resolveConfiguredBinPath( |
| 175 | + // biome-ignore lint/suspicious/noTemplateCurlyInString: literal VS Code variable |
| 176 | + "${workspaceFolder:backend}/bin/mise", |
| 177 | + folders, |
| 178 | + existsIn(), |
| 179 | + ), |
| 180 | + ).toBe("/repo/backend/bin/mise"); |
| 181 | + }); |
| 182 | + |
| 183 | + it("expands the home directory prefix", () => { |
| 184 | + const resolved = resolveConfiguredBinPath( |
| 185 | + "~/bin/mise", |
| 186 | + folders, |
| 187 | + existsIn(), |
| 188 | + ); |
| 189 | + expect(resolved.endsWith("bin/mise")).toBe(true); |
| 190 | + expect(resolved.startsWith("~")).toBe(false); |
| 191 | + }); |
| 192 | + |
| 193 | + it("returns the configured path unchanged without workspace folders", () => { |
| 194 | + expect(resolveConfiguredBinPath("./bin/mise", [], existsIn())).toBe( |
| 195 | + "./bin/mise", |
| 196 | + ); |
| 197 | + expect( |
| 198 | + resolveConfiguredBinPath( |
| 199 | + `${workspaceFolderVar}/bin/mise`, |
| 200 | + [], |
| 201 | + existsIn(), |
| 202 | + ), |
| 203 | + ).toBe(`${workspaceFolderVar}/bin/mise`); |
| 204 | + }); |
| 205 | +}); |
0 commit comments