The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { updateDeviceHosts } from "./deviceHostsSettings.logic"; |
| 3 | |
| 4 | describe("device host changes across environments", () => { |
| 5 | const shared = { |
| 6 | kind: "ssh" as const, |
| 7 | id: "shared", |
| 8 | label: "Mac mini", |
| 9 | target: "julius@macmini", |
| 10 | }; |
| 11 | const local = { kind: "ssh" as const, id: "other", label: "Android", target: "julius@android" }; |
| 12 | |
| 13 | it("adds to differing host lists without losing environment-specific hosts, including on retry", () => { |
| 14 | const environments = [[], [local], [shared, local]]; |
| 15 | const saved = environments.map((hosts) => updateDeviceHosts(hosts, shared, false)); |
| 16 | expect(saved).toEqual([[shared], [local, shared], [shared, local]]); |
| 17 | expect(saved.map((hosts) => updateDeviceHosts(hosts, shared, false))).toEqual(saved); |
| 18 | }); |
| 19 | |
| 20 | // regression: #11541 device settings edits must apply to selected environments only |
| 21 | it("edits and removes the shared host while preserving unrelated hosts", () => { |
| 22 | const edited = { ...shared, target: "julius@new-address" }; |
| 23 | const saved = [[shared], [local, shared]].map((hosts) => |
| 24 | updateDeviceHosts(hosts, edited, false), |
| 25 | ); |
| 26 | expect(saved).toEqual([[edited], [local, edited]]); |
| 27 | expect(saved.map((hosts) => updateDeviceHosts(hosts, edited, true))).toEqual([[], [local]]); |
| 28 | }); |
| 29 | |
| 30 | it("recognizes a host added separately on another environment and preserves its local ID", () => { |
| 31 | const remote = { ...shared, id: "remote-id" }; |
| 32 | const edited = { ...shared, target: "julius@new-address" }; |
| 33 | expect(updateDeviceHosts([remote, local], shared, false)).toEqual([remote, local]); |
| 34 | const saved = updateDeviceHosts([remote, local], edited, false, shared); |
| 35 | expect(saved).toEqual([{ ...edited, id: remote.id }, local]); |
| 36 | expect(updateDeviceHosts(saved, edited, false, shared)).toEqual(saved); |
| 37 | expect(updateDeviceHosts([remote, local], shared, true)).toEqual([local]); |
| 38 | }); |
| 39 | |
| 40 | it("keeps distinct SSH connections to the same target separate", () => { |
| 41 | const anotherPort = { ...shared, id: "another-port", port: 2222 }; |
| 42 | const anotherIdentity = { ...shared, id: "another-key", identityFile: "~/.ssh/another" }; |
| 43 | expect(updateDeviceHosts([anotherPort, anotherIdentity], shared, false)).toEqual([ |
| 44 | anotherPort, |
| 45 | anotherIdentity, |
| 46 | shared, |
| 47 | ]); |
| 48 | }); |
| 49 | |
| 50 | it("prefers the selected ID over a sibling with the same destination", () => { |
| 51 | const sibling = { ...shared, id: "sibling", label: "Another entry" }; |
| 52 | const edited = { ...shared, label: "Renamed" }; |
| 53 | expect(updateDeviceHosts([sibling, shared], edited, false, shared)).toEqual([sibling, edited]); |
| 54 | expect(updateDeviceHosts([sibling, shared], shared, true)).toEqual([sibling]); |
| 55 | }); |
| 56 | |
| 57 | it("refuses an ambiguous destination on another environment instead of changing a sibling", () => { |
| 58 | const remote = { ...shared, id: "remote" }; |
| 59 | const sibling = { ...shared, id: "sibling" }; |
| 60 | expect(() => updateDeviceHosts([remote, sibling], shared, true)).toThrow("Multiple hosts"); |
| 61 | expect(() => updateDeviceHosts([remote, sibling], shared, false)).toThrow("Multiple hosts"); |
| 62 | }); |
| 63 | }); |