|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 5 | + |
| 6 | +vi.mock('@/blocks/registry-maps', () => ({ |
| 7 | + BLOCK_REGISTRY: { |
| 8 | + svc: { |
| 9 | + type: 'svc', |
| 10 | + tools: { access: ['svc_send_v2'] }, |
| 11 | + }, |
| 12 | + // Preview successor sharing the released block's tools (the slack/slack_v2 |
| 13 | + // paradigm) — must not become the owner of the shared tools. |
| 14 | + svc_v2: { |
| 15 | + type: 'svc_v2', |
| 16 | + preview: true, |
| 17 | + tools: { access: ['svc_send_v2'] }, |
| 18 | + }, |
| 19 | + // Preview block with tools of its own — stays preview-owned and gated. |
| 20 | + newsvc: { |
| 21 | + type: 'newsvc', |
| 22 | + preview: true, |
| 23 | + tools: { access: ['newsvc_do_v1'] }, |
| 24 | + }, |
| 25 | + }, |
| 26 | +})) |
| 27 | + |
| 28 | +vi.mock('@/tools/registry', () => ({ |
| 29 | + tools: { |
| 30 | + svc_send_v1: { name: 'Send (legacy)' }, |
| 31 | + svc_send_v2: { name: 'Send' }, |
| 32 | + newsvc_do_v1: { name: 'Do' }, |
| 33 | + }, |
| 34 | +})) |
| 35 | + |
| 36 | +import { |
| 37 | + filterExposedIntegrationTools, |
| 38 | + getExposedIntegrationTools, |
| 39 | + resetExposedIntegrationToolsCache, |
| 40 | +} from '@/lib/copilot/integration-tools' |
| 41 | + |
| 42 | +describe('getExposedIntegrationTools', () => { |
| 43 | + beforeEach(() => { |
| 44 | + resetExposedIntegrationToolsCache() |
| 45 | + }) |
| 46 | + |
| 47 | + it('keeps the released block as owner of tools a preview block shares', () => { |
| 48 | + const send = getExposedIntegrationTools().find((t) => t.toolId === 'svc_send_v2') |
| 49 | + expect(send).toBeDefined() |
| 50 | + expect(send?.blockType).toBe('svc') |
| 51 | + expect(send?.preview).toBeFalsy() |
| 52 | + }) |
| 53 | + |
| 54 | + it('exposes shared tools to viewers without the preview reveal, but not preview-only tools', () => { |
| 55 | + const visible = filterExposedIntegrationTools(getExposedIntegrationTools(), null) |
| 56 | + expect(visible.some((t) => t.toolId === 'svc_send_v2')).toBe(true) |
| 57 | + expect(visible.some((t) => t.toolId === 'newsvc_do_v1')).toBe(false) |
| 58 | + }) |
| 59 | + |
| 60 | + it('exposes only the latest version of each tool', () => { |
| 61 | + const exposed = getExposedIntegrationTools() |
| 62 | + expect(exposed.some((t) => t.toolId === 'svc_send_v1')).toBe(false) |
| 63 | + expect(exposed.some((t) => t.toolId === 'svc_send_v2')).toBe(true) |
| 64 | + }) |
| 65 | +}) |
0 commit comments