Skip to content

Commit 2ef1572

Browse files
committed
feat(copilot): identify current workspace in workspace list
1 parent 23318a1 commit 2ef1572

2 files changed

Lines changed: 51 additions & 3 deletions

File tree

apps/sim/lib/copilot/tools/handlers/workflow/queries.test.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { getErrorMessage } from '@sim/utils/errors'
22
import { beforeEach, describe, expect, it, vi } from 'vitest'
33
import type { ExecutionContext } from '@/lib/copilot/request/types'
44

5-
const { executeWorkflowUseCaseMock } = vi.hoisted(() => ({
5+
const { executeWorkflowUseCaseMock, listUserWorkspacesMock } = vi.hoisted(() => ({
66
executeWorkflowUseCaseMock: vi.fn(),
7+
listUserWorkspacesMock: vi.fn(),
78
}))
89

910
vi.mock('@/lib/copilot/application/execute-workflow-use-case', () => ({
@@ -12,7 +13,51 @@ vi.mock('@/lib/copilot/application/execute-workflow-use-case', () => ({
1213
getErrorMessage(error, 'Workflow operation failed'),
1314
}))
1415

15-
import { executeGetBlockOutputs } from './queries'
16+
vi.mock('@/lib/workspaces/utils', () => ({
17+
listUserWorkspaces: listUserWorkspacesMock,
18+
}))
19+
20+
import { executeGetBlockOutputs, executeListUserWorkspaces } from './queries'
21+
22+
describe('executeListUserWorkspaces', () => {
23+
beforeEach(() => {
24+
vi.clearAllMocks()
25+
})
26+
27+
it('marks the current workspace in the accessible workspace list', async () => {
28+
listUserWorkspacesMock.mockResolvedValue([
29+
{ workspaceId: 'workspace-1', workspaceName: 'One', role: 'owner' },
30+
{ workspaceId: 'workspace-2', workspaceName: 'Two', role: 'read' },
31+
])
32+
33+
const result = await executeListUserWorkspaces({
34+
userId: 'user-1',
35+
workflowId: 'workflow-1',
36+
workspaceId: 'workspace-2',
37+
})
38+
39+
expect(listUserWorkspacesMock).toHaveBeenCalledWith('user-1')
40+
expect(result).toEqual({
41+
success: true,
42+
output: {
43+
workspaces: [
44+
{
45+
workspaceId: 'workspace-1',
46+
workspaceName: 'One',
47+
role: 'owner',
48+
isCurrent: false,
49+
},
50+
{
51+
workspaceId: 'workspace-2',
52+
workspaceName: 'Two',
53+
role: 'read',
54+
isCurrent: true,
55+
},
56+
],
57+
},
58+
})
59+
})
60+
})
1661

1762
describe('executeGetBlockOutputs', () => {
1863
beforeEach(() => {

apps/sim/lib/copilot/tools/handlers/workflow/queries.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ export async function executeListUserWorkspaces(
3434
context: ExecutionContext
3535
): Promise<ToolCallResult> {
3636
try {
37-
const workspaces = await listUserWorkspaces(context.userId)
37+
const workspaces = (await listUserWorkspaces(context.userId)).map((workspace) => ({
38+
...workspace,
39+
isCurrent: workspace.workspaceId === context.workspaceId,
40+
}))
3841

3942
return { success: true, output: { workspaces } }
4043
} catch (error) {

0 commit comments

Comments
 (0)