From 2ef15725ad35a5005de97b44b19ba8d35026044b Mon Sep 17 00:00:00 2001 From: Justin Blumencranz <96924014+j15z@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:04:01 -0700 Subject: [PATCH 1/2] feat(copilot): identify current workspace in workspace list --- .../tools/handlers/workflow/queries.test.ts | 49 ++++++++++++++++++- .../tools/handlers/workflow/queries.ts | 5 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts b/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts index f8f33c8289e..b7ec3ce3d6c 100644 --- a/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts +++ b/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts @@ -2,8 +2,9 @@ import { getErrorMessage } from '@sim/utils/errors' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { ExecutionContext } from '@/lib/copilot/request/types' -const { executeWorkflowUseCaseMock } = vi.hoisted(() => ({ +const { executeWorkflowUseCaseMock, listUserWorkspacesMock } = vi.hoisted(() => ({ executeWorkflowUseCaseMock: vi.fn(), + listUserWorkspacesMock: vi.fn(), })) vi.mock('@/lib/copilot/application/execute-workflow-use-case', () => ({ @@ -12,7 +13,51 @@ vi.mock('@/lib/copilot/application/execute-workflow-use-case', () => ({ getErrorMessage(error, 'Workflow operation failed'), })) -import { executeGetBlockOutputs } from './queries' +vi.mock('@/lib/workspaces/utils', () => ({ + listUserWorkspaces: listUserWorkspacesMock, +})) + +import { executeGetBlockOutputs, executeListUserWorkspaces } from './queries' + +describe('executeListUserWorkspaces', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('marks the current workspace in the accessible workspace list', async () => { + listUserWorkspacesMock.mockResolvedValue([ + { workspaceId: 'workspace-1', workspaceName: 'One', role: 'owner' }, + { workspaceId: 'workspace-2', workspaceName: 'Two', role: 'read' }, + ]) + + const result = await executeListUserWorkspaces({ + userId: 'user-1', + workflowId: 'workflow-1', + workspaceId: 'workspace-2', + }) + + expect(listUserWorkspacesMock).toHaveBeenCalledWith('user-1') + expect(result).toEqual({ + success: true, + output: { + workspaces: [ + { + workspaceId: 'workspace-1', + workspaceName: 'One', + role: 'owner', + isCurrent: false, + }, + { + workspaceId: 'workspace-2', + workspaceName: 'Two', + role: 'read', + isCurrent: true, + }, + ], + }, + }) + }) +}) describe('executeGetBlockOutputs', () => { beforeEach(() => { diff --git a/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts b/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts index 8861dbc98d6..0291fdee8fc 100644 --- a/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts +++ b/apps/sim/lib/copilot/tools/handlers/workflow/queries.ts @@ -34,7 +34,10 @@ export async function executeListUserWorkspaces( context: ExecutionContext ): Promise { try { - const workspaces = await listUserWorkspaces(context.userId) + const workspaces = (await listUserWorkspaces(context.userId)).map((workspace) => ({ + ...workspace, + isCurrent: workspace.workspaceId === context.workspaceId, + })) return { success: true, output: { workspaces } } } catch (error) { From 6194745943097085d597097ea173198335b08b0f Mon Sep 17 00:00:00 2001 From: Justin Blumencranz <96924014+j15z@users.noreply.github.com> Date: Mon, 3 Aug 2026 14:12:25 -0700 Subject: [PATCH 2/2] fix(review): use absolute workspace query import --- apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts b/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts index b7ec3ce3d6c..801372da6f1 100644 --- a/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts +++ b/apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts @@ -17,7 +17,10 @@ vi.mock('@/lib/workspaces/utils', () => ({ listUserWorkspaces: listUserWorkspacesMock, })) -import { executeGetBlockOutputs, executeListUserWorkspaces } from './queries' +import { + executeGetBlockOutputs, + executeListUserWorkspaces, +} from '@/lib/copilot/tools/handlers/workflow/queries' describe('executeListUserWorkspaces', () => { beforeEach(() => {