The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
| 3 | import { SpawnExecutableResolution } from "@t3tools/shared/shell"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | |
| 6 | import { ClaudeExecutableFileCheck, resolveClaudeSdkExecutablePath } from "./ClaudeExecutable.ts"; |
| 7 | |
| 8 | const NPM_DIR = "C:\\Users\\dev\\AppData\\Roaming\\npm"; |
| 9 | const NPM_SHIM = `${NPM_DIR}\\claude.cmd`; |
| 10 | const NPM_PACKAGE_EXE = `${NPM_DIR}\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe`; |
| 11 | const NPM_PACKAGE_CLI = `${NPM_DIR}\\node_modules\\@anthropic-ai\\claude-code\\cli.js`; |
| 12 | const WINGET_DIR = "C:\\Users\\dev\\AppData\\Local\\Microsoft\\WinGet"; |
| 13 | const WINGET_SHIM = `${WINGET_DIR}\\Links\\claude.cmd`; |
| 14 | const WINGET_EXE = `${WINGET_DIR}\\Packages\\Anthropic.ClaudeCode_Microsoft.Winget.Source_8wekyb3d8bbwe\\claude.exe`; |
| 15 | |
| 16 | function withWindowsResolution(input: { |
| 17 | readonly resolvedCommand: string | undefined; |
| 18 | readonly existingFiles?: ReadonlyArray<string>; |
| 19 | }) { |
| 20 | const existing = new Set(input.existingFiles ?? []); |
| 21 | return <A, E, R>(effect: Effect.Effect<A, E, R>) => |
| 22 | effect.pipe( |
| 23 | Effect.provideService(HostProcess.Platform, "win32"), |
| 24 | Effect.provideService(SpawnExecutableResolution, () => input.resolvedCommand), |
| 25 | Effect.provideService(ClaudeExecutableFileCheck, (filePath) => existing.has(filePath)), |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | describe("resolveClaudeSdkExecutablePath", () => { |
| 30 | it.effect("follows an npm launcher shim to the packaged native binary", () => |
| 31 | Effect.gen(function* () { |
| 32 | expect( |
| 33 | yield* resolveClaudeSdkExecutablePath("claude", {}).pipe( |
| 34 | withWindowsResolution({ |
| 35 | resolvedCommand: NPM_SHIM, |
| 36 | existingFiles: [NPM_PACKAGE_EXE, NPM_PACKAGE_CLI], |
| 37 | }), |
| 38 | ), |
| 39 | ).toBe(NPM_PACKAGE_EXE); |
| 40 | }), |
| 41 | ); |
| 42 | |
| 43 | it.effect("follows the WinGet launcher to the package's native binary", () => |
| 44 | Effect.gen(function* () { |
| 45 | expect( |
| 46 | yield* resolveClaudeSdkExecutablePath("claude", {}).pipe( |
| 47 | withWindowsResolution({ resolvedCommand: WINGET_SHIM, existingFiles: [WINGET_EXE] }), |
| 48 | ), |
| 49 | ).toBe(WINGET_EXE); |
| 50 | }), |
| 51 | ); |
| 52 | |
| 53 | it.effect("follows .bat and .ps1 launcher shims the same way", () => |
| 54 | Effect.gen(function* () { |
| 55 | for (const shim of [`${NPM_DIR}\\claude.bat`, `${NPM_DIR}\\claude.ps1`]) { |
| 56 | expect( |
| 57 | yield* resolveClaudeSdkExecutablePath("claude", {}).pipe( |
| 58 | withWindowsResolution({ |
| 59 | resolvedCommand: shim, |
| 60 | existingFiles: [NPM_PACKAGE_EXE], |
| 61 | }), |
| 62 | ), |
| 63 | ).toBe(NPM_PACKAGE_EXE); |
| 64 | } |
| 65 | }), |
| 66 | ); |
| 67 | |
| 68 | it.effect("normalizes mixed-case shim extensions before matching", () => |
| 69 | Effect.gen(function* () { |
| 70 | expect( |
| 71 | yield* resolveClaudeSdkExecutablePath("claude", {}).pipe( |
| 72 | withWindowsResolution({ |
| 73 | resolvedCommand: `${NPM_DIR}\\claude.CMD`, |
| 74 | existingFiles: [NPM_PACKAGE_EXE], |
| 75 | }), |
| 76 | ), |
| 77 | ).toBe(NPM_PACKAGE_EXE); |
| 78 | }), |
| 79 | ); |
| 80 | |
| 81 | it.effect("falls back to cli.js when the package ships no native binary", () => |
| 82 | Effect.gen(function* () { |
| 83 | expect( |
| 84 | yield* resolveClaudeSdkExecutablePath("claude", {}).pipe( |
| 85 | withWindowsResolution({ |
| 86 | resolvedCommand: NPM_SHIM, |
| 87 | existingFiles: [NPM_PACKAGE_CLI], |
| 88 | }), |
| 89 | ), |
| 90 | ).toBe(NPM_PACKAGE_CLI); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | it.effect("returns the configured path when a shim has no known package entry", () => |
| 95 | Effect.gen(function* () { |
| 96 | expect( |
| 97 | yield* resolveClaudeSdkExecutablePath("claude", {}).pipe( |
| 98 | withWindowsResolution({ resolvedCommand: NPM_SHIM }), |
| 99 | ), |
| 100 | ).toBe("claude"); |
| 101 | }), |
| 102 | ); |
| 103 | }); |