test: http proxy (#175)
This commit is contained in:
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
@@ -39,6 +39,11 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
|
- name: Install tinyproxy
|
||||||
|
if: matrix.os == 'ubuntu-latest'
|
||||||
|
run: |
|
||||||
|
sudo apt-get install tinyproxy
|
||||||
|
tinyproxy
|
||||||
- name: Test
|
- name: Test
|
||||||
env:
|
env:
|
||||||
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export default testSuite(({ describe }) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('CLI', async ({ test }) => {
|
describe('CLI', async ({ test, describe }) => {
|
||||||
const files = {
|
const files = {
|
||||||
'.aicommits': `OPENAI_KEY=${OPENAI_KEY}`,
|
'.aicommits': `OPENAI_KEY=${OPENAI_KEY}`,
|
||||||
'data.json': 'Lorem ipsum dolor sit amet '.repeat(10),
|
'data.json': 'Lorem ipsum dolor sit amet '.repeat(10),
|
||||||
@@ -133,5 +133,97 @@ export default testSuite(({ describe }) => {
|
|||||||
|
|
||||||
await fixture.rm();
|
await fixture.rm();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('proxy', ({ test }) => {
|
||||||
|
test('Fails on invalid proxy', async () => {
|
||||||
|
const { fixture, aicommits } = await createFixture({
|
||||||
|
...files,
|
||||||
|
'.aicommits': `${files['.aicommits']}\nproxy=http://localhost:1234`,
|
||||||
|
});
|
||||||
|
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('connect ECONNREFUSED');
|
||||||
|
|
||||||
|
await fixture.rm();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Connects with config', async () => {
|
||||||
|
const { fixture, aicommits } = await createFixture({
|
||||||
|
...files,
|
||||||
|
'.aicommits': `${files['.aicommits']}\nproxy=http://localhost:8888`,
|
||||||
|
});
|
||||||
|
const git = await createGit(fixture.path);
|
||||||
|
|
||||||
|
await git('add', ['data.json']);
|
||||||
|
|
||||||
|
const committing = aicommits();
|
||||||
|
|
||||||
|
committing.stdout!.on('data', (buffer: Buffer) => {
|
||||||
|
const stdout = buffer.toString();
|
||||||
|
if (stdout.match('└')) {
|
||||||
|
committing.stdin!.write('y');
|
||||||
|
committing.stdin!.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await committing;
|
||||||
|
|
||||||
|
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||||
|
expect(statusAfter.stdout).toBe('');
|
||||||
|
|
||||||
|
const { stdout: commitMessage } = await git('log', ['--oneline']);
|
||||||
|
console.log('Committed with:', commitMessage);
|
||||||
|
|
||||||
|
await fixture.rm();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Connects with env variable', async () => {
|
||||||
|
const { fixture, aicommits } = await createFixture(files);
|
||||||
|
const git = await createGit(fixture.path);
|
||||||
|
|
||||||
|
await git('add', ['data.json']);
|
||||||
|
|
||||||
|
const committing = aicommits([], {
|
||||||
|
env: {
|
||||||
|
HTTP_PROXY: 'http://localhost:8888',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
committing.stdout!.on('data', (buffer: Buffer) => {
|
||||||
|
const stdout = buffer.toString();
|
||||||
|
if (stdout.match('└')) {
|
||||||
|
committing.stdin!.write('y');
|
||||||
|
committing.stdin!.end();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await committing;
|
||||||
|
|
||||||
|
const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
|
||||||
|
expect(statusAfter.stdout).toBe('');
|
||||||
|
|
||||||
|
const { stdout: commitMessage } = await git('log', ['--oneline']);
|
||||||
|
console.log('Committed with:', commitMessage);
|
||||||
|
|
||||||
|
await fixture.rm();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user