Files
Cli-Proxy-API-Management-Ce…/tests/providerExcludedModelsDisableRule.test.ts
T
Supra4E8C 4abd41f947 refactor: streamline excluded models management and enhance localization
- Removed deprecated localization keys related to excluded models in zh-TW.json.
- Introduced a new structure for excluded models with improved UI components.
- Refactored AuthFilesOAuthExcludedEditPage to utilize ExcludedModelsPicker for better handling of model exclusions.
- Consolidated styles in AuthFilesOAuthExcludedEditPage.module.scss by removing unused classes.
- Added comprehensive tests for excluded model rules and their matching logic.
- Deleted obsolete tests for OAuth excluded rules and replaced them with more relevant tests for the new structure.
- Ensured that the disabled state of providers is correctly managed and reflected in the UI.
2026-07-31 07:42:56 +08:00

41 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, test } from 'bun:test';
import { buildExcludedModels } from '../src/features/providers/useProviderWorkbench';
/**
* `excluded-models: ['*']` 是「该 provider 已停用」的后端编码。
* 它的唯一所有者是表单的 `disabled` 开关:载入时被剥离进该 flag,保存时仅凭该 flag 重新追加。
*
* 这些断言把该不变量钉死,好让排除模型的编辑面(textarea → ExcludedModelsPicker
* 无论怎么重写都不可能污染停用语义。
*/
describe('buildExcludedModels — the "*" disable-rule invariant', () => {
test('appends "*" when disabled', () => {
expect(buildExcludedModels('a\nb', true, 'gemini')).toEqual(['a', 'b', '*']);
});
test('omits "*" when not disabled', () => {
expect(buildExcludedModels('a\nb', false, 'gemini')).toEqual(['a', 'b']);
});
test('a hand-typed "*" never duplicates the disable rule', () => {
expect(buildExcludedModels('a\n*\nb', true, 'gemini')).toEqual(['a', 'b', '*']);
});
test('a hand-typed "*" never switches the provider to disabled', () => {
expect(buildExcludedModels('a\n*\nb', false, 'gemini')).toEqual(['a', 'b']);
});
test('disabled with no rules yields exactly the disable rule', () => {
expect(buildExcludedModels('', true, 'gemini')).toEqual(['*']);
});
test('no rules and not disabled yields undefined, not an empty array', () => {
expect(buildExcludedModels('', false, 'gemini')).toBeUndefined();
});
test('openaiCompatibility never receives the disable rule', () => {
expect(buildExcludedModels('a', true, 'openaiCompatibility')).toEqual(['a']);
expect(buildExcludedModels('', true, 'openaiCompatibility')).toBeUndefined();
});
});