Open History to see the last commit
1import * as NodeOS from "node:os";
2
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import { describe, expect, it } from "@effect/vitest";
5import * as Effect from "effect/Effect";
6import * as Path from "effect/Path";
7
8import {
9 claudeSignedOutMessage,
10 makeClaudeCapabilitiesCacheKey,
11 makeClaudeContinuationGroupKey,
12 makeClaudeEnvironment,
13 resolveClaudeHomePath,
14} from "./ClaudeHome.ts";
15
16it.layer(NodeServices.layer)("ClaudeHome", (it) => {
17 describe("Claude home resolution", () => {
18 it.effect("uses the process home when no Claude home override is configured", () =>
19 Effect.gen(function* () {
20 const path = yield* Path.Path;
21 const resolved = path.resolve(NodeOS.homedir());
22
23 expect(yield* resolveClaudeHomePath({ homePath: "" })).toBe(resolved);
24 expect(yield* makeClaudeEnvironment({ homePath: "" })).toBe(process.env);
25 }),
26 );
27
28 it.effect("resolves configured Claude HOME and stamps continuation/cache keys with it", () =>
29 Effect.gen(function* () {
30 const path = yield* Path.Path;
31 const homePath = "~/.claude-work";
32 const resolved = path.resolve(NodeOS.homedir(), ".claude-work");
33
34 expect(yield* resolveClaudeHomePath({ homePath })).toBe(resolved);
35 expect((yield* makeClaudeEnvironment({ homePath })).CLAUDE_CONFIG_DIR).toBe(resolved);
36 expect(yield* makeClaudeContinuationGroupKey({ homePath })).toBe(`claude:home:${resolved}`);
37 expect(yield* makeClaudeCapabilitiesCacheKey({ binaryPath: "claude", homePath })).toBe(
38 `claude\0${resolved}\0`,
39 );
40 }),
41 );
42
43 it("points the signed-out hint at the configured Claude home", () => {
44 expect(claudeSignedOutMessage({ configDir: undefined, cwd: "/synthetic" })).toContain(
45 "run `claude auth login`",
46 );
47 const configDir = "/synthetic/Claude work's $literal";
48 const message = claudeSignedOutMessage({ configDir, cwd: "/synthetic/project" });
49 expect(message).toContain(`CLAUDE_CONFIG_DIR set to "${configDir}"`);
50 expect(message).not.toContain("CLAUDE_CONFIG_DIR=");
51 expect(message).toContain("then start a new thread");
52 });
53
54 it.effect("separates capability probes by cwd", () =>
55 Effect.gen(function* () {
56 const config = { binaryPath: "claude", homePath: "" };
57 const first = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-a");
58 const second = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-b");
59 expect(first).not.toBe(second);
60 }),
61 );
62
63 it.effect("keeps continuation compatible across instances with the same Claude HOME", () =>
64 Effect.gen(function* () {
65 const path = yield* Path.Path;
66 const resolved = path.resolve(NodeOS.homedir());
67
68 expect(yield* makeClaudeContinuationGroupKey({ homePath: "" })).toBe(
69 `claude:home:${resolved}`,
70 );
71 }),
72 );
73 });
74});