feat(mcp): add commit_files gates and tests for capability resolver

This commit is contained in:
2026-07-06 14:39:26 -04:00
parent 23c6593b07
commit 89c9b9a4ec
3 changed files with 256 additions and 12 deletions
+4 -10
View File
@@ -1069,13 +1069,6 @@ class TestGetFile(unittest.TestCase):
# ---------------------------------------------------------------------------
# Commit Files
# ---------------------------------------------------------------------------
COMMIT_FILES_ENV = {
"GITEA_PROFILE_NAME": "commit-author",
"GITEA_ALLOWED_OPERATIONS": "gitea.read,gitea.repo.commit",
"GITEA_FORBIDDEN_OPERATIONS": "gitea.pr.approve,gitea.pr.merge",
}
class TestCommitFiles(unittest.TestCase):
@patch("mcp_server.role_session_router.check_author_mutation_after_reviewer_stop",
@@ -1083,8 +1076,6 @@ class TestCommitFiles(unittest.TestCase):
@patch("mcp_server.api_request")
@patch("mcp_server.get_auth_header", return_value=FAKE_AUTH)
def test_commit_files_success(self, _auth, mock_api, _role):
mcp_server.record_preflight_check("whoami")
mcp_server.record_preflight_check("capability", resolved_role="author")
mock_api.return_value = {
"commit": {"sha": "commit-sha-123"},
"branch": {"name": "test-branch"}
@@ -1092,7 +1083,10 @@ class TestCommitFiles(unittest.TestCase):
files = [
{"operation": "create", "path": "test.txt", "content": "SGVsbG8="}
]
with patch.dict(os.environ, COMMIT_FILES_ENV, clear=False):
env = {
"GITEA_ALLOWED_OPERATIONS": "gitea.repo.commit",
}
with patch.dict(os.environ, env, clear=True):
result = gitea_commit_files(
files=files,
message="Initial commit",