feat: the frontend part of mcp (#22131)

Co-authored-by: jZonG <jzongcode@gmail.com>
Co-authored-by: Novice <novice12185727@gmail.com>
Co-authored-by: nite-knite <nkCoding@gmail.com>
Co-authored-by: Hanqing Zhao <sherry9277@gmail.com>
This commit is contained in:
Joel
2025-07-10 14:14:02 +08:00
committed by GitHub
parent 535fff62f3
commit 5375d9bb27
152 changed files with 6340 additions and 695 deletions

View File

@@ -0,0 +1,26 @@
import { isSupportMCP } from './plugin-version-feature'
describe('plugin-version-feature', () => {
beforeEach(() => {
jest.clearAllMocks()
})
describe('isSupportMCP', () => {
it('should call isEqualOrLaterThanVersion with the correct parameters', () => {
expect(isSupportMCP('0.0.3')).toBe(true)
expect(isSupportMCP('1.0.0')).toBe(true)
})
it('should return true when version is equal to the supported MCP version', () => {
const mockVersion = '0.0.2'
const result = isSupportMCP(mockVersion)
expect(result).toBe(true)
})
it('should return false when version is less than the supported MCP version', () => {
const mockVersion = '0.0.1'
const result = isSupportMCP(mockVersion)
expect(result).toBe(false)
})
})
})

View File

@@ -0,0 +1,10 @@
import { isEqualOrLaterThanVersion } from './semver'
const SUPPORT_MCP_VERSION = '0.0.2'
export const isSupportMCP = (version?: string): boolean => {
if (!version)
return false
return isEqualOrLaterThanVersion(version, SUPPORT_MCP_VERSION)
}

75
web/utils/semver.spec.ts Normal file
View File

@@ -0,0 +1,75 @@
import { compareVersion, getLatestVersion, isEqualOrLaterThanVersion } from './semver'
describe('semver utilities', () => {
describe('getLatestVersion', () => {
it('should return the latest version from a list of versions', () => {
expect(getLatestVersion(['1.0.0', '1.1.0', '1.0.1'])).toBe('1.1.0')
expect(getLatestVersion(['2.0.0', '1.9.9', '1.10.0'])).toBe('2.0.0')
expect(getLatestVersion(['1.0.0-alpha', '1.0.0-beta', '1.0.0'])).toBe('1.0.0')
})
it('should handle patch versions correctly', () => {
expect(getLatestVersion(['1.0.1', '1.0.2', '1.0.0'])).toBe('1.0.2')
expect(getLatestVersion(['1.0.10', '1.0.9', '1.0.11'])).toBe('1.0.11')
})
it('should handle mixed version formats', () => {
expect(getLatestVersion(['v1.0.0', '1.1.0', 'v1.2.0'])).toBe('v1.2.0')
expect(getLatestVersion(['1.0.0-rc.1', '1.0.0', '1.0.0-beta'])).toBe('1.0.0')
})
it('should return the only version if only one version is provided', () => {
expect(getLatestVersion(['1.0.0'])).toBe('1.0.0')
})
})
describe('compareVersion', () => {
it('should return 1 when first version is greater', () => {
expect(compareVersion('1.1.0', '1.0.0')).toBe(1)
expect(compareVersion('2.0.0', '1.9.9')).toBe(1)
expect(compareVersion('1.0.1', '1.0.0')).toBe(1)
})
it('should return -1 when first version is less', () => {
expect(compareVersion('1.0.0', '1.1.0')).toBe(-1)
expect(compareVersion('1.9.9', '2.0.0')).toBe(-1)
expect(compareVersion('1.0.0', '1.0.1')).toBe(-1)
})
it('should return 0 when versions are equal', () => {
expect(compareVersion('1.0.0', '1.0.0')).toBe(0)
expect(compareVersion('2.1.3', '2.1.3')).toBe(0)
})
it('should handle pre-release versions correctly', () => {
expect(compareVersion('1.0.0-beta', '1.0.0-alpha')).toBe(1)
expect(compareVersion('1.0.0', '1.0.0-beta')).toBe(1)
expect(compareVersion('1.0.0-alpha', '1.0.0-beta')).toBe(-1)
})
})
describe('isEqualOrLaterThanVersion', () => {
it('should return true when baseVersion is greater than targetVersion', () => {
expect(isEqualOrLaterThanVersion('1.1.0', '1.0.0')).toBe(true)
expect(isEqualOrLaterThanVersion('2.0.0', '1.9.9')).toBe(true)
expect(isEqualOrLaterThanVersion('1.0.1', '1.0.0')).toBe(true)
})
it('should return true when baseVersion is equal to targetVersion', () => {
expect(isEqualOrLaterThanVersion('1.0.0', '1.0.0')).toBe(true)
expect(isEqualOrLaterThanVersion('2.1.3', '2.1.3')).toBe(true)
})
it('should return false when baseVersion is less than targetVersion', () => {
expect(isEqualOrLaterThanVersion('1.0.0', '1.1.0')).toBe(false)
expect(isEqualOrLaterThanVersion('1.9.9', '2.0.0')).toBe(false)
expect(isEqualOrLaterThanVersion('1.0.0', '1.0.1')).toBe(false)
})
it('should handle pre-release versions correctly', () => {
expect(isEqualOrLaterThanVersion('1.0.0', '1.0.0-beta')).toBe(true)
expect(isEqualOrLaterThanVersion('1.0.0-beta', '1.0.0-alpha')).toBe(true)
expect(isEqualOrLaterThanVersion('1.0.0-alpha', '1.0.0')).toBe(false)
})
})
})

View File

@@ -7,3 +7,7 @@ export const getLatestVersion = (versionList: string[]) => {
export const compareVersion = (v1: string, v2: string) => {
return semver.compare(v1, v2)
}
export const isEqualOrLaterThanVersion = (baseVersion: string, targetVersion: string) => {
return semver.gte(baseVersion, targetVersion)
}