Files
wehub-resource-sync 0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

136 lines
4.2 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createGitHubProvider } from '../../../src/providers/github/index';
import { OpenAiChatCompletionProvider } from '../../../src/providers/openai/chat';
import { createMockProvider } from '../../factories/provider';
const mockOpenAiChatCompletionProvider = vi.hoisted(() =>
vi.fn(function (this: unknown) {
return {};
}),
);
vi.mock('../../../src/providers/openai/chat', async (importOriginal) => {
return {
...(await importOriginal()),
OpenAiChatCompletionProvider: mockOpenAiChatCompletionProvider,
};
});
describe('createGitHubProvider', () => {
beforeEach(() => {
vi.clearAllMocks();
mockOpenAiChatCompletionProvider.mockReset();
});
it('should create provider with default model when no model specified', () => {
const mockProvider = createMockProvider({ id: 'github:openai/gpt-5' });
mockOpenAiChatCompletionProvider.mockImplementation(function () {
return mockProvider as any;
});
const result = createGitHubProvider('github:', {}, {} as any);
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('openai/gpt-5', {
config: {
apiBaseUrl: 'https://models.github.ai/inference',
apiKeyEnvar: 'GITHUB_TOKEN',
},
});
expect(result).toBe(mockProvider);
});
it('should create provider with specified model', () => {
const mockProvider = createMockProvider({ id: 'github:openai/gpt-4.1-mini' });
mockOpenAiChatCompletionProvider.mockImplementation(function () {
return mockProvider as any;
});
const result = createGitHubProvider('github:openai/gpt-4.1-mini', {}, {} as any);
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('openai/gpt-4.1-mini', {
config: {
apiBaseUrl: 'https://models.github.ai/inference',
apiKeyEnvar: 'GITHUB_TOKEN',
},
});
expect(result).toBe(mockProvider);
});
it('should handle models with colons in their names', () => {
const mockProvider = createMockProvider({ id: 'github:anthropic/claude-3.5:sonnet' });
mockOpenAiChatCompletionProvider.mockImplementation(function () {
return mockProvider as any;
});
const result = createGitHubProvider('github:anthropic/claude-3.5:sonnet', {}, {} as any);
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('anthropic/claude-3.5:sonnet', {
config: {
apiBaseUrl: 'https://models.github.ai/inference',
apiKeyEnvar: 'GITHUB_TOKEN',
},
});
expect(result).toBe(mockProvider);
});
it('should merge existing config with GitHub-specific config', () => {
const mockProvider = createMockProvider({ id: 'github:openai/gpt-4.1' });
mockOpenAiChatCompletionProvider.mockImplementation(function () {
return mockProvider as any;
});
const existingConfig = {
temperature: 0.7,
max_tokens: 2048,
apiKey: 'custom-key',
};
const result = createGitHubProvider(
'github:openai/gpt-4.1',
{ config: existingConfig },
{} as any,
);
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('openai/gpt-4.1', {
config: {
temperature: 0.7,
max_tokens: 2048,
apiKey: 'custom-key',
apiBaseUrl: 'https://models.github.ai/inference',
apiKeyEnvar: 'GITHUB_TOKEN',
},
});
expect(result).toBe(mockProvider);
});
it('should pass through all provider options', () => {
const mockProvider = createMockProvider({ id: 'github:openai/gpt-4.1' });
mockOpenAiChatCompletionProvider.mockImplementation(function () {
return mockProvider as any;
});
const providerOptions = {
id: 'custom-id',
label: 'Custom Label',
config: { temperature: 0.5 },
transform: 'output.trim()',
delay: 1000,
};
const result = createGitHubProvider('github:openai/gpt-4.1', providerOptions, {} as any);
expect(OpenAiChatCompletionProvider).toHaveBeenCalledWith('openai/gpt-4.1', {
id: 'custom-id',
label: 'Custom Label',
transform: 'output.trim()',
delay: 1000,
config: {
temperature: 0.5,
apiBaseUrl: 'https://models.github.ai/inference',
apiKeyEnvar: 'GITHUB_TOKEN',
},
});
expect(result).toBe(mockProvider);
});
});