mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-11 03:13:12 +00:00
test(openrouter): refine regression test using existing profile-writer harness (#1728)
This commit is contained in:
1 parent
375a3468b8
commit
283e8843ac
2 files changed
+11
-39
No files matched your search
@@ -3,6 +3,7 @@ import * as fs from 'fs';
|
|||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { createApiProfile } from '../../../src/api/services/profile-writer';
|
import { createApiProfile } from '../../../src/api/services/profile-writer';
|
||||||
|
import { getPresetById } from '../../../src/api/services/provider-presets';
|
||||||
|
|
||||||
describe('profile-writer Anthropic direct', () => {
|
describe('profile-writer Anthropic direct', () => {
|
||||||
let tempHome = '';
|
let tempHome = '';
|
||||||
@@ -131,10 +132,14 @@ describe('profile-writer Anthropic direct', () => {
|
|||||||
expect(config.profile_targets?.['hf-target-claude']).toBeUndefined();
|
expect(config.profile_targets?.['hf-target-claude']).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('preserves OpenRouter ANTHROPIC_API_KEY blank behavior', () => {
|
it('preserves OpenRouter ANTHROPIC_API_KEY blank behavior and resolves preset baseUrl without duplicating /v1 (#1728)', () => {
|
||||||
|
const preset = getPresetById('openrouter');
|
||||||
|
expect(preset).toBeDefined();
|
||||||
|
expect(preset?.baseUrl).toBe('https://openrouter.ai/api');
|
||||||
|
|
||||||
const result = createApiProfile(
|
const result = createApiProfile(
|
||||||
'openrouter-test',
|
'openrouter-test',
|
||||||
'https://openrouter.ai/api',
|
preset!.baseUrl,
|
||||||
'sk-or-testkey',
|
'sk-or-testkey',
|
||||||
{ default: 'anthropic/claude-opus-4.5', opus: 'anthropic/claude-opus-4.5', sonnet: 'anthropic/claude-opus-4.5', haiku: 'anthropic/claude-opus-4.5' }
|
{ default: 'anthropic/claude-opus-4.5', opus: 'anthropic/claude-opus-4.5', sonnet: 'anthropic/claude-opus-4.5', haiku: 'anthropic/claude-opus-4.5' }
|
||||||
);
|
);
|
||||||
@@ -144,8 +149,9 @@ describe('profile-writer Anthropic direct', () => {
|
|||||||
const settingsPath = path.join(tempHome, '.ccs', 'openrouter-test.settings.json');
|
const settingsPath = path.join(tempHome, '.ccs', 'openrouter-test.settings.json');
|
||||||
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf8'));
|
||||||
|
|
||||||
// OpenRouter: proxy mode with ANTHROPIC_API_KEY explicitly blank
|
// OpenRouter: proxy mode with ANTHROPIC_API_KEY explicitly blank and baseUrl without /v1
|
||||||
expect(settings.env.ANTHROPIC_BASE_URL).toBe('https://openrouter.ai/api');
|
expect(settings.env.ANTHROPIC_BASE_URL).toBe('https://openrouter.ai/api');
|
||||||
|
expect(`${settings.env.ANTHROPIC_BASE_URL}/v1/messages`).toBe('https://openrouter.ai/api/v1/messages');
|
||||||
expect(settings.env.ANTHROPIC_AUTH_TOKEN).toBe('sk-or-testkey');
|
expect(settings.env.ANTHROPIC_AUTH_TOKEN).toBe('sk-or-testkey');
|
||||||
expect(settings.env.ANTHROPIC_API_KEY).toBe('');
|
expect(settings.env.ANTHROPIC_API_KEY).toBe('');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { tmpdir } from 'os';
|
import { resolve } from 'path';
|
||||||
import { join, resolve } from 'path';
|
|
||||||
import { describe, expect, it } from 'bun:test';
|
import { describe, expect, it } from 'bun:test';
|
||||||
import { createApiProfile } from '../../../src/api/services/profile-writer';
|
|
||||||
import {
|
import {
|
||||||
PROVIDER_PRESETS,
|
PROVIDER_PRESETS,
|
||||||
getPresetById,
|
getPresetById,
|
||||||
@@ -123,38 +121,6 @@ describe('provider-presets', () => {
|
|||||||
expect(finalEndpoint).not.toContain('/v1/v1/');
|
expect(finalEndpoint).not.toContain('/v1/v1/');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('generates an OpenRouter profile whose ANTHROPIC_BASE_URL does not duplicate /v1 (#1728)', () => {
|
|
||||||
const preset = getPresetById('openrouter');
|
|
||||||
expect(preset).toBeDefined();
|
|
||||||
const tempHome = mkdtempSync(join(tmpdir(), 'ccs-openrouter-tdd-'));
|
|
||||||
const prevCcsHome = process.env.CCS_HOME;
|
|
||||||
process.env.CCS_HOME = tempHome;
|
|
||||||
try {
|
|
||||||
const result = createApiProfile(
|
|
||||||
'openrouter-tdd',
|
|
||||||
preset!.baseUrl,
|
|
||||||
'sk-or-test-key',
|
|
||||||
{
|
|
||||||
default: preset!.defaultModel,
|
|
||||||
opus: preset!.defaultModel,
|
|
||||||
sonnet: preset!.defaultModel,
|
|
||||||
haiku: preset!.defaultModel,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expect(result.success).toBe(true);
|
|
||||||
const settings = JSON.parse(
|
|
||||||
readFileSync(join(tempHome, '.ccs', 'openrouter-tdd.settings.json'), 'utf8')
|
|
||||||
);
|
|
||||||
expect(settings.env.ANTHROPIC_BASE_URL).toBe('https://openrouter.ai/api');
|
|
||||||
expect(`${settings.env.ANTHROPIC_BASE_URL}/v1/messages`).toBe(
|
|
||||||
'https://openrouter.ai/api/v1/messages'
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
process.env.CCS_HOME = prevCcsHome;
|
|
||||||
rmSync(tempHome, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('keeps Anthropic direct last in the recommended preset order and reuses the Claude logo', () => {
|
it('keeps Anthropic direct last in the recommended preset order and reuses the Claude logo', () => {
|
||||||
const recommendedPresetIds = PROVIDER_PRESETS.filter(
|
const recommendedPresetIds = PROVIDER_PRESETS.filter(
|
||||||
(preset) => preset.category === 'recommended'
|
(preset) => preset.category === 'recommended'
|
||||||
|
|||||||
Reference in new issue
Block a user