remove tests out of date
This commit is contained in:
parent
908b18acc6
commit
741ee9fcbf
@ -1,181 +0,0 @@
|
|||||||
import { expect } from 'chai';
|
|
||||||
// import { describe, it } from 'mocha';
|
|
||||||
import sinon from 'sinon';
|
|
||||||
import * as path from 'path';
|
|
||||||
import { parseMessage, parseMessageAndSetOptions, processChatResponse, sendMessageBase, stopDevChatBase } from '../../src/handler/sendMessageBase';
|
|
||||||
import { ChatResponse } from '../../src/toolwrapper/devchat';
|
|
||||||
import { UiUtilWrapper } from '../../src/util/uiUtil';
|
|
||||||
|
|
||||||
import * as dotenv from 'dotenv';
|
|
||||||
|
|
||||||
const envPath = path.join(__dirname, '../../', '.env');
|
|
||||||
dotenv.config({ path: envPath });
|
|
||||||
|
|
||||||
describe('sendMessageBase', () => {
|
|
||||||
let workspaceFoldersFirstPathStub: sinon.SinonStub;
|
|
||||||
let getConfigurationStub: sinon.SinonStub;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
workspaceFoldersFirstPathStub = sinon.stub(UiUtilWrapper, 'workspaceFoldersFirstPath');
|
|
||||||
getConfigurationStub = sinon.stub(UiUtilWrapper, 'getConfiguration');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
workspaceFoldersFirstPathStub.restore();
|
|
||||||
getConfigurationStub.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('parseMessage', () => {
|
|
||||||
it('should parse message correctly', () => {
|
|
||||||
const message = '[context|path/to/context] [instruction|path/to/instruction] [reference|path/to/reference] Hello, world!';
|
|
||||||
const result = parseMessage(message);
|
|
||||||
|
|
||||||
expect(result.context).to.deep.equal(['path/to/context']);
|
|
||||||
expect(result.instruction).to.deep.equal(['path/to/instruction']);
|
|
||||||
expect(result.reference).to.deep.equal(['path/to/reference']);
|
|
||||||
expect(result.text).to.equal('Hello, world!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('parseMessageAndSetOptions', () => {
|
|
||||||
it('should parse message and set options correctly', async () => {
|
|
||||||
const message = {
|
|
||||||
text: '[context|path/to/context] [instruction|path/to/instruction] [reference|path/to/reference] Hello, world!'
|
|
||||||
};
|
|
||||||
|
|
||||||
const [result, chatOptions] = await parseMessageAndSetOptions(message);
|
|
||||||
|
|
||||||
expect(result.context).to.deep.equal(['path/to/context']);
|
|
||||||
expect(result.instruction).to.deep.equal(['path/to/instruction']);
|
|
||||||
expect(result.reference).to.deep.equal(['path/to/reference']);
|
|
||||||
expect(result.text).to.equal('Hello, world!');
|
|
||||||
expect(chatOptions.context).to.deep.equal(['path/to/context']);
|
|
||||||
expect(chatOptions.header).to.deep.equal([]);
|
|
||||||
expect(chatOptions.reference).to.deep.equal(['path/to/reference']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('processChatResponse', () => {
|
|
||||||
it('should handle response text correctly when isError is false', async () => {
|
|
||||||
const partialDataText = 'Partial data';
|
|
||||||
const chatResponse: ChatResponse = {
|
|
||||||
"finish_reason": "",
|
|
||||||
response: 'Hello, user!',
|
|
||||||
isError: false,
|
|
||||||
user: 'user',
|
|
||||||
date: '2022-01-01T00:00:00.000Z',
|
|
||||||
'prompt-hash': 'responsehash'
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await processChatResponse(chatResponse);
|
|
||||||
expect(result).to.equal('Hello, user!');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should handle response text correctly when isError is true', async () => {
|
|
||||||
const partialDataText = 'Partial data';
|
|
||||||
const chatResponse: ChatResponse = {
|
|
||||||
"finish_reason": "",
|
|
||||||
response: 'Error occurred!',
|
|
||||||
isError: true,
|
|
||||||
user: 'user',
|
|
||||||
date: '2022-01-01T00:00:00.000Z',
|
|
||||||
'prompt-hash': 'responsehash'
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await processChatResponse(chatResponse);
|
|
||||||
expect(result).to.equal('Error occurred!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('sendMessageBase', () => {
|
|
||||||
it('should send message correct with DevChat access key', async function() {
|
|
||||||
const message = {
|
|
||||||
text: 'Hello, world!'
|
|
||||||
};
|
|
||||||
const handlePartialData = (data: { command: string, text: string, user: string, date: string }) => {
|
|
||||||
// Handle partial data
|
|
||||||
};
|
|
||||||
|
|
||||||
workspaceFoldersFirstPathStub.returns('./');
|
|
||||||
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'Access_Key_DevChat').returns(process.env.TEST_DEVCHAT_KEY);
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'OpenAI.temperature').returns(0);
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'OpenAI.stream').returns('true');
|
|
||||||
|
|
||||||
const result = await sendMessageBase(message, handlePartialData);
|
|
||||||
expect(result).to.be.an('object');
|
|
||||||
expect(result!.command).to.equal('receiveMessage');
|
|
||||||
expect(result!.text).to.be.a('string');
|
|
||||||
expect(result!.hash).to.be.a('string');
|
|
||||||
expect(result!.user).to.be.a('string');
|
|
||||||
expect(result!.date).to.be.a('string');
|
|
||||||
// TODO fix
|
|
||||||
// Need to mock more config setting
|
|
||||||
// expect(result!.isError).to.be.false;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should send message error with invalid api key', async function() {
|
|
||||||
const message = {
|
|
||||||
text: 'Hello, world!'
|
|
||||||
};
|
|
||||||
const handlePartialData = (data: { command: string, text: string, user: string, date: string }) => {
|
|
||||||
// Handle partial data
|
|
||||||
};
|
|
||||||
|
|
||||||
workspaceFoldersFirstPathStub.returns('./');
|
|
||||||
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'Access_Key_DevChat').returns('sk-KvH7ZCtHmFDCBTqH0jUv');
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'OpenAI.temperature').returns('0');
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'OpenAI.stream').returns('true');
|
|
||||||
|
|
||||||
const result = await sendMessageBase(message, handlePartialData);
|
|
||||||
expect(result).to.be.an('object');
|
|
||||||
expect(result!.command).to.equal('receiveMessage');
|
|
||||||
expect(result!.text).to.be.a('string');
|
|
||||||
expect(result!.hash).to.be.a('string');
|
|
||||||
expect(result!.user).to.be.a('string');
|
|
||||||
expect(result!.date).to.be.a('string');
|
|
||||||
expect(result!.isError).to.be.true;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('stopDevChatBase', () => {
|
|
||||||
it('should stop sendMessageBase correctly', async () => {
|
|
||||||
const message = {
|
|
||||||
text: 'Hello, world!'
|
|
||||||
};
|
|
||||||
const handlePartialData = (data: { command: string, text: string, user: string, date: string }) => {
|
|
||||||
// Handle partial data
|
|
||||||
};
|
|
||||||
|
|
||||||
workspaceFoldersFirstPathStub.returns('./');
|
|
||||||
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'Access_Key_DevChat').returns(process.env.TEST_DEVCHAT_KEY);
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'OpenAI.temperature').returns(0);
|
|
||||||
getConfigurationStub.withArgs('DevChat', 'OpenAI.stream').returns('true');
|
|
||||||
|
|
||||||
|
|
||||||
// Start sendMessageBase in a separate Promise
|
|
||||||
const sendMessagePromise = sendMessageBase(message, handlePartialData);
|
|
||||||
|
|
||||||
// Wait for a short period to ensure sendMessageBase has started
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
||||||
|
|
||||||
// Call stopDevChatBase
|
|
||||||
const stopMessage = {
|
|
||||||
text: 'stop'
|
|
||||||
};
|
|
||||||
await stopDevChatBase(stopMessage);
|
|
||||||
|
|
||||||
// Check if sendMessageBase has been stopped and returns an error
|
|
||||||
// TODO fix
|
|
||||||
// Need to mock more config setting
|
|
||||||
// try {
|
|
||||||
// const result = await sendMessagePromise;
|
|
||||||
// expect(result).to.undefined;
|
|
||||||
// } catch (error) {
|
|
||||||
// expect(error).to.be.an('error');
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,71 +0,0 @@
|
|||||||
import { expect } from 'chai';
|
|
||||||
// import { describe, it } from 'mocha';
|
|
||||||
import sinon from 'sinon';
|
|
||||||
import DevChat, { ChatOptions } from '../../src/toolwrapper/devchat';
|
|
||||||
import { CommandRun } from '../../src/util/commonUtil';
|
|
||||||
import { UiUtilWrapper } from '../../src/util/uiUtil';
|
|
||||||
import { ApiKeyManager } from '../../src/util/apiKey';
|
|
||||||
|
|
||||||
// TODO: 删除devchat.js时,删除此测试文件
|
|
||||||
// TODO: 同时为 DevChatCLI & DevChatClient 添加测试
|
|
||||||
describe('DevChat', () => {
|
|
||||||
let devChat: DevChat;
|
|
||||||
let spawnAsyncStub: sinon.SinonStub;
|
|
||||||
let workspaceFoldersFirstPathStub: sinon.SinonStub;
|
|
||||||
let apiKeyManagerStub: sinon.SinonStub;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
devChat = new DevChat();
|
|
||||||
spawnAsyncStub = sinon.stub(CommandRun.prototype, 'spawnAsync');
|
|
||||||
workspaceFoldersFirstPathStub = sinon.stub(UiUtilWrapper, 'workspaceFoldersFirstPath');
|
|
||||||
apiKeyManagerStub = sinon.stub(ApiKeyManager, 'llmModel');
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach(() => {
|
|
||||||
spawnAsyncStub.restore();
|
|
||||||
workspaceFoldersFirstPathStub.restore();
|
|
||||||
apiKeyManagerStub.restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
describe('chat', () => {
|
|
||||||
it('should return a ChatResponse object with isError false when the chat is successful', async () => {
|
|
||||||
const content = 'Test chat content';
|
|
||||||
const options: ChatOptions = {
|
|
||||||
// Provide mock values for the options
|
|
||||||
parent: 'parent_value',
|
|
||||||
reference: ['ref1', 'ref2'],
|
|
||||||
header: ['header1', 'header2'],
|
|
||||||
context: ['context1', 'context2'],
|
|
||||||
};
|
|
||||||
const mockResponse = {
|
|
||||||
exitCode: 0,
|
|
||||||
stdout: 'User: Test user\nDate: 2022-01-01\nTest chat response\nprompt-hash: 12345',
|
|
||||||
stderr: '',
|
|
||||||
};
|
|
||||||
const mockWorkspacePath = './';
|
|
||||||
const llmModelResponse = {
|
|
||||||
"model": "gpt-3.5-turbo",
|
|
||||||
"api_key": "DC.1234567890"
|
|
||||||
}
|
|
||||||
|
|
||||||
spawnAsyncStub.resolves(mockResponse);
|
|
||||||
workspaceFoldersFirstPathStub.returns(mockWorkspacePath);
|
|
||||||
apiKeyManagerStub.resolves(llmModelResponse);
|
|
||||||
|
|
||||||
const response = await devChat.chat(content, options, (data)=>{}, false);
|
|
||||||
|
|
||||||
expect(response).to.have.property('prompt-hash', '');
|
|
||||||
expect(response).to.have.property('user', '');
|
|
||||||
expect(response).to.have.property('date', '');
|
|
||||||
expect(response).to.have.property('response', 'Test chat response');
|
|
||||||
expect(response).to.have.property('isError', false);
|
|
||||||
expect(spawnAsyncStub.calledOnce).to.be.true;
|
|
||||||
expect(workspaceFoldersFirstPathStub.calledOnce).to.be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add more test cases for the chat method here
|
|
||||||
});
|
|
||||||
|
|
||||||
// ... other test cases
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user