|
| 1 | +// @effect-diagnostics nodeBuiltinImport:off |
| 2 | +import * as NodePath from "node:path"; |
| 3 | + |
| 4 | +import { describe, expect, it } from "@effect/vitest"; |
| 5 | + |
| 6 | +import { |
| 7 | + isClaudeHomeExplicitOverride, |
| 8 | + resolveClaudeTranscriptDirPath, |
| 9 | +} from "./usageClaudeTranscriptDir.ts"; |
| 10 | + |
| 11 | +function resolve(input: { |
| 12 | + homePath: string; |
| 13 | + nestedProjectsExists: boolean; |
| 14 | + homeIsExplicitOverride: boolean; |
| 15 | +}): string { |
| 16 | + return resolveClaudeTranscriptDirPath({ |
| 17 | + ...input, |
| 18 | + join: NodePath.join, |
| 19 | + }); |
| 20 | +} |
| 21 | + |
| 22 | +describe("resolveClaudeTranscriptDirPath", () => { |
| 23 | + it("keeps the default home on ~/.claude/projects when the nested dir is missing", () => { |
| 24 | + const homePath = "/Users/alice"; |
| 25 | + const resolved = resolve({ |
| 26 | + homePath, |
| 27 | + nestedProjectsExists: false, |
| 28 | + homeIsExplicitOverride: false, |
| 29 | + }); |
| 30 | + |
| 31 | + expect(resolved).toBe(NodePath.join(homePath, ".claude", "projects")); |
| 32 | + expect(resolved).not.toBe(NodePath.join(homePath, "projects")); |
| 33 | + }); |
| 34 | + |
| 35 | + it("uses ~/.claude/projects when it exists on the default home", () => { |
| 36 | + const homePath = "/Users/alice"; |
| 37 | + expect( |
| 38 | + resolve({ |
| 39 | + homePath, |
| 40 | + nestedProjectsExists: true, |
| 41 | + homeIsExplicitOverride: false, |
| 42 | + }), |
| 43 | + ).toBe(NodePath.join(homePath, ".claude", "projects")); |
| 44 | + }); |
| 45 | + |
| 46 | + it("uses <override>/projects when a custom home has no nested projects dir", () => { |
| 47 | + const homePath = "/opt/claude-config"; |
| 48 | + expect( |
| 49 | + resolve({ |
| 50 | + homePath, |
| 51 | + nestedProjectsExists: false, |
| 52 | + homeIsExplicitOverride: true, |
| 53 | + }), |
| 54 | + ).toBe(NodePath.join(homePath, "projects")); |
| 55 | + }); |
| 56 | + |
| 57 | + it("prefers <override>/.claude/projects when a custom home nests the same way", () => { |
| 58 | + const homePath = "/opt/claude-config"; |
| 59 | + expect( |
| 60 | + resolve({ |
| 61 | + homePath, |
| 62 | + nestedProjectsExists: true, |
| 63 | + homeIsExplicitOverride: true, |
| 64 | + }), |
| 65 | + ).toBe(NodePath.join(homePath, ".claude", "projects")); |
| 66 | + }); |
| 67 | + |
| 68 | + it("treats empty or whitespace configured homePath as the default, not an override", () => { |
| 69 | + const homePath = "/Users/alice"; |
| 70 | + for (const configured of ["", " ", "\t", "\n", " \t\n "]) { |
| 71 | + expect(isClaudeHomeExplicitOverride(configured)).toBe(false); |
| 72 | + expect( |
| 73 | + resolve({ |
| 74 | + homePath, |
| 75 | + nestedProjectsExists: false, |
| 76 | + homeIsExplicitOverride: isClaudeHomeExplicitOverride(configured), |
| 77 | + }), |
| 78 | + ).toBe(NodePath.join(homePath, ".claude", "projects")); |
| 79 | + } |
| 80 | + }); |
| 81 | +}); |
| 82 | + |
| 83 | +describe("isClaudeHomeExplicitOverride", () => { |
| 84 | + it("is true only when the configured homePath is non-empty after trim", () => { |
| 85 | + expect(isClaudeHomeExplicitOverride("~/.claude-work")).toBe(true); |
| 86 | + expect(isClaudeHomeExplicitOverride(" /custom/claude ")).toBe(true); |
| 87 | + expect(isClaudeHomeExplicitOverride("")).toBe(false); |
| 88 | + expect(isClaudeHomeExplicitOverride(" ")).toBe(false); |
| 89 | + }); |
| 90 | +}); |
0 commit comments