feat: add prgs-reconciler profile model and role detection (Closes #304)
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
"""Tests for reconciler profile model (#304)."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import gitea_mcp_server as mcp_server
|
||||
import migrate_profiles
|
||||
import reconciler_profile
|
||||
|
||||
|
||||
PRGS_RECONCILER_ALLOWED = [
|
||||
"gitea.read",
|
||||
"gitea.pr.comment",
|
||||
"gitea.issue.comment",
|
||||
"gitea.issue.close",
|
||||
"gitea.pr.close",
|
||||
]
|
||||
PRGS_RECONCILER_FORBIDDEN = [
|
||||
"gitea.pr.approve",
|
||||
"gitea.pr.merge",
|
||||
"gitea.pr.create",
|
||||
"gitea.branch.push",
|
||||
]
|
||||
|
||||
|
||||
class TestReconcilerProfileModel(unittest.TestCase):
|
||||
def test_prgs_reconciler_shape_valid(self):
|
||||
result = reconciler_profile.assess_reconciler_profile(
|
||||
PRGS_RECONCILER_ALLOWED,
|
||||
PRGS_RECONCILER_FORBIDDEN,
|
||||
)
|
||||
self.assertTrue(result["is_reconciler_profile"])
|
||||
self.assertTrue(result["valid"])
|
||||
self.assertEqual(result["reasons"], [])
|
||||
|
||||
def test_author_profile_not_reconciler(self):
|
||||
allowed = [
|
||||
"gitea.read",
|
||||
"gitea.pr.create",
|
||||
"gitea.branch.push",
|
||||
"gitea.issue.comment",
|
||||
]
|
||||
forbidden = ["gitea.pr.approve", "gitea.pr.merge"]
|
||||
self.assertFalse(
|
||||
reconciler_profile.is_reconciler_profile(allowed, forbidden)
|
||||
)
|
||||
|
||||
def test_reviewer_profile_not_reconciler(self):
|
||||
allowed = [
|
||||
"gitea.read",
|
||||
"gitea.pr.review",
|
||||
"gitea.pr.approve",
|
||||
"gitea.pr.merge",
|
||||
]
|
||||
forbidden = ["gitea.pr.create", "gitea.branch.push"]
|
||||
self.assertFalse(
|
||||
reconciler_profile.is_reconciler_profile(allowed, forbidden)
|
||||
)
|
||||
|
||||
def test_broad_close_on_author_invalid(self):
|
||||
allowed = PRGS_RECONCILER_ALLOWED + ["gitea.pr.create"]
|
||||
result = reconciler_profile.assess_reconciler_profile(
|
||||
allowed,
|
||||
PRGS_RECONCILER_FORBIDDEN,
|
||||
)
|
||||
self.assertFalse(result["valid"])
|
||||
self.assertFalse(result["is_reconciler_profile"])
|
||||
|
||||
def test_role_kind_detects_reconciler(self):
|
||||
role = mcp_server._role_kind(
|
||||
PRGS_RECONCILER_ALLOWED,
|
||||
PRGS_RECONCILER_FORBIDDEN,
|
||||
)
|
||||
self.assertEqual(role, "reconciler")
|
||||
|
||||
def test_migrate_infer_role_reconciler(self):
|
||||
self.assertEqual(
|
||||
migrate_profiles.infer_role("prgs-reconciler", "prgs-reconciler"),
|
||||
"reconciler",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user