mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-03 13:12:09 +00:00
feat(cliproxy): add meetsBackendMinimumVersion comparator helper
This commit is contained in:
1 parent
485c436958
commit
3658c01137
2 files changed
+51
-1
No files matched your search
@@ -1,6 +1,11 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
|
||||
import { compareCliproxyVersions, isNewerVersion } from '../version-checker';
|
||||
import {
|
||||
type CLIProxyBackendMinVersions,
|
||||
compareCliproxyVersions,
|
||||
isNewerVersion,
|
||||
meetsBackendMinimumVersion,
|
||||
} from '../version-checker';
|
||||
|
||||
describe('cliproxy version comparison', () => {
|
||||
it('treats missing fork release suffix as zero', () => {
|
||||
@@ -19,3 +24,38 @@ describe('cliproxy version comparison', () => {
|
||||
expect(isNewerVersion('7.1.31-99', '7.1.32-0')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('meetsBackendMinimumVersion', () => {
|
||||
const testMinimums: CLIProxyBackendMinVersions = {
|
||||
original: '7.2.104',
|
||||
plus: '7.2.105-0',
|
||||
};
|
||||
|
||||
it('evaluates original backend boundary correctly', () => {
|
||||
expect(meetsBackendMinimumVersion('7.2.103', 'original', testMinimums)).toBe(false);
|
||||
expect(meetsBackendMinimumVersion('7.2.104', 'original', testMinimums)).toBe(true);
|
||||
expect(meetsBackendMinimumVersion('7.2.105', 'original', testMinimums)).toBe(true);
|
||||
});
|
||||
|
||||
it('evaluates plus backend boundary with fork suffixes correctly', () => {
|
||||
expect(meetsBackendMinimumVersion('7.2.104-9', 'plus', testMinimums)).toBe(false);
|
||||
expect(meetsBackendMinimumVersion('7.2.105-0', 'plus', testMinimums)).toBe(true);
|
||||
expect(meetsBackendMinimumVersion('7.2.105-1', 'plus', testMinimums)).toBe(true);
|
||||
});
|
||||
|
||||
it('treats missing fork suffix as equal to -0', () => {
|
||||
const minWithSuffix: CLIProxyBackendMinVersions = {
|
||||
original: '6.8.34-0',
|
||||
plus: '6.8.34-0',
|
||||
};
|
||||
expect(meetsBackendMinimumVersion('6.8.34', 'original', minWithSuffix)).toBe(true);
|
||||
expect(meetsBackendMinimumVersion('6.8.34', 'plus', minWithSuffix)).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects empty and invalid version strings against real minimums', () => {
|
||||
expect(meetsBackendMinimumVersion('', 'original', testMinimums)).toBe(false);
|
||||
expect(meetsBackendMinimumVersion('not-a-version', 'original', testMinimums)).toBe(false);
|
||||
expect(meetsBackendMinimumVersion('', 'plus', testMinimums)).toBe(false);
|
||||
expect(meetsBackendMinimumVersion('not-a-version', 'plus', testMinimums)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -21,6 +21,8 @@ import {
|
||||
} from '../binary/platform-detector';
|
||||
import type { CLIProxyBackend } from '../types';
|
||||
|
||||
export type CLIProxyBackendMinVersions = Readonly<Record<CLIProxyBackend, string>>;
|
||||
|
||||
interface FetchLatestVersionDeps {
|
||||
fetchJsonFn?: typeof fetchJson;
|
||||
}
|
||||
@@ -78,6 +80,14 @@ export function isNewerVersion(latest: string, current: string): boolean {
|
||||
return compareCliproxyVersions(latest, current) > 0;
|
||||
}
|
||||
|
||||
export function meetsBackendMinimumVersion(
|
||||
installedVersion: string,
|
||||
backend: CLIProxyBackend,
|
||||
minimumByBackend: CLIProxyBackendMinVersions
|
||||
): boolean {
|
||||
return compareCliproxyVersions(installedVersion, minimumByBackend[backend]) >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if version is within the faulty range (v81-85)
|
||||
* @returns true if version has known critical bugs
|
||||
|
||||
Reference in new issue
Block a user