Skip to content
Source
Sign inSign up

desktopAppActivation.test.ts

70 lines2.2 KB

1import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it, vi } from "vite-plus/test";
3​
4import {
5 handleDesktopAppActivationRequest,
6 type DesktopAppActivationDependencies,
7} from "./desktopAppActivation";
8​
9const environmentId = EnvironmentId.make("primary");
10const existingProjectId = ProjectId.make("project-existing");
11const createdProjectId = ProjectId.make("project-created");
12const threadId = ThreadId.make("thread-1");
13const request = {
14 version: 1,
15 requestId: "request-1",
16 type: "open-workspace",
17 workspaceRoot: "/workspace/project",
18 platform: "linux",
19} as const;
20​
21function dependencies(
22 overrides: Partial<DesktopAppActivationDependencies> = {},
23): DesktopAppActivationDependencies {
24 return {
25 getTarget: () => ({ environmentId, platform: "linux" }),
26 findProject: () => ({
27 id: existingProjectId,
28 environmentId,
29 workspaceRoot: request.workspaceRoot,
30 }),
31 createProject: vi.fn(async () => createdProjectId),
32 waitForProject: vi.fn(async () => undefined),
33 openThread: vi.fn(async () => ({ threadId })),
34 ...overrides,
35 };
37​
38describe("desktop app activation", () => {
39 it("waits for a created project before it opens the thread", async () => {
40 const order: string[] = [];
41 const deps = dependencies({
42 findProject: () => null,
43 createProject: vi.fn(async () => {
44 order.push("create");
45 return createdProjectId;
46 }),
47 waitForProject: vi.fn(async () => {
48 order.push("project-event");
49 }),
50 openThread: vi.fn(async () => {
51 order.push("open-thread");
52 return { threadId };
53 }),
54 });
55​
56 const response = await handleDesktopAppActivationRequest(request, deps);
57​
58 expect(order).toEqual(["create", "project-event", "open-thread"]);
59 expect(response).toMatchObject({ ok: true, projectId: createdProjectId });
60 });
61​
62 it("rejects a Windows path when the primary environment is WSL", async () => {
63 const response = await handleDesktopAppActivationRequest(
64 { ...request, platform: "win32" },
65 dependencies({ getTarget: () => ({ environmentId, platform: "linux" }) }),
66 );
67​
68 expect(response).toMatchObject({ ok: false, code: "platform-mismatch" });
69 });
70});