| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { resolveDesktopAppControlAddress } from "./desktopAppControl.ts"; |
| 4 | |
| 5 | describe("resolveDesktopAppControlAddress", () => { |
| 6 | it("keeps Unix socket paths short and separates desktop state directories", () => { |
| 7 | const first = resolveDesktopAppControlAddress({ |
| 8 | stateDir: `/home/user/${"long/".repeat(40)}userdata`, |
| 9 | platform: "linux", |
| 10 | tempDir: "/tmp", |
| 11 | userId: 1000, |
| 12 | joinPath: (...segments) => segments.join("/"), |
| 13 | }); |
| 14 | const second = resolveDesktopAppControlAddress({ |
| 15 | stateDir: "/home/user/.t3/other/userdata", |
| 16 | platform: "linux", |
| 17 | tempDir: "/tmp", |
| 18 | userId: 1000, |
| 19 | joinPath: (...segments) => segments.join("/"), |
| 20 | }); |
| 21 | |
| 22 | expect(first.directory).toBe("/tmp/t3code-1000"); |
| 23 | expect(first.address.length).toBeLessThan(108); |
| 24 | expect(first.address).not.toBe(second.address); |
| 25 | }); |
| 26 | |
| 27 | it("uses a Windows named pipe", () => { |
| 28 | const result = resolveDesktopAppControlAddress({ |
| 29 | stateDir: "C:\\Users\\user\\.t3\\userdata", |
| 30 | platform: "win32", |
| 31 | tempDir: "C:\\Temp", |
| 32 | userId: undefined, |
| 33 | joinPath: (...segments) => segments.join("\\"), |
| 34 | }); |
| 35 | |
| 36 | expect(result.directory).toBeNull(); |
| 37 | expect(result.address).toMatch(/^\\\\\.\\pipe\\t3code-app-[a-f0-9]{24}$/); |
| 38 | }); |
| 39 | }); |