|
1 | 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
2 | 2 | import { afterEach, beforeEach, expect, it } from "@effect/vitest"; |
| 3 | +import * as HostProcess from "@t3tools/shared/HostProcess"; |
3 | 4 | import * as Effect from "effect/Effect"; |
4 | 5 | import * as FileSystem from "effect/FileSystem"; |
5 | 6 | import * as Option from "effect/Option"; |
@@ -135,6 +136,14 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => { |
135 | 136 | yield* command.uninstall; |
136 | 137 | expect(yield* fs.readFileString(theirs)).toBe("npm's t3\n"); |
137 | 138 | expect(yield* fs.readLink(path.join(home, "bin", "t3"))).toBe(path.join(home, "gone")); |
| 139 | + |
| 140 | + const launcher = path.join(home, ".t3", "bin", "t3"); |
| 141 | + yield* fs.writeFileString(launcher, "npm's t3\n"); |
| 142 | + process.env.PATH = path.dirname(launcher); |
| 143 | + expect(yield* command.state).toMatchObject({ onPath: false, shadowedBy: launcher }); |
| 144 | + expect((yield* Effect.flip(command.install)).message).toContain("Could not set up"); |
| 145 | + yield* command.uninstall; |
| 146 | + expect(yield* fs.readFileString(launcher)).toBe("npm's t3\n"); |
138 | 147 | }).pipe(Effect.scoped), |
139 | 148 | ); |
140 | 149 |
|
@@ -183,6 +192,67 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => { |
183 | 192 | }).pipe(Effect.scoped), |
184 | 193 | ); |
185 | 194 |
|
| 195 | + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( |
| 196 | + "skips a t3 directory or a file this user cannot execute", |
| 197 | + () => |
| 198 | + Effect.gen(function* () { |
| 199 | + const fs = yield* FileSystem.FileSystem; |
| 200 | + const path = yield* Path.Path; |
| 201 | + const home = yield* fs.makeTempDirectoryScoped(); |
| 202 | + const folder = path.join(home, "folder"); |
| 203 | + const plain = path.join(home, "plain"); |
| 204 | + const shadow = path.join(home, "shadow"); |
| 205 | + yield* fs.makeDirectory(path.join(folder, "t3"), { recursive: true }); |
| 206 | + yield* fs.makeDirectory(plain); |
| 207 | + yield* fs.writeFileString(path.join(plain, "t3"), "notes\n"); |
| 208 | + // Root can execute mode 0o601; other users must honor the owner permissions. |
| 209 | + yield* fs.chmod(path.join(plain, "t3"), process.getuid?.() === 0 ? 0o600 : 0o601); |
| 210 | + yield* fs.makeDirectory(shadow); |
| 211 | + yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 }); |
| 212 | + process.env.PATH = [folder, plain, shadow, path.join(home, ".local", "bin")].join(":"); |
| 213 | + |
| 214 | + const command = yield* commandIn({ home }); |
| 215 | + expect((yield* command.state).shadowedBy).toBe(path.join(shadow, "t3")); |
| 216 | + |
| 217 | + const error = yield* Effect.flip(command.install); |
| 218 | + expect(error.message).toContain(path.join(shadow, "t3")); |
| 219 | + |
| 220 | + yield* fs.remove(shadow, { recursive: true }); |
| 221 | + expect(yield* command.install).toMatchObject({ |
| 222 | + onPath: true, |
| 223 | + installedPath: path.join(home, ".local", "bin", "t3"), |
| 224 | + }); |
| 225 | + }).pipe(Effect.scoped), |
| 226 | + ); |
| 227 | + |
| 228 | + it.effect("does not treat its own launcher as another t3 when its folder is first on PATH", () => |
| 229 | + Effect.gen(function* () { |
| 230 | + const fs = yield* FileSystem.FileSystem; |
| 231 | + const path = yield* Path.Path; |
| 232 | + const home = yield* fs.makeTempDirectoryScoped(); |
| 233 | + const launcher = path.join(home, ".t3", "bin", "t3"); |
| 234 | + process.env.PATH = [path.dirname(launcher), path.join(home, ".local", "bin")].join(":"); |
| 235 | + |
| 236 | + const command = yield* commandIn({ home }); |
| 237 | + const installed = yield* command.install; |
| 238 | + |
| 239 | + expect(yield* fs.exists(launcher)).toBe(true); |
| 240 | + expect(installed).toMatchObject({ |
| 241 | + onPath: true, |
| 242 | + installedPath: path.join(home, ".local", "bin", "t3"), |
| 243 | + }); |
| 244 | + expect(installed.shadowedBy).toBeUndefined(); |
| 245 | + expect(yield* command.state).toEqual(installed); |
| 246 | + |
| 247 | + const removed = yield* command.uninstall; |
| 248 | + expect(removed.installedPath).toBeNull(); |
| 249 | + expect(removed.onPath).toBe(true); |
| 250 | + expect(yield* command.state).toEqual(removed); |
| 251 | + expect(yield* fs.exists(installed.installedPath!)).toBe(false); |
| 252 | + expect(yield* fs.exists(launcher)).toBe(true); |
| 253 | + }).pipe(Effect.scoped), |
| 254 | + ); |
| 255 | + |
186 | 256 | it.effect("leaves the Windows PATH alone when it cannot be read", () => |
187 | 257 | Effect.gen(function* () { |
188 | 258 | const fs = yield* FileSystem.FileSystem; |
|
0 commit comments