|
| 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