|
1 | 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
2 | | -import { expect, it } from "@effect/vitest"; |
| 2 | +import { afterEach, beforeEach, expect, it } from "@effect/vitest"; |
3 | 3 | import * as Effect from "effect/Effect"; |
4 | 4 | import * as FileSystem from "effect/FileSystem"; |
5 | 5 | import * as Option from "effect/Option"; |
@@ -85,6 +85,15 @@ const fakePowerShell = (initial: string) => { |
85 | 85 | return { registry, spawner }; |
86 | 86 | }; |
87 | 87 |
|
| 88 | +// The machine's own PATH may already hold a t3; each test sets the PATH it means. |
| 89 | +const machinePath = process.env.PATH; |
| 90 | +beforeEach(() => { |
| 91 | + process.env.PATH = ""; |
| 92 | +}); |
| 93 | +afterEach(() => { |
| 94 | + process.env.PATH = machinePath; |
| 95 | +}); |
| 96 | + |
88 | 97 | it.layer(NodeServices.layer)("DesktopCliCommand", (it) => { |
89 | 98 | it.effect("links the launcher onto PATH and removes only that link", () => |
90 | 99 | Effect.gen(function* () { |
@@ -165,24 +174,31 @@ it.layer(NodeServices.layer)("DesktopCliCommand", (it) => { |
165 | 174 | }).pipe(Effect.scoped), |
166 | 175 | ); |
167 | 176 |
|
168 | | - it.effect("reports when another t3 earlier on PATH would run instead", () => |
| 177 | + it.effect("refuses to install behind another t3 that runs first", () => |
169 | 178 | Effect.gen(function* () { |
170 | 179 | const fs = yield* FileSystem.FileSystem; |
171 | 180 | const path = yield* Path.Path; |
172 | 181 | const home = yield* fs.makeTempDirectoryScoped(); |
173 | 182 | const shadow = path.join(home, "shadow"); |
174 | 183 | yield* fs.makeDirectory(shadow); |
175 | 184 | yield* fs.writeFileString(path.join(shadow, "t3"), "#!/bin/sh\n", { mode: 0o755 }); |
176 | | - const previous = process.env.PATH; |
177 | 185 | process.env.PATH = [shadow, path.join(home, ".local", "bin")].join(":"); |
178 | | - yield* Effect.addFinalizer(() => Effect.sync(() => (process.env.PATH = previous))); |
179 | 186 |
|
180 | 187 | const command = yield* commandIn({ home }); |
| 188 | + const theirs = path.join(shadow, "t3"); |
| 189 | + expect((yield* command.state).shadowedBy).toBe(theirs); |
| 190 | + // A link behind it would never run, so nothing is created. |
| 191 | + const error = yield* Effect.flip(command.install); |
| 192 | + expect(error.message).toContain(theirs); |
| 193 | + expect(yield* fs.exists(path.join(home, ".local", "bin", "t3"))).toBe(false); |
| 194 | + |
| 195 | + yield* fs.remove(theirs); |
181 | 196 | const installed = yield* command.install; |
182 | | - expect(installed.installedPath).toBe(path.join(home, ".local", "bin", "t3")); |
183 | | - expect(installed.onPath).toBe(false); |
184 | | - yield* fs.remove(path.join(shadow, "t3")); |
185 | | - expect((yield* command.state).onPath).toBe(true); |
| 197 | + expect(installed).toMatchObject({ |
| 198 | + onPath: true, |
| 199 | + installedPath: path.join(home, ".local", "bin", "t3"), |
| 200 | + }); |
| 201 | + expect(installed.shadowedBy).toBeUndefined(); |
186 | 202 | }).pipe(Effect.scoped), |
187 | 203 | ); |
188 | 204 |
|
|
0 commit comments