From 0704303ec8c72812644ee443b87857aae7059b90 Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Wed, 26 Nov 2025 12:11:49 -0600 Subject: [PATCH 1/2] update worktree directory --- .../routers/workspaces/workspaces.test.ts | 51 ++++++++++++++++++- .../lib/trpc/routers/workspaces/workspaces.ts | 8 ++- apps/desktop/src/shared/constants.ts | 3 ++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.test.ts b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.test.ts index 9c3c8fc54d2..3b45a05819f 100644 --- a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.test.ts +++ b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.test.ts @@ -1,3 +1,5 @@ +import { homedir } from "node:os"; +import { join } from "node:path"; import { beforeEach, describe, expect, it, mock } from "bun:test"; import { createWorkspacesRouter } from "./workspaces"; @@ -54,7 +56,10 @@ mock.module("main/lib/db", () => ({ let mockRemoveWorktree = mock((_mainRepoPath: string, _worktreePath: string) => Promise.resolve(), ); -const mockCreateWorktree = mock(() => Promise.resolve()); +const mockCreateWorktree = mock( + (_mainRepoPath: string, _branch: string, _worktreePath: string) => + Promise.resolve(), +); const mockGenerateBranchName = mock(() => "test-branch-123"); mock.module("./utils/git", () => ({ @@ -108,6 +113,50 @@ beforeEach(() => { }; }); +describe("workspaces router - create", () => { + it("creates worktree under home superset worktrees path", async () => { + const router = createWorkspacesRouter(); + const caller = router.createCaller({}); + + const result = await caller.create({ + projectId: "project-1", + name: "New Workspace", + }); + + const expectedPath = join( + homedir(), + ".superset", + "worktrees", + "test-branch-123", + ); + + expect(mockCreateWorktree).toHaveBeenCalledWith( + "/path/to/repo", + "test-branch-123", + expectedPath, + ); + expect(result.worktreePath).toBe(expectedPath); + expect(result.workspace.name).toBe("New Workspace"); + expect(result.workspace.tabOrder).toBe(1); + + const createdWorktree = mockDb.data.worktrees.find( + (worktree) => + worktree.branch === "test-branch-123" && + worktree.path === expectedPath && + worktree.projectId === "project-1", + ); + expect(createdWorktree).toBeTruthy(); + + const createdWorkspace = mockDb.data.workspaces.find( + (workspace) => workspace.id === result.workspace.id, + ); + expect(createdWorkspace?.worktreeId).toBe(createdWorktree?.id); + expect(mockDb.data.settings.lastActiveWorkspaceId).toBe( + result.workspace.id, + ); + }); +}); + describe("workspaces router - delete", () => { it("should successfully delete workspace and remove worktree", async () => { const router = createWorkspacesRouter(); diff --git a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts index dc667fe3d67..32cacbe71c1 100644 --- a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts +++ b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts @@ -1,3 +1,4 @@ +import { homedir } from "node:os"; import { join } from "node:path"; import { db } from "main/lib/db"; import { nanoid } from "nanoid"; @@ -28,7 +29,12 @@ export const createWorkspacesRouter = () => { const branch = generateBranchName(); - const worktreePath = join(project.mainRepoPath, ".superset", branch); + const worktreePath = join( + homedir(), + ".superset", + "worktrees", + branch, + ); await createWorktree(project.mainRepoPath, branch, worktreePath); diff --git a/apps/desktop/src/shared/constants.ts b/apps/desktop/src/shared/constants.ts index c182a64d74b..5e6c4dc4278 100644 --- a/apps/desktop/src/shared/constants.ts +++ b/apps/desktop/src/shared/constants.ts @@ -9,3 +9,6 @@ export const PLATFORM = { }; export const NOTIFICATIONS_PORT = 31415; + +export const SUPERSET_DIR_NAME = ".superset"; +export const WORKTREES_DIR_NAME = "worktrees"; From efe1523adc9f11e557f5b2ac78ea36821ce5071d Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Wed, 26 Nov 2025 12:16:15 -0600 Subject: [PATCH 2/2] refactor --- apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts index 32cacbe71c1..ccc9812ac90 100644 --- a/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts +++ b/apps/desktop/src/lib/trpc/routers/workspaces/workspaces.ts @@ -2,6 +2,7 @@ import { homedir } from "node:os"; import { join } from "node:path"; import { db } from "main/lib/db"; import { nanoid } from "nanoid"; +import { SUPERSET_DIR_NAME, WORKTREES_DIR_NAME } from "shared/constants"; import simpleGit from "simple-git"; import { z } from "zod"; import { publicProcedure, router } from "../.."; @@ -31,8 +32,8 @@ export const createWorkspacesRouter = () => { const worktreePath = join( homedir(), - ".superset", - "worktrees", + SUPERSET_DIR_NAME, + WORKTREES_DIR_NAME, branch, );