Open History to see the last commit
1import { describe, expect, it } from "@effect/vitest";
2import * as HostProcess from "@t3tools/shared/HostProcess";
3import { SpawnExecutableResolution } from "@t3tools/shared/shell";
4import * as Effect from "effect/Effect";
5
6import { ClaudeExecutableFileCheck, resolveClaudeSdkExecutablePath } from "./ClaudeExecutable.ts";
7
8const NPM_DIR = "C:\\Users\\dev\\AppData\\Roaming\\npm";
9const NPM_SHIM = `${NPM_DIR}\\claude.cmd`;
10const NPM_PACKAGE_EXE = `${NPM_DIR}\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe`;
11const NPM_PACKAGE_CLI = `${NPM_DIR}\\node_modules\\@anthropic-ai\\claude-code\\cli.js`;
12
13function withWindowsResolution(input: {
14 readonly resolvedCommand: string | undefined;
15 readonly existingFiles?: ReadonlyArray<string>;
16}) {
17 const existing = new Set(input.existingFiles ?? []);
18 return <A, E, R>(effect: Effect.Effect<A, E, R>) =>
19 effect.pipe(
20 Effect.provideService(HostProcess.Platform, "win32"),
21 Effect.provideService(SpawnExecutableResolution, () => input.resolvedCommand),
22 Effect.provideService(ClaudeExecutableFileCheck, (filePath) => existing.has(filePath)),
23 );
24}
25
26describe("resolveClaudeSdkExecutablePath", () => {
27 it.effect("follows an npm launcher shim to the packaged native binary", () =>
28 Effect.gen(function* () {
29 expect(
30 yield* resolveClaudeSdkExecutablePath("claude", {}).pipe(
31 withWindowsResolution({
32 resolvedCommand: NPM_SHIM,
33 existingFiles: [NPM_PACKAGE_EXE, NPM_PACKAGE_CLI],
34 }),
35 ),
36 ).toBe(NPM_PACKAGE_EXE);
37 }),
38 );
39
40 it.effect("follows .bat and .ps1 launcher shims the same way", () =>
41 Effect.gen(function* () {
42 for (const shim of [`${NPM_DIR}\\claude.bat`, `${NPM_DIR}\\claude.ps1`]) {
43 expect(
44 yield* resolveClaudeSdkExecutablePath("claude", {}).pipe(
45 withWindowsResolution({
46 resolvedCommand: shim,
47 existingFiles: [NPM_PACKAGE_EXE],
48 }),
49 ),
50 ).toBe(NPM_PACKAGE_EXE);
51 }
52 }),
53 );
54
55 it.effect("normalizes mixed-case shim extensions before matching", () =>
56 Effect.gen(function* () {
57 expect(
58 yield* resolveClaudeSdkExecutablePath("claude", {}).pipe(
59 withWindowsResolution({
60 resolvedCommand: `${NPM_DIR}\\claude.CMD`,
61 existingFiles: [NPM_PACKAGE_EXE],
62 }),
63 ),
64 ).toBe(NPM_PACKAGE_EXE);
65 }),
66 );
67
68 it.effect("falls back to cli.js when the package ships no native binary", () =>
69 Effect.gen(function* () {
70 expect(
71 yield* resolveClaudeSdkExecutablePath("claude", {}).pipe(
72 withWindowsResolution({
73 resolvedCommand: NPM_SHIM,
74 existingFiles: [NPM_PACKAGE_CLI],
75 }),
76 ),
77 ).toBe(NPM_PACKAGE_CLI);
78 }),
79 );
80
81 it.effect("returns the configured path when a shim has no known package entry", () =>
82 Effect.gen(function* () {
83 expect(
84 yield* resolveClaudeSdkExecutablePath("claude", {}).pipe(
85 withWindowsResolution({ resolvedCommand: NPM_SHIM }),
86 ),
87 ).toBe("claude");
88 }),
89 );
90});