|
1 | 1 | /** |
2 | 2 | * @vitest-environment node |
3 | 3 | */ |
4 | | -import { envFlagsMockFns, resetEnvFlagsMock, workflowsUtilsMock } from '@sim/testing' |
| 4 | +import { envFlagsMockFns, resetEnvFlagsMock, setEnvFlags, workflowsUtilsMock } from '@sim/testing' |
5 | 5 | import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 6 | +import { getExposedIntegrationTools } from '@/lib/integrations/tool-catalog' |
6 | 7 | import { ChatPayloadSchema } from '@/lib/mothership/generated/protocol' |
| 8 | +import { searchIssuesV2Tool } from '@/tools/github/search_issues' |
7 | 9 |
|
8 | 10 | const { |
9 | 11 | mockCreateUserToolSchema, |
@@ -149,13 +151,15 @@ vi.mock('@/tools/params', () => ({ |
149 | 151 |
|
150 | 152 | vi.mock('@/tools/metadata', () => ({ |
151 | 153 | getToolMetadata: (id: string) => |
152 | | - id === 'gmail_send' |
153 | | - ? { |
154 | | - id, |
155 | | - params: { accessToken: { type: 'string', visibility: 'hidden', required: true } }, |
156 | | - oauth: { required: true, provider: 'google-email' }, |
157 | | - } |
158 | | - : undefined, |
| 154 | + id === 'github_search_issues_v2' |
| 155 | + ? searchIssuesV2Tool |
| 156 | + : id === 'gmail_send' |
| 157 | + ? { |
| 158 | + id, |
| 159 | + params: { accessToken: { type: 'string', visibility: 'hidden', required: true } }, |
| 160 | + oauth: { required: true, provider: 'google-email' }, |
| 161 | + } |
| 162 | + : undefined, |
159 | 163 | })) |
160 | 164 |
|
161 | 165 | vi.mock('@/lib/uploads/contexts/workspace/workspace-file-manager', () => ({ |
@@ -635,6 +639,43 @@ describe('Assistant payload', () => { |
635 | 639 | mockCreateUserToolSchema.mockReturnValue({ type: 'object', properties: {} }) |
636 | 640 | mockSearchApprovals.mockResolvedValue(new Map()) |
637 | 641 | }) |
| 642 | + it('discovers the existing GitHub PR-count tool with a personal credential in live Search', async () => { |
| 643 | + clearIntegrationToolSchemaCacheForTests() |
| 644 | + setEnvFlags({ isLiveEnterpriseSearchEnabled: true }) |
| 645 | + mockSearchApprovals.mockResolvedValue(new Map([['github', true]])) |
| 646 | + vi.mocked(getExposedIntegrationTools).mockReturnValueOnce([ |
| 647 | + { |
| 648 | + toolId: searchIssuesV2Tool.id, |
| 649 | + config: searchIssuesV2Tool, |
| 650 | + service: 'github', |
| 651 | + operation: 'search_issues', |
| 652 | + blockType: 'github_v2', |
| 653 | + owners: [{ service: 'github', blockType: 'github_v2' }], |
| 654 | + }, |
| 655 | + ]) |
| 656 | + const actualParams = await vi.importActual<typeof import('@/tools/params')>('@/tools/params') |
| 657 | + mockCreateUserToolSchema.mockImplementationOnce(actualParams.createUserToolSchema) |
| 658 | + const tools = await buildIntegrationToolSchemas('github-live-person', { |
| 659 | + schemaSurface: 'copilot', |
| 660 | + personalAccountsOnly: true, |
| 661 | + organizationId: 'org', |
| 662 | + }) |
| 663 | + expect(tools).toHaveLength(1) |
| 664 | + expect(tools[0]).toMatchObject({ |
| 665 | + name: 'github_search_issues_v2', |
| 666 | + oauth: { provider: 'github-repositories' }, |
| 667 | + input_schema: { required: expect.arrayContaining(['q', 'credentialId']) }, |
| 668 | + }) |
| 669 | + expect(tools[0].input_schema.properties).not.toHaveProperty('apiKey') |
| 670 | + mockSearchApprovals.mockResolvedValue(new Map([['github', false]])) |
| 671 | + expect( |
| 672 | + await buildIntegrationToolSchemas('github-live-person', { |
| 673 | + schemaSurface: 'copilot', |
| 674 | + personalAccountsOnly: true, |
| 675 | + organizationId: 'org', |
| 676 | + }) |
| 677 | + ).toEqual([]) |
| 678 | + }) |
638 | 679 | it('advertises approved personal organization integrations and rechecks revocation', async () => { |
639 | 680 | mockSearchApprovals.mockResolvedValue(new Map([['gmail', true]])) |
640 | 681 | const options = { |
|
0 commit comments