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

ClaudeHome.test.ts

102 lines3.8 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 FileSystem from "effect/FileSystem";
7import * as Path from "effect/Path";
8​
9import {
10 makeClaudeCapabilitiesCacheKey,
11 makeClaudeContinuationGroupKey,
12 makeClaudeEnvironment,
13 mergeClaudeProcessEnvironment,
14 resolveClaudeHomePath,
15} from "./ClaudeHome.ts";
16​
17it.layer(NodeServices.layer)("ClaudeHome", (it) => {
18 describe("Claude home resolution", () => {
19 it.effect("resolves configured Claude HOME and stamps continuation/cache keys with it", () =>
20 Effect.gen(function* () {
21 const path = yield* Path.Path;
22 const homePath = "~/.claude-work";
23 const resolved = path.resolve(NodeOS.homedir(), ".claude-work");
24​
25 expect(yield* resolveClaudeHomePath({ homePath })).toBe(resolved);
26 expect((yield* makeClaudeEnvironment({ homePath })).CLAUDE_CONFIG_DIR).toBe(resolved);
27 expect(yield* makeClaudeContinuationGroupKey({ homePath })).toBe(`claude:home:${resolved}`);
28 expect(yield* makeClaudeCapabilitiesCacheKey({ binaryPath: "claude", homePath })).toBe(
29 `claude\0${resolved}\0`,
30 );
31 }),
32 );
33​
34 it.effect("uses inherited CLAUDE_CONFIG_DIR when homePath is empty", () =>
35 Effect.gen(function* () {
36 const path = yield* Path.Path;
37 const inherited = path.resolve("/tmp/claude-inherited");
38 const environment = { CLAUDE_CONFIG_DIR: inherited };
39​
40 expect(yield* resolveClaudeHomePath({ homePath: "" }, environment)).toBe(inherited);
41 expect(yield* makeClaudeContinuationGroupKey({ homePath: "" }, environment)).toBe(
42 `claude:home:${inherited}`,
43 );
44​
45 const explicit = path.resolve(NodeOS.homedir(), ".claude-work");
46 expect(yield* resolveClaudeHomePath({ homePath: "~/.claude-work" }, environment)).toBe(
47 explicit,
48 );
49 }),
50 );
51​
52 it.effect("separates capability probes by cwd", () =>
53 Effect.gen(function* () {
54 const config = { binaryPath: "claude", homePath: "" };
55 const first = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-a");
56 const second = yield* makeClaudeCapabilitiesCacheKey(config, "/repo-b");
57 expect(first).not.toBe(second);
58 }),
59 );
60 });
61​
62 it.effect(
63 "drops the launching Claude session and labels processes t3-code unless overridden",
64 () =>
65 Effect.gen(function* () {
66 const fileSystem = yield* FileSystem.FileSystem;
67 const path = yield* Path.Path;
68 const homePath = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
69 const host = {
70 CLAUDE_CODE_ENTRYPOINT: "claude-desktop",
71 CLAUDECODE: "1",
72 CLAUDE_CODE_SESSION_ID: "host-session",
73 CLAUDE_CODE_MESSAGING_SOCKET: "/tmp/host-claude.sock",
74 CLAUDE_EFFORT: "high",
75 KEEP: "1",
76 };
77 const instance = [
78 { name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false },
79 { name: "CLAUDE_EFFORT", value: "low", sensitive: false },
80 ];
81​
82 expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toEqual({
83 CLAUDE_CODE_ENTRYPOINT: "t3-code",
84 KEEP: "1",
85 });
86 expect(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).toEqual({
87 CLAUDE_CODE_ENTRYPOINT: "instance",
88 CLAUDE_EFFORT: "low",
89 KEEP: "1",
90 });
91​
92 yield* fileSystem.writeFileString(
93 path.join(homePath, "settings.json"),
94 JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }),
95 );
96 expect(
97 (yield* mergeClaudeProcessEnvironment({ homePath }, instance, host))
98 .CLAUDE_CODE_ENTRYPOINT,
99 ).toBe("custom");
100 }),
101 );
102});