Skip to content

Commit 5f040a9

Browse files
authored
Merge pull request #15 from lzwjava/feat/integration-tests
Feat: Add Integration Tests
2 parents 8db24ed + 4b47f89 commit 5f040a9

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

.github/workflows/test.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ jobs:
3939
export PYTHONPATH=$PYTHONPATH:.
4040
python3 -m coverage run -m unittest discover tests
4141
python3 -m coverage report -m mini_copilot/*.py mini_copilot/commands/*.py
42+
43+
- name: Run integration tests
44+
if: env.GITHUB_TOKEN_INTEGRATION != ''
45+
env:
46+
GITHUB_TOKEN_INTEGRATION: ${{ secrets.GITHUB_TOKEN_INTEGRATION }}
47+
run: |
48+
export PYTHONPATH=$PYTHONPATH:.
49+
python3 -m unittest discover integration_tests

integration_tests/__init__.py

Whitespace-only changes.

integration_tests/test_copilot.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import unittest
2+
import os
3+
import requests
4+
from mini_copilot import github_api
5+
6+
class TestCopilotIntegration(unittest.TestCase):
7+
def setUp(self):
8+
self.github_token = os.environ.get("GITHUB_TOKEN_INTEGRATION")
9+
if not self.github_token:
10+
self.skipTest("GITHUB_TOKEN_INTEGRATION environment variable not set")
11+
12+
def test_copilot_token_and_models(self):
13+
# Step 1: Exchange GitHub token for Copilot token
14+
try:
15+
copilot_token = github_api.get_copilot_token(self.github_token)
16+
self.assertTrue(len(copilot_token) > 0, "Copilot token should not be empty")
17+
print("\n✅ Successfully obtained Copilot token.")
18+
except Exception as e:
19+
self.fail(f"Failed to get Copilot token: {e}")
20+
21+
# Step 2: Fetch available models
22+
try:
23+
models = github_api.get_models(copilot_token)
24+
self.assertIsInstance(models, list, "Models should be a list")
25+
self.assertTrue(len(models) > 0, "Should find at least one model")
26+
model_ids = [m['id'] for m in models]
27+
print(f"✅ Found {len(models)} models. Available: {', '.join(model_ids[:5])}...")
28+
except Exception as e:
29+
self.fail(f"Failed to fetch models: {e}")
30+
31+
def test_copilot_chat(self):
32+
copilot_token = github_api.get_copilot_token(self.github_token)
33+
messages = [{"role": "user", "content": "Say 'hello world' and nothing else."}]
34+
35+
try:
36+
response = github_api.chat(messages, copilot_token, model="gpt-4o")
37+
content = response.get("content", "").lower()
38+
self.assertIn("hello world", content)
39+
print(f"✅ Copilot Chat responded correctly: {content}")
40+
except Exception as e:
41+
self.fail(f"Chat integration failed: {e}")
42+
43+
if __name__ == "__main__":
44+
unittest.main()

0 commit comments

Comments
 (0)