Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ClaudeHome.test.ts

59 lines2.3 KB

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("resolves configured Claude HOME and stamps continuation/cache keys with it", () =>
18 Effect.gen(function* () {
19 const path = yield* Path.Path;
20 const homePath = "~/.claude-work";
21 const resolved = path.resolve(NodeOS.homedir(), ".claude-work");
22​
23 expect(yield* resolveClaudeHomePath({ homePath })).toBe(resolved);
24 expect((yield* makeClaudeEnvironment({ homePath })).CLAUDE_CONFIG_DIR).toBe(resolved);
25 expect(yield* makeClaudeContinuationGroupKey({ homePath })).toBe(`claude:home:${resolved}`);
26 expect(yield* makeClaudeCapabilitiesCacheKey({ binaryPath: "claude", homePath })).toBe(
27 `claude\0${resolved}\0`,
28 );
29 }),
30 );
31​
32 it.effect("uses inherited CLAUDE_CONFIG_DIR when homePath is empty", () =>
33 Effect.gen(function* () {
34 const path = yield* Path.Path;
35 const inherited = path.resolve("/tmp/claude-inherited");
36 const environment = { CLAUDE_CONFIG_DIR: inherited };
37​
38 expect(yield* resolveClaudeHomePath({ homePath: "" }, environment)).toBe(inherited);
39 expect(yield* makeClaudeContinuationGroupKey({ homePath: "" }, environment)).toBe(
40 `claude:home:${inherited}`,
41 );
42​
43 const explicit = path.resolve(NodeOS.homedir(), ".claude-work");
44 expect(yield* resolveClaudeHomePath({ homePath: "~/.claude-work" }, environment)).toBe(
45 explicit,
46 );
47 }),
48 );
49​
50 it.effect("separates capability probes by cwd", () =>
51 Effect.gen(function* () {
52 const config = { binaryPath: "claude", homePath: "" };
53 const first = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-a");
54 const second = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-b");
55 expect(first).not.toBe(second);
56 }),
57 );
58 });
59});