Open History to see the last commit
1import type { DesktopBridge, DesktopCliCommandState } from "@t3tools/contracts";
2import { describe, expect, it, vi } from "vite-plus/test";
3
4import { resolveTriageCommand } from "./bootError";
5
6const desktopWith = (getState: () => Promise<DesktopCliCommandState>) =>
7 ({ cliCommand: { getState } }) as unknown as DesktopBridge;
8
9const notOnPath = (launcherPath: string | null): DesktopCliCommandState => ({
10 supported: launcherPath !== null,
11 installedPath: null,
12 onPath: false,
13 launcherPath,
14});
15
16describe("resolveTriageCommand", () => {
17 it("prefers t3 on PATH, then the desktop launcher", async () => {
18 const onPath = { ...notOnPath("/home/me/.t3/bin/t3"), onPath: true };
19 await expect(resolveTriageCommand(desktopWith(async () => onPath))).resolves.toBe("t3 triage");
20 await expect(
21 resolveTriageCommand(desktopWith(async () => notOnPath("/home/me/.t3/bin/t3"))),
22 ).resolves.toBe("/home/me/.t3/bin/t3 triage");
23 });
24
25 it("quotes launcher paths for the shell that runs them", async () => {
26 await expect(
27 resolveTriageCommand(desktopWith(async () => notOnPath("/Users/O'Neil/.t3/bin/t3"))),
28 ).resolves.toBe(`'/Users/O'"'"'Neil/.t3/bin/t3' triage`);
29 await expect(
30 resolveTriageCommand(desktopWith(async () => notOnPath("C:\\Users\\Me\\.t3\\bin\\t3.cmd"))),
31 ).resolves.toBe("C:\\Users\\Me\\.t3\\bin\\t3.cmd triage");
32 await expect(
33 resolveTriageCommand(
34 desktopWith(async () => notOnPath("C:\\Users\\Jo O'Neil\\.t3\\bin\\t3.cmd")),
35 ),
36 ).resolves.toBe("& 'C:\\Users\\Jo O''Neil\\.t3\\bin\\t3.cmd' triage");
37 });
38
39 it("falls back to npx without a usable desktop launcher", async () => {
40 using _warn = vi.spyOn(console, "warn").mockImplementation(() => {});
41 await expect(resolveTriageCommand(undefined)).resolves.toBe("npx t3 triage");
42 await expect(resolveTriageCommand({} as DesktopBridge)).resolves.toBe("npx t3 triage");
43 await expect(resolveTriageCommand(desktopWith(async () => notOnPath(null)))).resolves.toBe(
44 "npx t3 triage",
45 );
46 const staleWindowsPathEntry = { ...notOnPath(null), supported: true, onPath: true };
47 await expect(
48 resolveTriageCommand(desktopWith(async () => staleWindowsPathEntry)),
49 ).resolves.toBe("npx t3 triage");
50 await expect(
51 resolveTriageCommand(desktopWith(() => Promise.reject(new Error("ipc closed")))),
52 ).resolves.toBe("npx t3 triage");
53 });
54});