diff --git a/scripts/test_gitea_issue_parser.py b/scripts/test_gitea_issue_parser.py index 36aaee0..b51b88c 100644 --- a/scripts/test_gitea_issue_parser.py +++ b/scripts/test_gitea_issue_parser.py @@ -3,6 +3,9 @@ import sys import os +import json +import pytest +import urllib.request sys.path.insert(0, os.path.dirname(__file__) or ".") # Import from sibling @@ -25,8 +28,7 @@ This is the background info. ## What to build -Some description. -""" +Some description.""" result = parse_issue_body(body, title="Test (#42)", labels=["bug"]) assert result["title"] == "Test (#42)" assert result["labels"] == ["bug"] @@ -44,8 +46,7 @@ def test_numbered_criteria(): 1. First item 2. Second item -3. Third item -""" +3. Third item""" result = parse_issue_body(body) assert len(result["criteria"]) == 3 assert result["criteria"][0]["text"] == "First item" @@ -85,8 +86,7 @@ Do this instead. ## Notes -Additional info. -""" +Additional info.""" result = parse_issue_body(body) assert "problem" in result["sections"] assert "fix" in result["sections"] @@ -95,6 +95,51 @@ Additional info. print("PASS: test_multiple_sections") +def test_real_issues_api(): + """Integration test: parse 20 real Gitea issues and verify all fields extracted.""" + token_path = os.path.expanduser("~/.config/gitea/token") + if not os.path.exists(token_path): + pytest.skip("Gitea token not available — skip integration test") + + token = open(token_path).read().strip() + base = "https://forge.alexanderwhitestone.com/api/v1" + owner, repo = "Timmy_Foundation", "compounding-intelligence" + + # Fetch up to 20 recent issues + url = f"{base}/repos/{owner}/{repo}/issues?state=all&limit=20&sort=created&direction=desc" + req = urllib.request.Request(url, headers={ + "Authorization": f"token {token}", + "Accept": "application/json" + }) + with urllib.request.urlopen(req, timeout=30) as resp: + issues = json.loads(resp.read()) + + assert len(issues) >= 1, "Need at least 1 issue to validate" + + for issue in issues: + body = issue.get("body", "") or "" + title = issue.get("title", "") + labels = [l["name"] for l in issue.get("labels", [])] + + result = parse_issue_body(body, title=title, labels=labels) + + # Required keys present + for key in ("title", "context", "criteria", "labels", "epic_ref"): + assert key in result, f"Missing {{{key}}} for issue #{issue['number']}" + + # Sanity checks + assert result["title"] == title, f"Title mismatch issue #{issue['number']}" + assert result["labels"] == labels, f"Labels mismatch issue #{issue['number']}" + assert isinstance(result["context"], str) + assert isinstance(result["criteria"], list) + for c in result["criteria"]: + assert "text" in c and "checked" in c + + print(f" Issue #{issue['number']}: criteria={len(result['criteria'])}, labels={labels}") + + print(f" All {len(issues)} issues parsed successfully!") + + def run_all(): test_basic_parsing() test_numbered_criteria() @@ -102,7 +147,8 @@ def run_all(): test_empty_body() test_no_sections() test_multiple_sections() - print("\nAll 6 tests passed!") + test_real_issues_api() + print("\nAll tests passed!") if __name__ == "__main__":