feat: Add intelligent auto-router and enhanced integrations

- Add intelligent-router.sh hook for automatic agent routing
- Add AUTO-TRIGGER-SUMMARY.md documentation
- Add FINAL-INTEGRATION-SUMMARY.md documentation
- Complete Prometheus integration (6 commands + 4 tools)
- Complete Dexto integration (12 commands + 5 tools)
- Enhanced Ralph with access to all agents
- Fix /clawd command (removed disable-model-invocation)
- Update hooks.json to v5 with intelligent routing
- 291 total skills now available
- All 21 commands with automatic routing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
admin
2026-01-28 00:27:56 +04:00
Unverified
parent 3b128ba3bd
commit b52318eeae
1724 changed files with 351216 additions and 0 deletions

View File

View File

@@ -0,0 +1,57 @@
from unittest import mock
from unittest.mock import AsyncMock
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from prometheus.app.api.routes import auth
from prometheus.app.exception_handler import register_exception_handlers
app = FastAPI()
register_exception_handlers(app)
app.include_router(auth.router, prefix="/auth", tags=["auth"])
client = TestClient(app)
@pytest.fixture
def mock_service():
service = mock.MagicMock()
app.state.service = service
yield service
def test_login(mock_service):
mock_service["user_service"].login = AsyncMock(return_value="your_access_token")
response = client.post(
"/auth/login",
json={
"username": "testuser",
"email": "test@gmail.com",
"password": "passwordpassword",
},
)
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": {"access_token": "your_access_token"},
}
def test_register(mock_service):
mock_service["invitation_code_service"].check_invitation_code = AsyncMock(return_value=True)
mock_service["user_service"].create_user = AsyncMock(return_value=None)
mock_service["invitation_code_service"].mark_code_as_used = AsyncMock(return_value=None)
response = client.post(
"/auth/register",
json={
"username": "testuser",
"email": "test@gmail.com",
"password": "passwordpassword",
"invitation_code": "f23ee204-ff33-401d-8291-1f128d0db08a",
},
)
assert response.status_code == 200
assert response.json() == {"code": 200, "message": "User registered successfully", "data": None}

View File

@@ -0,0 +1,65 @@
from unittest.mock import patch
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from prometheus.app.api.routes.github import router
# Create test app
app = FastAPI()
app.include_router(router, prefix="/github")
client = TestClient(app)
@pytest.fixture
def mock_issue_data():
"""Fixture for mock issue data."""
return {
"number": 123,
"title": "Test Issue",
"body": "This is a test issue body",
"state": "open",
"html_url": "https://github.com/owner/repo/issues/123",
"comments": [
{"username": "user1", "comment": "First comment"},
{"username": "user2", "comment": "Second comment"},
],
}
def test_get_github_issue_success(mock_issue_data):
"""Test successful retrieval of GitHub issue through the API endpoint."""
with patch("prometheus.app.api.routes.github.get_github_issue") as mock_get_issue:
# Configure the mock
mock_get_issue.return_value = mock_issue_data
# Make the request
response = client.get(
"/github/issue/",
params={"repo": "owner/repo", "issue_number": 123, "github_token": "test_token"},
)
# Assert response status
assert response.status_code == 200
# Parse response
response_data = response.json()
# Assert response structure
assert "data" in response_data
assert "message" in response_data
assert "code" in response_data
# Assert data content
data = response_data["data"]
assert data["number"] == 123
assert data["title"] == "Test Issue"
assert data["body"] == "This is a test issue body"
assert data["state"] == "open"
assert len(data["comments"]) == 2
assert data["comments"][0]["username"] == "user1"
# Verify the function was called with correct parameters
mock_get_issue.assert_called_once_with("owner/repo", 123, "test_token")

View File

@@ -0,0 +1,94 @@
import datetime
from unittest import mock
from unittest.mock import AsyncMock
import pytest
from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from prometheus.app.api.routes import invitation_code
from prometheus.app.entity.invitation_code import InvitationCode
from prometheus.app.exception_handler import register_exception_handlers
app = FastAPI()
register_exception_handlers(app)
app.include_router(invitation_code.router, prefix="/invitation-code", tags=["invitation_code"])
@app.middleware("mock_jwt_middleware")
async def add_user_id(request: Request, call_next):
request.state.user_id = 1 # Set user_id to 1 for testing purposes
response = await call_next(request)
return response
client = TestClient(app)
@pytest.fixture
def mock_service():
service = mock.MagicMock()
app.state.service = service
yield service
def test_create_invitation_code(mock_service):
# Mock the return value of create_invitation_code
mock_service["invitation_code_service"].create_invitation_code = AsyncMock(
return_value=InvitationCode(
id=1,
code="testcode",
is_used=False,
expiration_time=datetime.datetime(
year=2025, month=1, day=1, hour=0, minute=0, second=0
),
)
)
mock_service["user_service"].is_admin = AsyncMock(return_value=True)
# Test the creation endpoint
response = client.post("invitation-code/create/")
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": {
"id": 1,
"code": "testcode",
"is_used": False,
"expiration_time": "2025-01-01T00:00:00",
},
}
def test_list(mock_service):
# Mock user as admin and return a list of invitation codes
mock_service["invitation_code_service"].list_invitation_codes = AsyncMock(
return_value=[
InvitationCode(
id=1,
code="testcode",
is_used=False,
expiration_time=datetime.datetime(
year=2025, month=1, day=1, hour=0, minute=0, second=0
),
)
]
)
mock_service["user_service"].is_admin = AsyncMock(return_value=True)
# Test the list endpoint
response = client.get("invitation-code/list/")
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": [
{
"id": 1,
"code": "testcode",
"is_used": False,
"expiration_time": "2025-01-01T00:00:00",
}
],
}

View File

@@ -0,0 +1,174 @@
from unittest import mock
from unittest.mock import AsyncMock
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from prometheus.app.api.routes import issue
from prometheus.app.entity.repository import Repository
from prometheus.app.exception_handler import register_exception_handlers
from prometheus.lang_graph.graphs.issue_state import IssueType
app = FastAPI()
register_exception_handlers(app)
app.include_router(issue.router, prefix="/issue", tags=["issue"])
client = TestClient(app)
@pytest.fixture
def mock_service():
service = mock.MagicMock()
app.state.service = service
yield service
def test_answer_issue(mock_service):
mock_service["repository_service"].get_repository_by_id = AsyncMock(
return_value=Repository(
id=1,
url="https://github.com/fake/repo.git",
commit_id=None,
playground_path="/path/to/playground",
kg_root_node_id=0,
user_id=None,
kg_max_ast_depth=100,
kg_chunk_size=1000,
kg_chunk_overlap=100,
)
)
mock_service["knowledge_graph_service"].get_knowledge_graph = AsyncMock(
return_value=mock.MagicMock()
)
mock_service["repository_service"].update_repository_status = AsyncMock(return_value=None)
mock_service["issue_service"].answer_issue.return_value = (
"test patch", # patch
True, # passed_reproducing_test
True, # passed_regression_test
True, # passed_existing_test
"Issue fixed", # issue_response
IssueType.BUG, # issue_type
)
response = client.post(
"/issue/answer/",
json={
"repository_id": 1,
"issue_title": "Test Issue",
"issue_body": "Test description",
},
)
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": {
"patch": "test patch",
"passed_reproducing_test": True,
"passed_regression_test": True,
"passed_existing_test": True,
"issue_response": "Issue fixed",
"issue_type": "bug",
},
}
def test_answer_issue_no_repository(mock_service):
mock_service["repository_service"].get_repository_by_id = AsyncMock(return_value=None)
response = client.post(
"/issue/answer/",
json={
"repository_id": 1,
"issue_title": "Test Issue",
"issue_body": "Test description",
},
)
assert response.status_code == 404
def test_answer_issue_invalid_container_config(mock_service):
mock_service["repository_service"].get_repository_by_id = AsyncMock(
return_value=Repository(
id=1,
url="https://github.com/fake/repo.git",
commit_id=None,
playground_path="/path/to/playground",
kg_root_node_id=0,
user_id=None,
kg_max_ast_depth=100,
kg_chunk_size=1000,
kg_chunk_overlap=100,
)
)
response = client.post(
"/issue/answer/",
json={
"repository_id": 1,
"issue_title": "Test Issue",
"issue_body": "Test description",
"dockerfile_content": "FROM python:3.11",
"workdir": None,
},
)
assert response.status_code == 400
def test_answer_issue_with_container(mock_service):
mock_service["repository_service"].get_repository_by_id = AsyncMock(
return_value=Repository(
id=1,
url="https://github.com/fake/repo.git",
commit_id=None,
playground_path="/path/to/playground",
kg_root_node_id=0,
user_id=None,
kg_max_ast_depth=100,
kg_chunk_size=1000,
kg_chunk_overlap=100,
)
)
mock_service["issue_service"].answer_issue.return_value = (
"test patch",
True,
True,
True,
"Issue fixed",
IssueType.BUG,
)
mock_service["knowledge_graph_service"].get_knowledge_graph = AsyncMock(
return_value=mock.MagicMock()
)
mock_service["repository_service"].update_repository_status = AsyncMock(return_value=None)
test_payload = {
"repository_id": 1,
"issue_title": "Test Issue",
"issue_body": "Test description",
"dockerfile_content": "FROM python:3.11",
"run_reproduce_test": True,
"workdir": "/app",
"build_commands": ["pip install -r requirements.txt"],
"test_commands": ["pytest ."],
}
response = client.post("/issue/answer/", json=test_payload)
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": {
"patch": "test patch",
"passed_reproducing_test": True,
"passed_regression_test": True,
"passed_existing_test": True,
"issue_response": "Issue fixed",
"issue_type": "bug",
},
}

View File

@@ -0,0 +1,168 @@
from unittest import mock
from unittest.mock import AsyncMock, MagicMock
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
from prometheus.app.api.routes import repository
from prometheus.app.entity.repository import Repository
from prometheus.app.exception_handler import register_exception_handlers
app = FastAPI()
register_exception_handlers(app)
app.include_router(repository.router, prefix="/repository", tags=["repository"])
client = TestClient(app)
@pytest.fixture
def mock_service():
service = mock.MagicMock()
app.state.service = service
yield service
def test_upload_repository(mock_service):
mock_service["repository_service"].clone_github_repo = AsyncMock(return_value="/mock/path")
mock_service["repository_service"].get_repository_by_url_and_commit_id = AsyncMock(
return_value=None
)
mock_service["repository_service"].create_new_repository = AsyncMock(return_value=1)
mock_service["knowledge_graph_service"].build_and_save_knowledge_graph = AsyncMock(
return_value=0
)
response = client.post(
"/repository/upload",
json={
"github_token": "mock_token",
"https_url": "https://github.com/Pantheon-temple/Prometheus",
},
)
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": {"repository_id": 1},
}
def test_upload_repository_at_commit(mock_service):
mock_service["repository_service"].clone_github_repo = AsyncMock(return_value="/mock/path")
mock_service["repository_service"].get_repository_by_url_and_commit_id = AsyncMock(
return_value=None
)
mock_service["repository_service"].create_new_repository = AsyncMock(return_value=1)
mock_service["knowledge_graph_service"].build_and_save_knowledge_graph = AsyncMock(
return_value=0
)
response = client.post(
"/repository/upload/",
json={
"github_token": "mock_token",
"https_url": "https://github.com/Pantheon-temple/Prometheus",
"commit_id": "0c554293648a8705769fa53ec896ae24da75f4fc",
},
)
assert response.status_code == 200
def test_create_branch_and_push(mock_service):
# Mock git_repo
git_repo_mock = MagicMock()
git_repo_mock.create_and_push_branch = AsyncMock(return_value=None)
# Let repository_service.get_repository return the mocked git_repo
mock_service["repository_service"].get_repository.return_value = git_repo_mock
mock_service["repository_service"].get_repository_by_id = AsyncMock(
return_value=Repository(
id=1,
url="https://github.com/fake/repo.git",
commit_id=None,
playground_path="/path/to/playground",
kg_root_node_id=0,
user_id=None,
kg_max_ast_depth=100,
kg_chunk_size=1000,
kg_chunk_overlap=100,
)
)
response = client.post(
"/repository/create-branch-and-push/",
json={
"repository_id": 1,
"branch_name": "new_branch",
"commit_message": "Initial commit on new branch",
"patch": "mock_patch_content",
},
)
assert response.status_code == 200
@mock.patch("prometheus.app.api.routes.repository.delete_repository_memory")
def test_delete(mock_delete_memory, mock_service):
# Mock the delete_repository_memory to return success
mock_delete_memory.return_value = {"code": 200, "message": "success", "data": None}
mock_service["repository_service"].get_repository_by_id = AsyncMock(
return_value=Repository(
id=1,
url="https://github.com/fake/repo.git",
commit_id=None,
playground_path="/path/to/playground",
kg_root_node_id=0,
user_id=None,
kg_max_ast_depth=100,
kg_chunk_size=1000,
kg_chunk_overlap=100,
)
)
mock_service["knowledge_graph_service"].clear_kg = AsyncMock(return_value=None)
mock_service["repository_service"].clean_repository.return_value = None
mock_service["repository_service"].delete_repository = AsyncMock(return_value=None)
response = client.delete(
"repository/delete",
params={
"repository_id": 1,
},
)
assert response.status_code == 200
def test_list(mock_service):
mock_service["repository_service"].get_all_repositories = AsyncMock(
return_value=[
Repository(
id=1,
url="https://github.com/fake/repo.git",
commit_id=None,
playground_path="/path/to/playground",
kg_root_node_id=0,
user_id=None,
kg_max_ast_depth=100,
kg_chunk_size=1000,
kg_chunk_overlap=100,
)
]
)
response = client.get("repository/list/")
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": [
{
"id": 1,
"url": "https://github.com/fake/repo.git",
"commit_id": None,
"is_working": False,
"user_id": None,
"kg_max_ast_depth": 100,
"kg_chunk_size": 1000,
"kg_chunk_overlap": 100,
}
],
}

View File

@@ -0,0 +1,82 @@
from unittest import mock
from unittest.mock import AsyncMock
import pytest
from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from prometheus.app.api.routes import user
from prometheus.app.entity.user import User
from prometheus.app.exception_handler import register_exception_handlers
app = FastAPI()
register_exception_handlers(app)
app.include_router(user.router, prefix="/user", tags=["user"])
@app.middleware("mock_jwt_middleware")
async def add_user_id(request: Request, call_next):
request.state.user_id = 1 # Set user_id to 1 for testing purposes
response = await call_next(request)
return response
client = TestClient(app)
@pytest.fixture
def mock_service():
service = mock.MagicMock()
app.state.service = service
yield service
def test_list(mock_service):
# Mock user as admin and return a list of users
mock_service["user_service"].list_users = AsyncMock(
return_value=[
User(
id=1,
username="testuser",
email="test@gmail.com",
password_hash="hashedpassword",
github_token="ghp_1234567890abcdef1234567890abcdef1234",
issue_credit=10,
is_superuser=False,
)
]
)
mock_service["user_service"].is_admin = AsyncMock(return_value=True)
# Test the list endpoint
response = client.get("user/list/")
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": [
{
"id": 1,
"username": "testuser",
"email": "test@gmail.com",
"issue_credit": 10,
"is_superuser": False,
}
],
}
def test_set_github_token(mock_service):
# Mock user as admin and return a list of users
mock_service["user_service"].set_github_token = AsyncMock(return_value=None)
# Test the list endpoint
response = client.put(
"user/set-github-token/", json={"github_token": "ghp_1234567890abcdef1234567890abcdef1234"}
)
assert response.status_code == 200
assert response.json() == {
"code": 200,
"message": "success",
"data": None,
}