The best way to control Claude Code, Codex and more from any computer or phone

main
ts 88 lines 3.61 KB
Raw
1 import { assert, describe, it } from "@effect/vitest";
2 import * as NodeServices from "@effect/platform-node/NodeServices";
3 import * as FileSystem from "effect/FileSystem";
4 import * as Path from "effect/Path";
5 import * as Effect from "effect/Effect";
6 import * as Layer from "effect/Layer";
7
8 import * as DesktopEnvironment from "../../app/DesktopEnvironment.ts";
9 import * as DesktopLifecycle from "../../app/DesktopLifecycle.ts";
10 import * as DesktopShutdown from "../../app/DesktopShutdown.ts";
11 import * as DesktopState from "../../app/DesktopState.ts";
12 import * as ElectronApp from "../../electron/ElectronApp.ts";
13 import * as ElectronTheme from "../../electron/ElectronTheme.ts";
14 import * as DesktopAppSettings from "../../settings/DesktopAppSettings.ts";
15 import * as DesktopWindow from "../../window/DesktopWindow.ts";
16 import {
17 getHostEnvironmentId,
18 getLocalEnvironmentEnabled,
19 setLocalEnvironmentEnabled,
20 } from "./localEnvironment.ts";
21
22 const layerUnusedLifecycleRuntime = Layer.mergeAll(
23 DesktopShutdown.layer,
24 DesktopState.layer,
25 Layer.succeed(
26 DesktopEnvironment.DesktopEnvironment,
27 DesktopEnvironment.DesktopEnvironment.of(
28 {} as DesktopEnvironment.DesktopEnvironment["Service"],
29 ),
30 ),
31 Layer.mock(DesktopWindow.DesktopWindow, {}),
32 Layer.mock(ElectronApp.ElectronApp, {}),
33 Layer.mock(ElectronTheme.ElectronTheme, {}),
34 );
35
36 describe("local environment IPC", () => {
37 it.effect("reads the shared home identity without creating one", () =>
38 Effect.gen(function* () {
39 const fs = yield* FileSystem.FileSystem;
40 const path = yield* Path.Path;
41 const stateDir = yield* fs.makeTempDirectoryScoped();
42 const environment = DesktopEnvironment.DesktopEnvironment.of({
43 path,
44 stateDir,
45 } as DesktopEnvironment.DesktopEnvironment["Service"]);
46 const read = getHostEnvironmentId
47 .handler(undefined)
48 .pipe(Effect.provideService(DesktopEnvironment.DesktopEnvironment, environment));
49 assert.strictEqual(yield* read, null);
50 assert.isFalse(yield* fs.exists(path.join(stateDir, "environment-id")));
51 yield* fs.writeFileString(path.join(stateDir, "environment-id"), " service-id\n");
52 assert.strictEqual(yield* read, "service-id");
53 yield* fs.writeFileString(path.join(stateDir, "environment-id"), "\n");
54 assert.strictEqual(yield* read, null);
55 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
56 );
57 it.effect("relaunches only when the setting changes and keeps other settings", () => {
58 const relaunchReasons: Array<string> = [];
59 const layer = Layer.mergeAll(
60 DesktopAppSettings.layerTest({
61 ...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
62 wslBackendEnabled: true,
63 }),
64 Layer.mock(DesktopLifecycle.DesktopLifecycle, {
65 relaunch: (reason) =>
66 Effect.sync(() => {
67 relaunchReasons.push(reason);
68 }),
69 }),
70 layerUnusedLifecycleRuntime,
71 );
72 return Effect.gen(function* () {
73 yield* setLocalEnvironmentEnabled.handler(false);
74 assert.isFalse(yield* getLocalEnvironmentEnabled.handler());
75 yield* setLocalEnvironmentEnabled.handler(false);
76 assert.deepEqual(relaunchReasons, ["localEnvironmentEnabled=false"]);
77
78 yield* setLocalEnvironmentEnabled.handler(true);
79 assert.isTrue(yield* getLocalEnvironmentEnabled.handler());
80 const appSettings = yield* DesktopAppSettings.DesktopAppSettings;
81 assert.isTrue((yield* appSettings.get).wslBackendEnabled);
82 assert.deepEqual(relaunchReasons, [
83 "localEnvironmentEnabled=false",
84 "localEnvironmentEnabled=true",
85 ]);
86 }).pipe(Effect.provide(layer));
87 });
88 });