feat: request timeout config (#191)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
This commit is contained in:
@@ -252,5 +252,34 @@ export default testSuite(({ describe }) => {
|
||||
await fixture.rm();
|
||||
});
|
||||
});
|
||||
|
||||
test('Fails on timeout', async () => {
|
||||
const { fixture, aicommits } = await createFixture({
|
||||
...files,
|
||||
'.aicommits': `${files['.aicommits']}\ntimeout=500`,
|
||||
});
|
||||
const git = await createGit(fixture.path);
|
||||
|
||||
await git('add', ['data.json']);
|
||||
|
||||
const committing = aicommits([], {
|
||||
reject: false,
|
||||
});
|
||||
|
||||
committing.stdout!.on('data', (buffer: Buffer) => {
|
||||
const stdout = buffer.toString();
|
||||
if (stdout.match('└')) {
|
||||
committing.stdin!.write('y');
|
||||
committing.stdin!.end();
|
||||
}
|
||||
});
|
||||
|
||||
const { stdout, exitCode } = await committing;
|
||||
|
||||
expect(exitCode).toBe(1);
|
||||
expect(stdout).toMatch('Time out error: request took over 500ms.');
|
||||
|
||||
await fixture.rm();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import { testSuite, expect } from 'manten';
|
||||
import { createFixture } from '../utils.js';
|
||||
|
||||
export default testSuite(({ describe }) => {
|
||||
describe('config', async ({ test }) => {
|
||||
describe('config', async ({ test, describe }) => {
|
||||
const { fixture, aicommits } = await createFixture();
|
||||
const configPath = path.join(fixture.path, '.aicommits');
|
||||
const openAiToken = 'OPENAI_KEY=sk-abc';
|
||||
@@ -49,6 +49,25 @@ export default testSuite(({ describe }) => {
|
||||
expect(stderr).toBe('');
|
||||
});
|
||||
|
||||
await describe('timeout', ({ test }) => {
|
||||
test('setting invalid timeout config', async () => {
|
||||
const { stderr } = await aicommits(['config', 'set', 'timeout=abc'], {
|
||||
reject: false,
|
||||
});
|
||||
|
||||
expect(stderr).toMatch('Must be an integer');
|
||||
});
|
||||
|
||||
test('setting valid timeout config', async () => {
|
||||
const timeout = 'timeout=20000';
|
||||
await aicommits(['config', 'set', timeout]);
|
||||
|
||||
const configFile = await fs.readFile(configPath, 'utf8');
|
||||
|
||||
expect(configFile).toMatch(timeout);
|
||||
});
|
||||
});
|
||||
|
||||
await fixture.rm();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user