mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-10-16 14:57:05 +08:00
- Updated test cases in `providerWeightTransformers.test.ts` to reflect changes in API key structure from 'api-key-entries' to 'keys'. - Introduced new tests in `providerWorkbenchUi.test.ts` to verify the editing surface of provider workbench. - Modified `sponsorCustomEndpoint.test.ts` to adapt to the new API key structure. - Adjusted `visualConfigAntigravitySensitiveWords.test.ts` and `visualConfigConcurrency.test.ts` to accommodate new YAML structure for sensitive words and concurrency settings. - Enhanced `visualConfigDefaults.test.ts` to ensure proper handling of boolean defaults and YAML structure. - Updated `visualConfigDevinSensitiveWords.test.ts` to reflect changes in the YAML structure for sensitive words. - Refined `visualConfigDisableImageGeneration.test.ts` to align with new multimedia settings. - Added comprehensive tests in `visualConfigV8.test.ts` to validate the v8 visual config contract and ensure scalar read/write path parity. - Improved validation tests in `visualConfigValidation.test.ts` to handle new routing and requests structure. - Cleaned up `xaiApiKeyProvider.test.ts` by removing unnecessary API client mocks and focusing on normalization of the xAI API key contract.
106 lines
3.9 KiB
TypeScript
106 lines
3.9 KiB
TypeScript
import { describe, expect, test } from 'bun:test';
|
|
import { parse as parseYaml } from 'yaml';
|
|
import { runVisualConfig } from './helpers/visualConfig';
|
|
|
|
// Backend contract: config_load.go defaults WebsocketAuth to true; QuotaExceeded
|
|
// uses Go's false zero values. config.example.yaml values are not missing-key defaults.
|
|
describe('visual config boolean defaults', () => {
|
|
test('initial and missing-key values agree with backend defaults', () => {
|
|
for (const config of [runVisualConfig(), runVisualConfig('server:\n port: 8317\n')]) {
|
|
expect(config.visualValues.wsAuth).toBe(true);
|
|
expect(config.visualValues.quotaSwitchProject).toBe(false);
|
|
expect(config.visualValues.quotaSwitchPreviewModel).toBe(false);
|
|
expect(config.visualDirty).toBe(false);
|
|
}
|
|
});
|
|
|
|
for (const enabled of [true, false]) {
|
|
test(`preserves explicit boolean values: ${enabled}`, () => {
|
|
const yaml = `quota-exceeded:
|
|
switch-project: ${enabled}
|
|
switch-preview-model: ${enabled}
|
|
oauth:
|
|
providers:
|
|
aistudio:
|
|
ws-auth: ${enabled}
|
|
`;
|
|
const config = runVisualConfig(yaml);
|
|
expect(config.visualValues.wsAuth).toBe(enabled);
|
|
expect(config.visualValues.quotaSwitchProject).toBe(enabled);
|
|
expect(config.visualValues.quotaSwitchPreviewModel).toBe(enabled);
|
|
expect(parseYaml(config.applyVisualChangesToYaml(yaml))).toEqual(parseYaml(yaml));
|
|
});
|
|
}
|
|
|
|
test('writes explicit false when disabling omitted ws-auth', () => {
|
|
const yaml = 'server:\n port: 8317\n';
|
|
const config = runVisualConfig(yaml, [{ wsAuth: false }]);
|
|
expect([...config.visualDirtyFields]).toEqual(['wsAuth']);
|
|
expect(parseYaml(config.applyVisualChangesToYaml(yaml))).toEqual({
|
|
server: { port: 8317 },
|
|
oauth: { providers: { aistudio: { 'ws-auth': false } } },
|
|
});
|
|
});
|
|
|
|
test('writes enabled quota options when their block was omitted', () => {
|
|
const yaml = 'server:\n port: 8317\n';
|
|
const config = runVisualConfig(yaml, [
|
|
{ quotaSwitchProject: true, quotaSwitchPreviewModel: true },
|
|
]);
|
|
expect(parseYaml(config.applyVisualChangesToYaml(yaml))).toEqual({
|
|
server: { port: 8317 },
|
|
'quota-exceeded': { 'switch-project': true, 'switch-preview-model': true },
|
|
});
|
|
});
|
|
|
|
test('writes toggles in both directions without changing unrelated settings', () => {
|
|
for (const enabled of [true, false]) {
|
|
const yaml = `quota-exceeded:
|
|
switch-project: ${!enabled}
|
|
switch-preview-model: ${!enabled}
|
|
oauth:
|
|
providers:
|
|
aistudio:
|
|
ws-auth: ${!enabled}
|
|
antigravity:
|
|
antigravity-credits: true
|
|
`;
|
|
const config = runVisualConfig(yaml, [
|
|
{ wsAuth: enabled, quotaSwitchProject: enabled, quotaSwitchPreviewModel: enabled },
|
|
]);
|
|
expect(parseYaml(config.applyVisualChangesToYaml(yaml))).toEqual({
|
|
oauth: {
|
|
providers: {
|
|
aistudio: { 'ws-auth': enabled },
|
|
antigravity: { 'antigravity-credits': true },
|
|
},
|
|
},
|
|
'quota-exceeded': {
|
|
'switch-project': enabled,
|
|
'switch-preview-model': enabled,
|
|
},
|
|
});
|
|
}
|
|
});
|
|
|
|
test('reverting toggles clears dirty state without inserting missing keys', () => {
|
|
const yaml = 'server:\n port: 8317\n';
|
|
const config = runVisualConfig(yaml, [
|
|
{ wsAuth: false, quotaSwitchProject: true, quotaSwitchPreviewModel: true },
|
|
{ wsAuth: true, quotaSwitchProject: false, quotaSwitchPreviewModel: false },
|
|
]);
|
|
expect(config.visualDirty).toBe(false);
|
|
expect(config.visualDirtyFields.size).toBe(0);
|
|
expect(config.applyVisualChangesToYaml(yaml)).toBe(yaml);
|
|
});
|
|
|
|
test('unrelated edits do not materialize boolean defaults', () => {
|
|
const yaml = 'server:\n port: 8317\n';
|
|
const config = runVisualConfig(yaml, [{ debug: true }]);
|
|
expect(parseYaml(config.applyVisualChangesToYaml(yaml))).toEqual({
|
|
server: { port: 8317 },
|
|
observability: { logs: { debug: true } },
|
|
});
|
|
});
|
|
});
|