1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as FileSystem from "effect/FileSystem";
5import * as Path from "effect/Path";
6import * as HostProcess from "@t3tools/shared/HostProcess";
7
8import { findOwnedLauncher } from "./uninstall.ts";
9
10it.layer(NodeServices.layer)("t3 uninstall launcher", (it) => {
11 it.effect("claims only a launcher that points into this home's runtime tree", () =>
12 Effect.gen(function* () {
13 const fs = yield* FileSystem.FileSystem;
14 const path = yield* Path.Path;
15 const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-uninstall-" });
16 const versionsDir = path.join(root, "runtime/versions");
17 const exe = path.join(versionsDir, "1.0.0/t3");
18 const otherExe = path.join(root, "other/runtime/versions/1.0.0/t3");
19 const copy = path.join(root, "copy/t3");
20 for (const file of [exe, otherExe, copy]) {
21 yield* fs.makeDirectory(path.dirname(file), { recursive: true });
22 yield* fs.writeFileString(file, "");
23 }
24 const ours = path.join(root, "bin/t3");
25 const theirs = path.join(root, "other/bin/t3");
26 yield* fs.makeDirectory(path.dirname(ours), { recursive: true });
27 yield* fs.makeDirectory(path.dirname(theirs), { recursive: true });
28 yield* fs.symlink(exe, ours);
29 yield* fs.symlink(otherExe, theirs);
30
31 assert.equal(yield* findOwnedLauncher({ launchedAs: ours, versionsDir }), ours);
32 assert.isUndefined(yield* findOwnedLauncher({ launchedAs: theirs, versionsDir }));
33 assert.isUndefined(yield* findOwnedLauncher({ launchedAs: copy, versionsDir }));
34 assert.isUndefined(yield* findOwnedLauncher({ launchedAs: undefined, versionsDir }));
35 }).pipe(Effect.scoped, Effect.provideService(HostProcess.Platform, "linux")),
36 );
37});