mirror of
https://github.com/coleam00/Archon.git
synced 2025-12-23 18:29:18 -05:00
fix: Update bug report to use centralized repository configuration from version.py
Fixes #802 The bug report feature was redirecting users to the old repository URL (dynamous-community/Archon-V2-Alpha) instead of the current repository (coleam00/Archon). This occurred because hardcoded default values in the bug report API were not updated during the Alpha-to-Beta rebranding. Changes: - Import GITHUB_REPO_OWNER and GITHUB_REPO_NAME from version.py - Update GitHubService.__init__() to construct default from constants - Update health check endpoint to use same centralized default - Add comprehensive integration tests for bug report URL generation - Document repository configuration in CLAUDE.md The fix ensures single source of truth for repository information and maintains backward compatibility with GITHUB_REPO environment variable override. All tests pass (7/7) validating correct repository URL usage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
10
CLAUDE.md
10
CLAUDE.md
@@ -198,6 +198,16 @@ SUPABASE_SERVICE_KEY=your-service-key-here # Use legacy key format for clou
|
||||
Optional variables and full configuration:
|
||||
See `python/.env.example` for complete list
|
||||
|
||||
### Repository Configuration
|
||||
|
||||
Repository information (owner, name) is centralized in `python/src/server/config/version.py`:
|
||||
- `GITHUB_REPO_OWNER` - GitHub repository owner (default: "coleam00")
|
||||
- `GITHUB_REPO_NAME` - GitHub repository name (default: "Archon")
|
||||
|
||||
This is the single source of truth for repository configuration. All services (version checking, bug reports, etc.) should import these constants rather than hardcoding repository URLs.
|
||||
|
||||
Environment variable override: `GITHUB_REPO="owner/repo"` can be set to override defaults.
|
||||
|
||||
## Common Development Tasks
|
||||
|
||||
### Add a new API endpoint
|
||||
|
||||
@@ -12,6 +12,7 @@ from fastapi import APIRouter, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..config.logfire_config import get_logger
|
||||
from ..config.version import GITHUB_REPO_NAME, GITHUB_REPO_OWNER
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -47,7 +48,9 @@ class BugReportResponse(BaseModel):
|
||||
class GitHubService:
|
||||
def __init__(self):
|
||||
self.token = os.getenv("GITHUB_TOKEN")
|
||||
self.repo = os.getenv("GITHUB_REPO", "dynamous-community/Archon-V2-Alpha")
|
||||
# Use centralized version config with environment override
|
||||
default_repo = f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}"
|
||||
self.repo = os.getenv("GITHUB_REPO", default_repo)
|
||||
|
||||
async def create_issue(self, bug_report: BugReportRequest) -> dict[str, Any]:
|
||||
"""Create a GitHub issue from a bug report."""
|
||||
@@ -271,10 +274,13 @@ async def bug_report_health():
|
||||
github_configured = bool(os.getenv("GITHUB_TOKEN"))
|
||||
repo_configured = bool(os.getenv("GITHUB_REPO"))
|
||||
|
||||
# Use centralized version config with environment override
|
||||
default_repo = f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}"
|
||||
|
||||
return {
|
||||
"status": "healthy" if github_configured else "degraded",
|
||||
"github_token_configured": github_configured,
|
||||
"github_repo_configured": repo_configured,
|
||||
"repo": os.getenv("GITHUB_REPO", "dynamous-community/Archon-V2-Alpha"),
|
||||
"repo": os.getenv("GITHUB_REPO", default_repo),
|
||||
"message": "Bug reporting is ready" if github_configured else "GitHub token not configured",
|
||||
}
|
||||
|
||||
173
python/tests/server/api_routes/test_bug_report_api.py
Normal file
173
python/tests/server/api_routes/test_bug_report_api.py
Normal file
@@ -0,0 +1,173 @@
|
||||
"""
|
||||
Unit tests for bug_report_api.py
|
||||
"""
|
||||
|
||||
import os
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from src.server.config.version import GITHUB_REPO_NAME, GITHUB_REPO_OWNER
|
||||
from src.server.main import app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
"""Create test client."""
|
||||
return TestClient(app)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_bug_report():
|
||||
"""Mock bug report data."""
|
||||
return {
|
||||
"title": "Test Bug",
|
||||
"description": "Test description",
|
||||
"stepsToReproduce": "Step 1\nStep 2",
|
||||
"expectedBehavior": "Expected result",
|
||||
"actualBehavior": "Actual result",
|
||||
"severity": "medium",
|
||||
"component": "ui",
|
||||
"context": {
|
||||
"error": {
|
||||
"name": "TypeError",
|
||||
"message": "Test error",
|
||||
"stack": "Test stack trace",
|
||||
},
|
||||
"app": {
|
||||
"version": "0.1.0",
|
||||
"url": "http://localhost:3737",
|
||||
"timestamp": "2025-10-17T12:00:00Z",
|
||||
},
|
||||
"system": {
|
||||
"platform": "linux",
|
||||
"memory": "8GB",
|
||||
},
|
||||
"services": {
|
||||
"server": True,
|
||||
"mcp": True,
|
||||
"agents": False,
|
||||
},
|
||||
"logs": ["Log line 1", "Log line 2"],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def test_health_check_with_defaults(client):
|
||||
"""Test health check returns correct default repository."""
|
||||
with patch.dict(os.environ, {}, clear=False):
|
||||
# Ensure no GITHUB_TOKEN or GITHUB_REPO env vars
|
||||
os.environ.pop("GITHUB_TOKEN", None)
|
||||
os.environ.pop("GITHUB_REPO", None)
|
||||
|
||||
response = client.get("/api/bug-report/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "degraded" # No token
|
||||
assert data["github_token_configured"] is False
|
||||
assert data["github_repo_configured"] is False
|
||||
# Verify it uses the version.py constants
|
||||
assert data["repo"] == f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}"
|
||||
assert data["repo"] == "coleam00/Archon"
|
||||
|
||||
|
||||
def test_health_check_with_github_token(client):
|
||||
"""Test health check when GitHub token is configured."""
|
||||
with patch.dict(os.environ, {"GITHUB_TOKEN": "test-token"}, clear=False):
|
||||
os.environ.pop("GITHUB_REPO", None)
|
||||
|
||||
response = client.get("/api/bug-report/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "healthy"
|
||||
assert data["github_token_configured"] is True
|
||||
assert data["github_repo_configured"] is False
|
||||
assert data["repo"] == f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}"
|
||||
|
||||
|
||||
def test_health_check_with_custom_repo(client):
|
||||
"""Test health check with custom GITHUB_REPO environment variable."""
|
||||
with patch.dict(os.environ, {"GITHUB_REPO": "custom/repo"}, clear=False):
|
||||
response = client.get("/api/bug-report/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["github_repo_configured"] is True
|
||||
assert data["repo"] == "custom/repo"
|
||||
|
||||
|
||||
def test_manual_submission_url_uses_correct_repo(client, mock_bug_report):
|
||||
"""Test that manual submission URL points to correct repository."""
|
||||
with patch.dict(os.environ, {}, clear=False):
|
||||
# No GITHUB_TOKEN, should create manual submission URL
|
||||
os.environ.pop("GITHUB_TOKEN", None)
|
||||
os.environ.pop("GITHUB_REPO", None)
|
||||
|
||||
response = client.post("/api/bug-report/github", json=mock_bug_report)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["success"] is True
|
||||
assert data["issue_url"] is not None
|
||||
# Verify URL contains correct repository
|
||||
expected_repo = f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}"
|
||||
assert expected_repo in data["issue_url"]
|
||||
assert "coleam00/Archon" in data["issue_url"]
|
||||
# Ensure old repository is NOT in URL
|
||||
assert "dynamous-community" not in data["issue_url"]
|
||||
assert "Archon-V2-Alpha" not in data["issue_url"]
|
||||
|
||||
|
||||
def test_api_submission_with_token(client, mock_bug_report):
|
||||
"""Test bug report submission with GitHub token."""
|
||||
mock_response_data = {
|
||||
"success": True,
|
||||
"issue_number": 123,
|
||||
"issue_url": f"https://github.com/{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}/issues/123",
|
||||
}
|
||||
|
||||
with patch.dict(os.environ, {"GITHUB_TOKEN": "test-token"}, clear=False):
|
||||
with patch("src.server.api_routes.bug_report_api.github_service") as mock_service:
|
||||
mock_service.token = "test-token"
|
||||
mock_service.repo = f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}"
|
||||
mock_service.create_issue = AsyncMock(return_value=mock_response_data)
|
||||
|
||||
response = client.post("/api/bug-report/github", json=mock_bug_report)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["success"] is True
|
||||
assert data["issue_number"] == 123
|
||||
# Verify issue URL contains correct repository
|
||||
assert f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}" in data["issue_url"]
|
||||
# Ensure old repository is NOT in URL
|
||||
assert "dynamous-community" not in data["issue_url"]
|
||||
|
||||
|
||||
def test_github_service_initialization():
|
||||
"""Test GitHubService uses correct default repository."""
|
||||
from src.server.api_routes.bug_report_api import GitHubService
|
||||
|
||||
with patch.dict(os.environ, {}, clear=False):
|
||||
os.environ.pop("GITHUB_REPO", None)
|
||||
|
||||
service = GitHubService()
|
||||
|
||||
# Verify service uses version.py constants as default
|
||||
expected_repo = f"{GITHUB_REPO_OWNER}/{GITHUB_REPO_NAME}"
|
||||
assert service.repo == expected_repo
|
||||
assert service.repo == "coleam00/Archon"
|
||||
# Ensure old repository is NOT used
|
||||
assert service.repo != "dynamous-community/Archon-V2-Alpha"
|
||||
|
||||
|
||||
def test_github_service_with_custom_repo():
|
||||
"""Test GitHubService respects GITHUB_REPO environment variable."""
|
||||
from src.server.api_routes.bug_report_api import GitHubService
|
||||
|
||||
with patch.dict(os.environ, {"GITHUB_REPO": "custom/repo"}, clear=False):
|
||||
service = GitHubService()
|
||||
assert service.repo == "custom/repo"
|
||||
Reference in New Issue
Block a user