test: add the first E2E test and configuration to CI (#316)

* add tests
This commit is contained in:
Takanori Matsumoto
2024-03-25 13:01:05 +09:00
committed by GitHub
parent bdc98c6fa8
commit 5cda8b1b03
17 changed files with 4380 additions and 29 deletions
+3 -2
View File
@@ -57,7 +57,7 @@ export const configValidators = {
//need api key unless running locally with ollama
validateConfig(
'API_KEY',
value || config.OCO_AI_PROVIDER == 'ollama',
value || config.OCO_AI_PROVIDER == 'ollama' || config.OCO_AI_PROVIDER == 'test',
'You need to provide an API key'
);
validateConfig(
@@ -190,7 +190,8 @@ export const configValidators = {
[
'',
'openai',
'ollama'
'ollama',
'test'
].includes(value),
`${value} is not supported yet, use 'ollama' or 'openai' (default)`
);
+1 -1
View File
@@ -27,7 +27,7 @@ let apiKey = config?.OCO_OPENAI_API_KEY
const [command, mode] = process.argv.slice(2);
const isLocalModel = config?.OCO_AI_PROVIDER == 'ollama'
const isLocalModel = config?.OCO_AI_PROVIDER == 'ollama' || config?.OCO_AI_PROVIDER == 'test';
if (!apiKey && command !== 'config' && mode !== CONFIG_MODES.set && !isLocalModel) {
+12
View File
@@ -0,0 +1,12 @@
import { ChatCompletionRequestMessage } from 'openai';
import { AiEngine } from './Engine';
export class TestAi implements AiEngine {
async generateCommitMessage(
messages: Array<ChatCompletionRequestMessage>
): Promise<string | undefined> {
return 'test commit message';
}
}
export const testAi = new TestAi();
+3
View File
@@ -2,11 +2,14 @@ import { AiEngine } from '../engine/Engine';
import { api } from '../engine/openAi';
import { getConfig } from '../commands/config';
import { ollamaAi } from '../engine/ollama';
import { testAi } from '../engine/testAi';
export function getEngine(): AiEngine {
const config = getConfig();
if (config?.OCO_AI_PROVIDER == 'ollama') {
return ollamaAi;
} else if (config?.OCO_AI_PROVIDER == 'test') {
return testAi;
}
//open ai gpt by default
return api;