|
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"; |
@@ -183,6 +184,39 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => { |
183 | 184 | }).pipe(Effect.scoped), |
184 | 185 | ); |
185 | 186 |
|
| 187 | + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( |
| 188 | + "skips a t3 directory or a file this user cannot execute", |
| 189 | + () => |
| 190 | + Effect.gen(function* () { |
| 191 | + const fs = yield* FileSystem.FileSystem; |
| 192 | + const path = yield* Path.Path; |
| 193 | + const home = yield* fs.makeTempDirectoryScoped(); |
| 194 | + const folder = path.join(home, "folder"); |
| 195 | + const plain = path.join(home, "plain"); |
| 196 | + const shadow = path.join(home, "shadow"); |
| 197 | + yield* fs.makeDirectory(path.join(folder, "t3"), { recursive: true }); |
| 198 | + yield* fs.makeDirectory(plain); |
| 199 | + yield* fs.writeFileString(path.join(plain, "t3"), "notes\n"); |
| 200 | + // Root can execute mode 0o601; other users must honor the owner permissions. |
| 201 | + yield* fs.chmod(path.join(plain, "t3"), process.getuid?.() === 0 ? 0o600 : 0o601); |
| 202 | + yield* fs.makeDirectory(shadow); |
| 203 | + yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 }); |
| 204 | + process.env.PATH = [folder, plain, shadow, path.join(home, ".local", "bin")].join(":"); |
| 205 | + |
| 206 | + const command = yield* commandIn({ home }); |
| 207 | + expect((yield* command.state).shadowedBy).toBe(path.join(shadow, "t3")); |
| 208 | + |
| 209 | + const error = yield* Effect.flip(command.install); |
| 210 | + expect(error.message).toContain(path.join(shadow, "t3")); |
| 211 | + |
| 212 | + yield* fs.remove(shadow, { recursive: true }); |
| 213 | + expect(yield* command.install).toMatchObject({ |
| 214 | + onPath: true, |
| 215 | + installedPath: path.join(home, ".local", "bin", "t3"), |
| 216 | + }); |
| 217 | + }).pipe(Effect.scoped), |
| 218 | + ); |
| 219 | + |
186 | 220 | it.effect("leaves the Windows PATH alone when it cannot be read", () => |
187 | 221 | Effect.gen(function* () { |
188 | 222 | const fs = yield* FileSystem.FileSystem; |
|
0 commit comments