The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as NodePath from "@effect/platform-node/NodePath"; |
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 3 | import { assert, describe, it } from "@effect/vitest"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as Layer from "effect/Layer"; |
| 6 | |
| 7 | import * as DesktopEnvironment from "./DesktopEnvironment.ts"; |
| 8 | import * as DesktopConfig from "./DesktopConfig.ts"; |
| 9 | |
| 10 | const defaultInput = { |
| 11 | dirname: "/repo/apps/desktop/dist-electron", |
| 12 | homeDirectory: "/Users/alice", |
| 13 | platform: "darwin", |
| 14 | processArch: "arm64", |
| 15 | appVersion: "0.0.22", |
| 16 | appPath: "/Applications/T3 Code.app/Contents/Resources/app.asar", |
| 17 | isPackaged: false, |
| 18 | resourcesPath: "/Applications/T3 Code.app/Contents/Resources", |
| 19 | runningUnderArm64Translation: false, |
| 20 | } satisfies DesktopEnvironment.MakeDesktopEnvironmentInput; |
| 21 | |
| 22 | const layerEnvironment = ( |
| 23 | overrides: Partial<DesktopEnvironment.MakeDesktopEnvironmentInput> = {}, |
| 24 | env: Record<string, string | undefined> = {}, |
| 25 | ) => |
| 26 | DesktopEnvironment.layer({ |
| 27 | ...defaultInput, |
| 28 | ...overrides, |
| 29 | }).pipe( |
| 30 | Layer.provide( |
| 31 | Layer.mergeAll(NodeServices.layer, NodePath.layerPosix, DesktopConfig.layerTest(env)), |
| 32 | ), |
| 33 | ); |
| 34 | |
| 35 | const makeEnvironment = ( |
| 36 | overrides: Partial<DesktopEnvironment.MakeDesktopEnvironmentInput> = {}, |
| 37 | env: Record<string, string | undefined> = {}, |
| 38 | ) => DesktopEnvironment.DesktopEnvironment.pipe(Effect.provide(layerEnvironment(overrides, env))); |
| 39 | |
| 40 | describe("DesktopEnvironment", () => { |
| 41 | it.effect("uses the packaged Windows server sidecar as the backend root", () => |
| 42 | Effect.gen(function* () { |
| 43 | const environment = yield* makeEnvironment({ |
| 44 | platform: "win32", |
| 45 | isPackaged: true, |
| 46 | appPath: "/install/resources/app.asar", |
| 47 | resourcesPath: "/install/resources", |
| 48 | }); |
| 49 | |
| 50 | assert.equal(environment.appRoot, "/install/resources/app.asar"); |
| 51 | assert.equal(environment.serverRoot, "/install/resources/server.asar"); |
| 52 | assert.equal( |
| 53 | environment.backendEntryPath, |
| 54 | "/install/resources/server.asar/apps/server/dist/bin.mjs", |
| 55 | ); |
| 56 | assert.equal( |
| 57 | environment.clientAssetsDir, |
| 58 | "/install/resources/server.asar/apps/server/dist/client", |
| 59 | ); |
| 60 | }), |
| 61 | ); |
| 62 | |
| 63 | it.effect("keeps implicit development state separate from production state", () => |
| 64 | Effect.gen(function* () { |
| 65 | const development = yield* makeEnvironment( |
| 66 | {}, |
| 67 | { VITE_DEV_SERVER_URL: "http://localhost:5173" }, |
| 68 | ); |
| 69 | const production = yield* makeEnvironment(); |
| 70 | |
| 71 | assert.equal(development.stateDir, "/Users/alice/.t3/dev"); |
| 72 | assert.equal(production.stateDir, "/Users/alice/.t3/userdata"); |
| 73 | }), |
| 74 | ); |
| 75 | }); |