From 76d8ff8847db29b093771d8b71289bbdb9dbe06e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 31 Jan 2026 00:43:14 +0000 Subject: [PATCH] Add test suite and fix OpenAI client initialization - Create test_app.py with basic endpoint tests - Add pytest to requirements.txt - Fix issue_detector.py to lazily initialize OpenAI client - All tests passing Co-authored-by: kodjima33 --- issue_detector.py | 13 ++++++++++- requirements.txt | 1 + test_app.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test_app.py diff --git a/issue_detector.py b/issue_detector.py index 7c73d51..3532a59 100644 --- a/issue_detector.py +++ b/issue_detector.py @@ -7,7 +7,13 @@ from dotenv import load_dotenv load_dotenv() -client = AsyncOpenAI(api_key=os.getenv("OPENAI_API_KEY")) + +def get_openai_client(): + """Get OpenAI client, initialized lazily.""" + api_key = os.getenv("OPENAI_API_KEY") + if not api_key: + return None + return AsyncOpenAI(api_key=api_key) async def ai_select_labels(title: str, description: str, available_labels: List[str]) -> List[str]: @@ -18,6 +24,11 @@ async def ai_select_labels(title: str, description: str, available_labels: List[ if not available_labels: return [] + client = get_openai_client() + if not client: + print("OpenAI API key not set, skipping AI label selection", flush=True) + return [] + try: response = await client.chat.completions.create( model="gpt-4o", diff --git a/requirements.txt b/requirements.txt index fbd036c..11335ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ httpx==0.25.2 openai==1.3.7 requests==2.31.0 anthropic==0.39.0 +pytest==7.4.3 diff --git a/test_app.py b/test_app.py new file mode 100644 index 0000000..c004b14 --- /dev/null +++ b/test_app.py @@ -0,0 +1,57 @@ +""" +Simple tests for the OMI GitHub Issues Integration +""" +import pytest +from fastapi.testclient import TestClient +from main import app + +client = TestClient(app) + + +def test_health_endpoint(): + """Test the health check endpoint""" + response = client.get("/health") + assert response.status_code == 200 + data = response.json() + assert data["status"] == "healthy" + assert data["service"] == "omi-github-issues" + + +def test_root_endpoint(): + """Test the root endpoint without uid""" + response = client.get("/") + assert response.status_code == 200 + data = response.json() + assert data["app"] == "OMI GitHub Issues Integration" + assert data["version"] == "2.0.0" + assert data["status"] == "active" + + +def test_omi_tools_manifest(): + """Test the OMI tools manifest endpoint""" + response = client.get("/.well-known/omi-tools.json") + assert response.status_code == 200 + data = response.json() + assert "tools" in data + assert len(data["tools"]) > 0 + + # Verify key tools exist + tool_names = [tool["name"] for tool in data["tools"]] + assert "create_issue" in tool_names + assert "list_repos" in tool_names + assert "list_issues" in tool_names + assert "code_feature" in tool_names + + +def test_setup_completed_endpoint(): + """Test setup check endpoint""" + response = client.get("/setup-completed?uid=test-user") + assert response.status_code == 200 + data = response.json() + assert "is_setup_completed" in data + # Should be False for non-existent user + assert data["is_setup_completed"] is False + + +if __name__ == "__main__": + pytest.main([__file__, "-v"])