chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,77 @@
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'
|
||||
import { useCategories, usePluginPageTabs, useTags } from '../hooks'
|
||||
|
||||
describe('useTags', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should return non-empty tags array with name and label properties', () => {
|
||||
const { result } = renderHook(() => useTags())
|
||||
|
||||
expect(result.current.tags.length).toBeGreaterThan(0)
|
||||
result.current.tags.forEach((tag) => {
|
||||
expect(result.current.tagsMap[tag.name]).toEqual(tag)
|
||||
expect(tag.label).toBe(`pluginTags.tags.${tag.name}`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getTagLabel', () => {
|
||||
it('should return translated label for existing tags', () => {
|
||||
const { result } = renderHook(() => useTags())
|
||||
|
||||
expect(result.current.getTagLabel('agent')).toBe('pluginTags.tags.agent')
|
||||
expect(result.current.getTagLabel('search')).toBe('pluginTags.tags.search')
|
||||
expect(result.current.getTagLabel('rag')).toBe('pluginTags.tags.rag')
|
||||
})
|
||||
|
||||
it('should return the name itself for non-existing tags', () => {
|
||||
const { result } = renderHook(() => useTags())
|
||||
|
||||
expect(result.current.getTagLabel('non-existing')).toBe('non-existing')
|
||||
expect(result.current.getTagLabel('custom-tag')).toBe('custom-tag')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('useCategories', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('isSingle parameter', () => {
|
||||
it('should use plural labels by default', () => {
|
||||
const { result } = renderHook(() => useCategories())
|
||||
|
||||
expect(result.current.categoriesMap.tool!.label).toBe('plugin.category.tools')
|
||||
expect(result.current.categoriesMap['agent-strategy']!.label).toBe('plugin.category.agents')
|
||||
})
|
||||
|
||||
it('should use singular labels when isSingle is true', () => {
|
||||
const { result } = renderHook(() => useCategories(true))
|
||||
|
||||
expect(result.current.categoriesMap.tool!.label).toBe('plugin.categorySingle.tool')
|
||||
expect(result.current.categoriesMap['agent-strategy']!.label).toBe(
|
||||
'plugin.categorySingle.agent',
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('usePluginPageTabs', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('should return two tabs: plugins first, marketplace second', () => {
|
||||
const { result } = renderHook(() => usePluginPageTabs())
|
||||
|
||||
expect(result.current).toHaveLength(2)
|
||||
expect(result.current[0]).toEqual({ value: 'plugins', text: 'navigation.menus.plugins' })
|
||||
expect(result.current[1]).toEqual({
|
||||
value: 'discover',
|
||||
text: 'navigation.menus.exploreMarketplace',
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,161 @@
|
||||
import {
|
||||
getFirstPackageIdFromSearchParams,
|
||||
getInstallRedirectPathByPluginCategory,
|
||||
getInstallRedirectPathFromSearchParams,
|
||||
getLegacyPluginRedirectPath,
|
||||
shouldResolveInstallCategoryRedirect,
|
||||
} from '../plugin-routes'
|
||||
|
||||
describe('plugin routes', () => {
|
||||
it.each([
|
||||
[{}, '/integrations'],
|
||||
[{ tab: 'plugins' }, '/integrations'],
|
||||
[{ tab: ['plugins', 'discover'] }, '/integrations'],
|
||||
])('redirects installed plugin URLs for search params %j', (searchParams, expected) => {
|
||||
expect(getLegacyPluginRedirectPath(searchParams)).toBe(expected)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ tab: 'trigger' }, '/integrations/trigger'],
|
||||
[{ tab: 'agent-strategy' }, '/integrations/agent-strategy'],
|
||||
[{ tab: 'extension' }, '/integrations/extension'],
|
||||
[
|
||||
{
|
||||
tab: 'trigger',
|
||||
'package-ids': '["langgenius/telegram_trigger"]',
|
||||
source: 'https://marketplace.dify.ai',
|
||||
},
|
||||
'/integrations/trigger?package-ids=%5B%22langgenius%2Ftelegram_trigger%22%5D',
|
||||
],
|
||||
])('redirects legacy plugin category URLs for search params %j', (searchParams, expected) => {
|
||||
expect(getLegacyPluginRedirectPath(searchParams)).toBe(expected)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ 'package-ids': '["langgenius/telegram_trigger"]' }, '/integrations'],
|
||||
[{ tab: 'plugins', 'package-ids': '["langgenius/telegram_trigger"]' }, '/integrations'],
|
||||
[{ 'bundle-info': '{"org":"langgenius","name":"bundle","version":"1.0.0"}' }, '/integrations'],
|
||||
])(
|
||||
'redirects unresolved install deep links to integrations for search params %j',
|
||||
(searchParams, expected) => {
|
||||
expect(getLegacyPluginRedirectPath(searchParams)).toBe(expected)
|
||||
},
|
||||
)
|
||||
|
||||
it('parses the first package id from marketplace install search params', () => {
|
||||
expect(
|
||||
getFirstPackageIdFromSearchParams({
|
||||
'package-ids':
|
||||
'["junjiem/mcp_see_agent:0.2.4@82caf96890992e9dec2c43c3fac82bfce8bd18a41de7c2b6948151b2d7f7b7a2"]',
|
||||
}),
|
||||
).toBe(
|
||||
'junjiem/mcp_see_agent:0.2.4@82caf96890992e9dec2c43c3fac82bfce8bd18a41de7c2b6948151b2d7f7b7a2',
|
||||
)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ 'package-ids': '["junjiem/mcp_see_agent"]' }, true],
|
||||
[{ tab: 'plugins', 'package-ids': '["junjiem/mcp_see_agent"]' }, true],
|
||||
[{ tab: 'trigger', 'package-ids': '["langgenius/telegram_trigger"]' }, false],
|
||||
[{ 'bundle-info': '{"org":"langgenius","name":"bundle","version":"1.0.0"}' }, false],
|
||||
])(
|
||||
'detects package install deep links that need category resolution for search params %j',
|
||||
(searchParams, expected) => {
|
||||
expect(shouldResolveInstallCategoryRedirect(searchParams)).toBe(expected)
|
||||
},
|
||||
)
|
||||
|
||||
it.each([
|
||||
[
|
||||
'model',
|
||||
{ 'package-ids': '["langgenius/openai"]' },
|
||||
'/integrations/model-provider?package-ids=%5B%22langgenius%2Fopenai%22%5D',
|
||||
],
|
||||
[
|
||||
'agent-strategy',
|
||||
{ 'package-ids': '["junjiem/mcp_see_agent"]' },
|
||||
'/integrations/agent-strategy?package-ids=%5B%22junjiem%2Fmcp_see_agent%22%5D',
|
||||
],
|
||||
[
|
||||
'trigger',
|
||||
{
|
||||
tab: 'plugins',
|
||||
'package-ids': '["langgenius/telegram_trigger"]',
|
||||
source: 'https://marketplace.dify.ai',
|
||||
},
|
||||
'/integrations/trigger?package-ids=%5B%22langgenius%2Ftelegram_trigger%22%5D',
|
||||
],
|
||||
[
|
||||
'datasource',
|
||||
{ 'package-ids': '["langgenius/notion_datasource"]' },
|
||||
'/integrations/data-source?package-ids=%5B%22langgenius%2Fnotion_datasource%22%5D',
|
||||
],
|
||||
])(
|
||||
'builds install redirect paths from marketplace plugin category %s',
|
||||
(category, searchParams, expected) => {
|
||||
expect(getInstallRedirectPathByPluginCategory(category, searchParams)).toBe(expected)
|
||||
},
|
||||
)
|
||||
|
||||
it.each([
|
||||
[
|
||||
{
|
||||
category: 'agent-strategy',
|
||||
'package-ids': '["junjiem/mcp_see_agent"]',
|
||||
source: 'https://marketplace.dify.ai',
|
||||
},
|
||||
'/integrations/agent-strategy?package-ids=%5B%22junjiem%2Fmcp_see_agent%22%5D',
|
||||
],
|
||||
[
|
||||
{
|
||||
tab: 'trigger',
|
||||
'package-ids': '["langgenius/telegram_trigger"]',
|
||||
source: 'https://marketplace.dify.ai',
|
||||
},
|
||||
'/integrations/trigger?package-ids=%5B%22langgenius%2Ftelegram_trigger%22%5D',
|
||||
],
|
||||
[
|
||||
{
|
||||
category: 'model',
|
||||
'package-ids': '["langgenius/openai"]',
|
||||
source: 'https://marketplace.dify.ai',
|
||||
},
|
||||
'/integrations/model-provider?package-ids=%5B%22langgenius%2Fopenai%22%5D',
|
||||
],
|
||||
[
|
||||
{
|
||||
category: 'datasource',
|
||||
'package-ids': '["langgenius/notion_datasource"]',
|
||||
source: 'https://marketplace.dify.ai',
|
||||
},
|
||||
'/integrations/data-source?package-ids=%5B%22langgenius%2Fnotion_datasource%22%5D',
|
||||
],
|
||||
[{ category: 'bundle', 'package-ids': '["langgenius/bundle"]' }, undefined],
|
||||
[{ category: 'agent-strategy' }, undefined],
|
||||
])(
|
||||
'builds install redirect paths directly from install search params %j',
|
||||
(searchParams, expected) => {
|
||||
expect(getInstallRedirectPathFromSearchParams(searchParams)).toBe(expected)
|
||||
},
|
||||
)
|
||||
|
||||
it.each([
|
||||
[{ tab: 'discover' }, '/marketplace'],
|
||||
[{ tab: 'discover', category: 'extension' }, '/marketplace?category=extension'],
|
||||
[{ tab: 'discover', q: 'slack', tags: ['a', 'b'] }, '/marketplace?q=slack&tags=a&tags=b'],
|
||||
[{ tab: 'all' }, '/marketplace?category=all'],
|
||||
[{ tab: 'tool' }, '/marketplace?category=tool'],
|
||||
[{ tab: 'model' }, '/marketplace?category=model'],
|
||||
[{ tab: 'datasource' }, '/marketplace?category=datasource'],
|
||||
[{ tab: 'bundle' }, '/marketplace?category=bundle'],
|
||||
])('redirects marketplace plugin URLs for search params %j', (searchParams, expected) => {
|
||||
expect(getLegacyPluginRedirectPath(searchParams)).toBe(expected)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[{ tab: 'unsupported' }, '/integrations'],
|
||||
[{ tab: 'toString' }, '/integrations'],
|
||||
])('redirects unsupported plugin URLs for search params %j', (searchParams, expected) => {
|
||||
expect(getLegacyPluginRedirectPath(searchParams)).toBe(expected)
|
||||
})
|
||||
})
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
import type { PluginDetail } from '../types'
|
||||
import { waitFor } from '@testing-library/react'
|
||||
import { renderHookWithConsoleQuery as renderHook } from '@/test/console/query-data'
|
||||
import { usePluginsWithLatestVersion } from '../hooks'
|
||||
import { PluginSource } from '../types'
|
||||
const getVersions = vi.hoisted(() => vi.fn())
|
||||
vi.mock('@/service/console', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/service/console')>()
|
||||
const { withConsoleResponses } = await import('@/test/console/service-responses')
|
||||
return {
|
||||
...actual,
|
||||
consoleQuery: withConsoleResponses(actual.consoleQuery, {
|
||||
'workspaces.current.plugin.list.latestVersions.post': getVersions,
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
const createPlugin = (overrides: Partial<PluginDetail> = {}): PluginDetail => ({
|
||||
id: 'plugin-1',
|
||||
created_at: '2026-01-01T00:00:00Z',
|
||||
updated_at: '2026-01-01T00:00:00Z',
|
||||
name: 'demo-plugin',
|
||||
plugin_id: 'plugin-1',
|
||||
plugin_unique_identifier: 'plugin-1@1.0.0',
|
||||
declaration: {} as PluginDetail['declaration'],
|
||||
installation_id: 'installation-1',
|
||||
tenant_id: 'tenant-1',
|
||||
endpoints_setups: 0,
|
||||
endpoints_active: 0,
|
||||
version: '1.0.0',
|
||||
latest_version: '1.0.0',
|
||||
latest_unique_identifier: 'plugin-1@1.0.0',
|
||||
source: PluginSource.marketplace,
|
||||
meta: undefined,
|
||||
status: 'active',
|
||||
deprecated_reason: '',
|
||||
alternative_plugin_id: '',
|
||||
...overrides,
|
||||
})
|
||||
|
||||
describe('usePluginsWithLatestVersion', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
getVersions.mockReset().mockImplementation(() => new Promise(() => {}))
|
||||
})
|
||||
|
||||
it('should disable latest-version querying when there are no marketplace plugins', () => {
|
||||
const plugins = [createPlugin({ plugin_id: 'github-plugin', source: PluginSource.github })]
|
||||
|
||||
const { result } = renderHook(() => usePluginsWithLatestVersion(plugins))
|
||||
|
||||
expect(getVersions).not.toHaveBeenCalled()
|
||||
expect(result.current).toEqual(plugins)
|
||||
})
|
||||
|
||||
it('should return the original plugins when version data is unavailable', () => {
|
||||
const plugins = [createPlugin()]
|
||||
|
||||
const { result } = renderHook(() => usePluginsWithLatestVersion(plugins))
|
||||
|
||||
expect(result.current).toEqual(plugins)
|
||||
})
|
||||
|
||||
it('should keep plugins unchanged when a plugin has no matching latest version', async () => {
|
||||
const plugins = [createPlugin()]
|
||||
getVersions.mockResolvedValue({ versions: {} })
|
||||
|
||||
const { result, queryClient } = renderHook(() => usePluginsWithLatestVersion(plugins))
|
||||
|
||||
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
||||
expect(result.current).toEqual(plugins)
|
||||
})
|
||||
|
||||
it('should merge latest version fields for marketplace plugins with version data', async () => {
|
||||
const plugins = [
|
||||
createPlugin(),
|
||||
createPlugin({
|
||||
id: 'plugin-2',
|
||||
plugin_id: 'plugin-2',
|
||||
plugin_unique_identifier: 'plugin-2@1.0.0',
|
||||
latest_version: '1.0.0',
|
||||
latest_unique_identifier: 'plugin-2@1.0.0',
|
||||
source: PluginSource.github,
|
||||
}),
|
||||
]
|
||||
getVersions.mockResolvedValue({
|
||||
versions: {
|
||||
'plugin-1': {
|
||||
version: '1.1.0',
|
||||
unique_identifier: 'plugin-1@1.1.0',
|
||||
status: 'deleted',
|
||||
deprecated_reason: 'replaced',
|
||||
alternative_plugin_id: 'plugin-3',
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const { result } = renderHook(() => usePluginsWithLatestVersion(plugins))
|
||||
|
||||
await waitFor(() => expect(result.current[0]?.latest_version).toBe('1.1.0'))
|
||||
expect(getVersions).toHaveBeenCalledWith({ body: { plugin_ids: ['plugin-1'] } })
|
||||
expect(result.current).toEqual([
|
||||
expect.objectContaining({
|
||||
plugin_id: 'plugin-1',
|
||||
latest_version: '1.1.0',
|
||||
latest_unique_identifier: 'plugin-1@1.1.0',
|
||||
status: 'deleted',
|
||||
deprecated_reason: 'replaced',
|
||||
alternative_plugin_id: 'plugin-3',
|
||||
}),
|
||||
plugins[1],
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,55 @@
|
||||
import type { Plugin } from '../types'
|
||||
import { describe, expect, it } from 'vite-plus/test'
|
||||
import { API_PREFIX } from '@/config'
|
||||
import { MARKETPLACE_API_PREFIX } from '@/features/marketplace/api'
|
||||
import { getPluginCardIconUrl } from '../utils'
|
||||
|
||||
const createPlugin = (
|
||||
overrides: Partial<Pick<Plugin, 'from' | 'name' | 'org' | 'type'>> = {},
|
||||
): Pick<Plugin, 'from' | 'name' | 'org' | 'type'> => ({
|
||||
from: 'github',
|
||||
name: 'demo-plugin',
|
||||
org: 'langgenius',
|
||||
type: 'plugin',
|
||||
...overrides,
|
||||
})
|
||||
|
||||
describe('plugins/utils', () => {
|
||||
describe('getPluginCardIconUrl', () => {
|
||||
it('returns an empty string when icon is missing', () => {
|
||||
expect(getPluginCardIconUrl(createPlugin(), undefined, 'tenant-1')).toBe('')
|
||||
})
|
||||
|
||||
it('returns absolute urls and root-relative urls as-is', () => {
|
||||
expect(getPluginCardIconUrl(createPlugin(), 'https://example.com/icon.png', 'tenant-1')).toBe(
|
||||
'https://example.com/icon.png',
|
||||
)
|
||||
expect(getPluginCardIconUrl(createPlugin(), '/icons/demo.png', 'tenant-1')).toBe(
|
||||
'/icons/demo.png',
|
||||
)
|
||||
})
|
||||
|
||||
it('builds the marketplace icon url for plugins and bundles', () => {
|
||||
expect(
|
||||
getPluginCardIconUrl(createPlugin({ from: 'marketplace' }), 'icon.png', 'tenant-1'),
|
||||
).toBe(`${MARKETPLACE_API_PREFIX}/plugins/langgenius/demo-plugin/icon`)
|
||||
expect(
|
||||
getPluginCardIconUrl(
|
||||
createPlugin({ from: 'marketplace', type: 'bundle' }),
|
||||
'icon.png',
|
||||
'tenant-1',
|
||||
),
|
||||
).toBe(`${MARKETPLACE_API_PREFIX}/bundles/langgenius/demo-plugin/icon`)
|
||||
})
|
||||
|
||||
it('falls back to the raw icon when tenant id is missing for non-marketplace plugins', () => {
|
||||
expect(getPluginCardIconUrl(createPlugin(), 'icon.png', '')).toBe('icon.png')
|
||||
})
|
||||
|
||||
it('builds the workspace icon url for tenant-scoped plugins', () => {
|
||||
expect(getPluginCardIconUrl(createPlugin(), 'icon.png', 'tenant-1')).toBe(
|
||||
`${API_PREFIX}/workspaces/current/plugin/icon?tenant_id=tenant-1&filename=icon.png`,
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user