Open History to see the last commit
1import { assert, describe, it } from "@effect/vitest";
2
3import { launchDetached, resolveEditorLaunch } from "./open";
4import { Effect } from "effect";
5import { assertSuccess } from "@effect/vitest/utils";
6
7describe("resolveEditorLaunch", () => {
8 it.effect("returns cursor command for cursor editor", () =>
9 Effect.gen(function* () {
10 const launch = yield* resolveEditorLaunch(
11 { cwd: "/tmp/workspace", editor: "cursor" },
12 "darwin",
13 );
14 assert.deepEqual(launch, {
15 command: "cursor",
16 args: ["/tmp/workspace"],
17 });
18 }),
19 );
20
21 it.effect("uses --goto when cursor target includes line/column suffixes", () =>
22 Effect.gen(function* () {
23 const lineOnly = yield* resolveEditorLaunch(
24 { cwd: "/tmp/workspace/AGENTS.md:48", editor: "cursor" },
25 "darwin",
26 );
27 assert.deepEqual(lineOnly, {
28 command: "cursor",
29 args: ["--goto", "/tmp/workspace/AGENTS.md:48"],
30 });
31
32 const lineAndColumn = yield* resolveEditorLaunch(
33 { cwd: "/tmp/workspace/src/open.ts:71:5", editor: "cursor" },
34 "darwin",
35 );
36 assert.deepEqual(lineAndColumn, {
37 command: "cursor",
38 args: ["--goto", "/tmp/workspace/src/open.ts:71:5"],
39 });
40 }),
41 );
42
43 it.effect("maps file-manager editor to OS open commands", () =>
44 Effect.gen(function* () {
45 const launch1 = yield* resolveEditorLaunch(
46 { cwd: "/tmp/workspace", editor: "file-manager" },
47 "darwin",
48 );
49 assert.deepEqual(launch1, {
50 command: "open",
51 args: ["/tmp/workspace"],
52 });
53
54 const launch2 = yield* resolveEditorLaunch(
55 { cwd: "C:\\workspace", editor: "file-manager" },
56 "win32",
57 );
58 assert.deepEqual(launch2, {
59 command: "explorer",
60 args: ["C:\\workspace"],
61 });
62
63 const launch3 = yield* resolveEditorLaunch(
64 { cwd: "/tmp/workspace", editor: "file-manager" },
65 "linux",
66 );
67 assert.deepEqual(launch3, {
68 command: "xdg-open",
69 args: ["/tmp/workspace"],
70 });
71 }),
72 );
73});
74
75describe("launchDetached", () => {
76 it.effect("resolves when command can be spawned", () =>
77 Effect.gen(function* () {
78 const result = yield* launchDetached({
79 command: process.execPath,
80 args: ["-e", "process.exit(0)"],
81 }).pipe(Effect.result);
82 assertSuccess(result, undefined);
83 }),
84 );
85
86 it.effect("rejects when command does not exist", () =>
87 Effect.gen(function* () {
88 const result = yield* launchDetached({
89 command: `t3code-no-such-command-${Date.now()}`,
90 args: [],
91 }).pipe(Effect.result);
92 assert.equal(result._tag, "Failure");
93 }),
94 );
95});