The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | ProviderDriverKind, |
| 3 | ProviderInstanceId, |
| 4 | type ManagedPolicySummary, |
| 5 | type ServerSettings, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import { describe, expect, it } from "vite-plus/test"; |
| 8 | |
| 9 | import { planClaudeAccountSave } from "./claude-accounts"; |
| 10 | |
| 11 | const claude = ProviderDriverKind.make("claudeAgent"); |
| 12 | const work = ProviderInstanceId.make("claudeAgent_work"); |
| 13 | |
| 14 | describe("planClaudeAccountSave", () => { |
| 15 | it("adds a signed-in config folder as a new Claude instance with a free id", () => { |
| 16 | const providerInstances: ServerSettings["providerInstances"] = { |
| 17 | [work]: { driver: claude, config: { homePath: "~/.claude-work" } }, |
| 18 | }; |
| 19 | const plan = (name: string, configDir: string) => |
| 20 | planClaudeAccountSave({ |
| 21 | providerInstances, |
| 22 | policy: undefined, |
| 23 | instanceId: null, |
| 24 | draft: { name, configDir }, |
| 25 | }); |
| 26 | |
| 27 | expect(plan(" Work ", " ~/.claude-willy ")).toEqual({ |
| 28 | mutation: { |
| 29 | operation: "create", |
| 30 | instanceId: "claudeAgent_work_2", |
| 31 | instance: { |
| 32 | driver: "claudeAgent", |
| 33 | enabled: true, |
| 34 | displayName: "Work", |
| 35 | config: { homePath: "~/.claude-willy" }, |
| 36 | }, |
| 37 | }, |
| 38 | }); |
| 39 | expect(plan("", "~/.claude-willy")).toHaveProperty("error"); |
| 40 | expect(plan("Willy", " ")).toHaveProperty("error"); |
| 41 | }); |
| 42 | |
| 43 | it("edits the name and folder without dropping the instance's other settings", () => { |
| 44 | const providerInstances: ServerSettings["providerInstances"] = { |
| 45 | [work]: { |
| 46 | driver: claude, |
| 47 | displayName: "Work", |
| 48 | accentColor: "#ff0000", |
| 49 | enabled: false, |
| 50 | environment: [{ name: "TOKEN", value: "", sensitive: true, valueRedacted: true }], |
| 51 | config: { homePath: "~/.claude-work", binaryPath: "/opt/claude", launchArgs: "--chrome" }, |
| 52 | }, |
| 53 | }; |
| 54 | const edit = (name: string, configDir: string) => |
| 55 | planClaudeAccountSave({ |
| 56 | providerInstances, |
| 57 | policy: undefined, |
| 58 | instanceId: work, |
| 59 | draft: { name, configDir }, |
| 60 | }); |
| 61 | |
| 62 | expect(edit("Willy", "~/.claude-willy")).toEqual({ |
| 63 | mutation: { |
| 64 | operation: "upsert", |
| 65 | instanceId: work, |
| 66 | instance: { |
| 67 | ...providerInstances[work], |
| 68 | displayName: "Willy", |
| 69 | config: { |
| 70 | binaryPath: "/opt/claude", |
| 71 | launchArgs: "--chrome", |
| 72 | homePath: "~/.claude-willy", |
| 73 | }, |
| 74 | }, |
| 75 | }, |
| 76 | }); |
| 77 | // Clearing both falls back to the driver's label and the default ~/.claude folder. |
| 78 | expect(edit("", "")).toEqual({ |
| 79 | mutation: { |
| 80 | operation: "upsert", |
| 81 | instanceId: work, |
| 82 | instance: { |
| 83 | driver: claude, |
| 84 | accentColor: "#ff0000", |
| 85 | enabled: false, |
| 86 | environment: providerInstances[work]!.environment, |
| 87 | config: { binaryPath: "/opt/claude", launchArgs: "--chrome" }, |
| 88 | }, |
| 89 | }, |
| 90 | }); |
| 91 | expect( |
| 92 | planClaudeAccountSave({ |
| 93 | providerInstances: { [work]: { driver: claude, config: { homePath: "~/.claude-work" } } }, |
| 94 | policy: undefined, |
| 95 | instanceId: work, |
| 96 | draft: { name: "", configDir: "" }, |
| 97 | }), |
| 98 | ).toEqual({ |
| 99 | mutation: { operation: "upsert", instanceId: work, instance: { driver: claude } }, |
| 100 | }); |
| 101 | }); |
| 102 | |
| 103 | it("refuses instances the managed policy pins", () => { |
| 104 | const policy: ManagedPolicySummary = { |
| 105 | organization: "Example Corp", |
| 106 | lockedSettings: ["providerInstances.claudeAgent_work.config.homePath"], |
| 107 | }; |
| 108 | expect( |
| 109 | planClaudeAccountSave({ |
| 110 | providerInstances: { [work]: { driver: claude } }, |
| 111 | policy, |
| 112 | instanceId: work, |
| 113 | draft: { name: "Work", configDir: "~/.claude-other" }, |
| 114 | }), |
| 115 | ).toEqual({ error: "Managed by Example Corp." }); |
| 116 | }); |
| 117 | }); |