From 7f14c565df8d629d92ba85e4b430db7ac0b9bbc4 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Sat, 25 Apr 2026 11:30:44 -0400 Subject: [PATCH] test: cover --extra-models parsing and CLIProxy sync dedup --- tests/unit/cliproxy/profile-mapper.test.ts | 42 ++++++++++++++++++++ tests/unit/commands/api-command-args.test.ts | 18 +++++++++ 2 files changed, 60 insertions(+) diff --git a/tests/unit/cliproxy/profile-mapper.test.ts b/tests/unit/cliproxy/profile-mapper.test.ts index c95f2c71..92f688ff 100644 --- a/tests/unit/cliproxy/profile-mapper.test.ts +++ b/tests/unit/cliproxy/profile-mapper.test.ts @@ -74,6 +74,48 @@ describe('Profile Mapper', () => { assert.ok(result); assert.strictEqual(result['base-url'], undefined); }); + + it('appends ANTHROPIC_EXTRA_MODELS as additional models, deduped against primary and each other', () => { + const profile = { + name: 'dashscope', + settingsPath: '/path', + isConfigured: true, + env: { + ANTHROPIC_AUTH_TOKEN: 'sk-test', + ANTHROPIC_BASE_URL: 'https://api.example.com', + ANTHROPIC_MODEL: 'qwen3-coder-plus', + // Includes whitespace, empty entries, a duplicate of the primary + // model, and a repeated extra entry — all should be cleaned up. + ANTHROPIC_EXTRA_MODELS: ' glm-4.6 , kimi-k2 , ,qwen3-coder-plus, kimi-k2 ', + }, + }; + const result = profileMapper.mapProfileToClaudeKey(profile); + + assert.ok(result, 'Should return ClaudeKey'); + assert.deepStrictEqual(result.models, [ + { name: 'qwen3-coder-plus', alias: '' }, + { name: 'glm-4.6', alias: '' }, + { name: 'kimi-k2', alias: '' }, + ]); + }); + + it('ignores empty ANTHROPIC_EXTRA_MODELS', () => { + const profile = { + name: 'test', + settingsPath: '/path', + isConfigured: true, + env: { + ANTHROPIC_AUTH_TOKEN: 'sk-test', + ANTHROPIC_MODEL: 'gpt-4', + ANTHROPIC_EXTRA_MODELS: ' ', + }, + }; + const result = profileMapper.mapProfileToClaudeKey(profile); + + assert.ok(result); + assert.strictEqual(result.models.length, 1); + assert.strictEqual(result.models[0].name, 'gpt-4'); + }); }); describe('loadSyncableProfiles', () => { diff --git a/tests/unit/commands/api-command-args.test.ts b/tests/unit/commands/api-command-args.test.ts index 1f5dee30..83387831 100644 --- a/tests/unit/commands/api-command-args.test.ts +++ b/tests/unit/commands/api-command-args.test.ts @@ -163,6 +163,24 @@ describe('api-command arg parser', () => { expect(parsed.extendedContext).toBeUndefined(); expect(parsed.errors).toEqual(['Cannot combine --1m and --no-1m']); }); + + test('parses --extra-models as comma-separated list with whitespace and empty entries trimmed', () => { + const parsed = parseApiCommandArgs([ + 'my-api', + '--extra-models', + ' glm-4.6 , kimi-k2 , ,MiniMax-M2 ', + ]); + + expect(parsed.extraModels).toEqual(['glm-4.6', 'kimi-k2', 'MiniMax-M2']); + expect(parsed.errors).toEqual([]); + }); + + test('records missing-value error for --extra-models with no value', () => { + const parsed = parseApiCommandArgs(['my-api', '--extra-models']); + + expect(parsed.extraModels).toBeUndefined(); + expect(parsed.errors).toEqual(['Missing value for --extra-models']); + }); }); describe('collectUnexpectedApiArgs', () => {