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 makeClaudeCapabilitiesCacheKey,
10 makeClaudeContinuationGroupKey,
11 makeClaudeEnvironment,
12 resolveClaudeHomePath,
13} from "./ClaudeHome.ts";
14
15it.layer(NodeServices.layer)("ClaudeHome", (it) => {
16 describe("Claude home resolution", () => {
17 it.effect("uses the process home when no Claude home override is configured", () =>
18 Effect.gen(function* () {
19 const path = yield* Path.Path;
20 const resolved = path.resolve(NodeOS.homedir());
21
22 expect(yield* resolveClaudeHomePath({ homePath: "" })).toBe(resolved);
23 expect(yield* makeClaudeEnvironment({ homePath: "" })).toBe(process.env);
24 }),
25 );
26
27 it.effect("resolves configured Claude HOME and stamps continuation/cache keys with it", () =>
28 Effect.gen(function* () {
29 const path = yield* Path.Path;
30 const homePath = "~/.claude-work";
31 const resolved = path.resolve(NodeOS.homedir(), ".claude-work");
32
33 expect(yield* resolveClaudeHomePath({ homePath })).toBe(resolved);
34 expect((yield* makeClaudeEnvironment({ homePath })).CLAUDE_CONFIG_DIR).toBe(resolved);
35 expect(yield* makeClaudeContinuationGroupKey({ homePath })).toBe(`claude:home:${resolved}`);
36 expect(yield* makeClaudeCapabilitiesCacheKey({ binaryPath: "claude", homePath })).toBe(
37 `claude\0${resolved}\0`,
38 );
39 }),
40 );
41
42 it.effect("separates capability probes by cwd", () =>
43 Effect.gen(function* () {
44 const config = { binaryPath: "claude", homePath: "" };
45 const first = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-a");
46 const second = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-b");
47 expect(first).not.toBe(second);
48 }),
49 );
50
51 it.effect("keeps continuation compatible across instances with the same Claude HOME", () =>
52 Effect.gen(function* () {
53 const path = yield* Path.Path;
54 const resolved = path.resolve(NodeOS.homedir());
55
56 expect(yield* makeClaudeContinuationGroupKey({ homePath: "" })).toBe(
57 `claude:home:${resolved}`,
58 );
59 }),
60 );
61 });
62});