Skip to content

Commit 5195f91

Browse files
committed
feat(copilot): mark current workspace in workspace list
1 parent 88b4f4c commit 5195f91

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ const {
1111
getEffectiveBlockOutputPathsMock,
1212
hasTriggerCapabilityMock,
1313
getBlockMock,
14+
listUserWorkspacesMock,
1415
} = vi.hoisted(() => ({
1516
ensureWorkflowAccessMock: vi.fn(),
1617
getEffectiveBlockOutputPathsMock: vi.fn(),
1718
hasTriggerCapabilityMock: vi.fn(),
1819
getBlockMock: vi.fn(),
20+
listUserWorkspacesMock: vi.fn(),
1921
}))
2022

2123
const loadWorkflowFromNormalizedTablesMock =
@@ -44,7 +46,51 @@ vi.mock('@/blocks/registry', () => ({
4446

4547
vi.mock('@/lib/workflows/utils', () => workflowsUtilsMock)
4648

47-
import { executeGetBlockOutputs } from './queries'
49+
vi.mock('@/lib/workspaces/utils', () => ({
50+
listUserWorkspaces: listUserWorkspacesMock,
51+
}))
52+
53+
import { executeGetBlockOutputs, executeListUserWorkspaces } from './queries'
54+
55+
describe('executeListUserWorkspaces', () => {
56+
beforeEach(() => {
57+
vi.clearAllMocks()
58+
})
59+
60+
it('marks the current workspace in the accessible workspace list', async () => {
61+
listUserWorkspacesMock.mockResolvedValue([
62+
{ workspaceId: 'workspace-1', workspaceName: 'One', role: 'owner' },
63+
{ workspaceId: 'workspace-2', workspaceName: 'Two', role: 'read' },
64+
])
65+
66+
const result = await executeListUserWorkspaces({
67+
userId: 'user-1',
68+
workflowId: 'workflow-1',
69+
workspaceId: 'workspace-2',
70+
})
71+
72+
expect(listUserWorkspacesMock).toHaveBeenCalledWith('user-1')
73+
expect(result).toEqual({
74+
success: true,
75+
output: {
76+
workspaces: [
77+
{
78+
workspaceId: 'workspace-1',
79+
workspaceName: 'One',
80+
role: 'owner',
81+
isCurrent: false,
82+
},
83+
{
84+
workspaceId: 'workspace-2',
85+
workspaceName: 'Two',
86+
role: 'read',
87+
isCurrent: true,
88+
},
89+
],
90+
},
91+
})
92+
})
93+
})
4894

4995
describe('executeGetBlockOutputs', () => {
5096
beforeEach(() => {

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

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

3740
return { success: true, output: { workspaces } }
3841
} catch (error) {

0 commit comments

Comments
 (0)