|
1 | 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
2 | 2 | import { assert, it } from "@effect/vitest"; |
3 | 3 | import * as Config from "effect/Config"; |
| 4 | +import * as ConfigProvider from "effect/ConfigProvider"; |
4 | 5 | import * as Effect from "effect/Effect"; |
5 | 6 | import * as FileSystem from "effect/FileSystem"; |
| 7 | +import * as Layer from "effect/Layer"; |
6 | 8 | import * as Path from "effect/Path"; |
| 9 | +import * as TestConsole from "effect/testing/TestConsole"; |
| 10 | +import { Command } from "effect/cli"; |
7 | 11 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
| 12 | +import * as NetService from "@t3tools/shared/Net"; |
| 13 | +import { afterEach, vi } from "vite-plus/test"; |
8 | 14 |
|
9 | | -import { findOwnedLauncher, findRecordedLaunchers, spawnWindowsRemoval } from "./uninstall.ts"; |
| 15 | +import packageJson from "../../package.json" with { type: "json" }; |
| 16 | +import * as BootService from "../cloud/bootService.ts"; |
| 17 | +import { |
| 18 | + findOwnedLauncher, |
| 19 | + findRecordedLaunchers, |
| 20 | + spawnWindowsRemoval, |
| 21 | + uninstallCommand, |
| 22 | +} from "./uninstall.ts"; |
| 23 | + |
| 24 | +afterEach(() => vi.restoreAllMocks()); |
| 25 | + |
| 26 | +it.layer(Layer.mergeAll(NodeServices.layer, NetService.layer))("t3 uninstall command", (it) => { |
| 27 | + it.effect("names another home's service it leaves installed", () => |
| 28 | + Effect.gen(function* () { |
| 29 | + const fs = yield* FileSystem.FileSystem; |
| 30 | + const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-uninstall-cli-test-" }); |
| 31 | + const uninstalls: Array<true> = []; |
| 32 | + vi.spyOn(BootService, "layer").mockReturnValue( |
| 33 | + Layer.succeed( |
| 34 | + BootService.BootService, |
| 35 | + BootService.BootService.of({ |
| 36 | + status: Effect.succeed({ |
| 37 | + supported: true, |
| 38 | + installed: true, |
| 39 | + current: true, |
| 40 | + installedBaseDir: "/home/me/.t3", |
| 41 | + unitPath: "/home/me/.config/systemd/user/t3code.service", |
| 42 | + logPath: "/home/me/.t3/userdata/logs/boot-service.log", |
| 43 | + }), |
| 44 | + withStopped: (operation) => operation, |
| 45 | + restart: Effect.die("unexpected restart"), |
| 46 | + install: () => Effect.die("unexpected install"), |
| 47 | + uninstall: Effect.sync(() => { |
| 48 | + uninstalls.push(true); |
| 49 | + return true; |
| 50 | + }), |
| 51 | + }), |
| 52 | + ), |
| 53 | + ); |
| 54 | + |
| 55 | + const output = yield* Command.runWith(uninstallCommand, { version: packageJson.version })([ |
| 56 | + "--base-dir", |
| 57 | + baseDir, |
| 58 | + "--yes", |
| 59 | + ]).pipe( |
| 60 | + Effect.andThen(TestConsole.logLines), |
| 61 | + Effect.map((lines) => lines.join("\n")), |
| 62 | + Effect.provideService(HostProcess.Environment, {}), |
| 63 | + Effect.provideService(HostProcess.IsExecutable, false), |
| 64 | + Effect.provide( |
| 65 | + Layer.mergeAll( |
| 66 | + ConfigProvider.layer(ConfigProvider.fromEnv({ env: {} })), |
| 67 | + Layer.fresh(TestConsole.layer), |
| 68 | + ), |
| 69 | + ), |
| 70 | + ); |
| 71 | + assert.deepStrictEqual(uninstalls, []); |
| 72 | + assert.include(output, "--base-dir '/home/me/.t3'"); |
| 73 | + }), |
| 74 | + ); |
| 75 | +}); |
10 | 76 |
|
11 | 77 | it.layer(NodeServices.layer)("t3 uninstall launcher", (it) => { |
12 | 78 | it.effect("claims only a launcher that points into this home's runtime tree", () => |
|
0 commit comments