diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af23970a..f86f1451 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,11 @@ jobs: - name: Build run: pnpm build + - name: Install tinyproxy + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get install tinyproxy + tinyproxy - name: Test env: OPENAI_KEY: ${{ secrets.OPENAI_KEY }} diff --git a/tests/specs/cli/commits.ts b/tests/specs/cli/commits.ts index 717d7169..7b7b3a41 100644 --- a/tests/specs/cli/commits.ts +++ b/tests/specs/cli/commits.ts @@ -15,7 +15,7 @@ export default testSuite(({ describe }) => { return; } - describe('CLI', async ({ test }) => { + describe('CLI', async ({ test, describe }) => { const files = { '.aicommits': `OPENAI_KEY=${OPENAI_KEY}`, 'data.json': 'Lorem ipsum dolor sit amet '.repeat(10), @@ -133,5 +133,97 @@ export default testSuite(({ describe }) => { 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(); + }); + }); }); });