Merge pull request 'Add fail-closed PR inventory wall when list_prs returns an unexpected empty queue (Issue #194)' (#195) from feat/issue-194-fail-closed-pr-inventory-wall into master
This commit was merged in pull request #195.
This commit is contained in:
@@ -27,6 +27,7 @@ from review_proofs import ( # noqa: E402
|
||||
assess_self_review_contamination,
|
||||
assess_validation_report,
|
||||
build_final_report,
|
||||
pr_inventory_trust_gate,
|
||||
resolve_repos_from_user_reference,
|
||||
verify_pinned_head_checkout,
|
||||
)
|
||||
@@ -796,5 +797,87 @@ class TestControllerHandoff(unittest.TestCase):
|
||||
self.assertIn("issue #182", skill)
|
||||
|
||||
|
||||
class TestPRInventoryTrustGate(unittest.TestCase):
|
||||
"""Issue #194: unit tests for the PR inventory trust gate."""
|
||||
|
||||
def setUp(self):
|
||||
self.profile = {
|
||||
"profile_name": "prgs-reviewer",
|
||||
"allowed_operations": ["read", "gitea.read", "gitea.pr.approve"],
|
||||
}
|
||||
self.local_url = "https://gitea.prgs.cc/Scaled-Tech-Consulting/Gitea-Tools.git"
|
||||
|
||||
def test_trusted_nonempty(self):
|
||||
res = pr_inventory_trust_gate([{"number": 1}])
|
||||
self.assertEqual(res["status"], "trusted_nonempty")
|
||||
self.assertFalse(res["corroborated"])
|
||||
|
||||
def test_inventory_error_none_or_not_list(self):
|
||||
self.assertEqual(pr_inventory_trust_gate(None)["status"], "inventory_error")
|
||||
self.assertEqual(pr_inventory_trust_gate("not a list")["status"], "inventory_error")
|
||||
|
||||
def test_untrusted_empty_no_pagination_or_corroboration(self):
|
||||
res = pr_inventory_trust_gate(
|
||||
[], remote="prgs", org="Scaled-Tech-Consulting", repo="Gitea-Tools",
|
||||
state="open", authenticated_profile=self.profile,
|
||||
local_remote_url=self.local_url, user_context=None,
|
||||
corroboration_open_pr_counter=None, has_finality_metadata=False
|
||||
)
|
||||
self.assertEqual(res["status"], "untrusted_empty")
|
||||
self.assertIn("pagination finality not proven and open_pr_counter corroboration is missing or non-zero", res["reasons"])
|
||||
|
||||
def test_untrusted_empty_profile_permission_mismatch(self):
|
||||
bad_profile = {"profile_name": "prgs-bad", "allowed_operations": ["write"]}
|
||||
res = pr_inventory_trust_gate(
|
||||
[], remote="prgs", org="Scaled-Tech-Consulting", repo="Gitea-Tools",
|
||||
state="open", authenticated_profile=bad_profile,
|
||||
local_remote_url=self.local_url, user_context=None,
|
||||
corroboration_open_pr_counter=0, has_finality_metadata=False
|
||||
)
|
||||
self.assertEqual(res["status"], "untrusted_empty")
|
||||
self.assertIn("authenticated profile lacks read permissions", res["reasons"])
|
||||
|
||||
def test_untrusted_empty_remote_url_mismatch(self):
|
||||
bad_url = "https://gitea.prgs.cc/other-org/other-repo.git"
|
||||
res = pr_inventory_trust_gate(
|
||||
[], remote="prgs", org="Scaled-Tech-Consulting", repo="Gitea-Tools",
|
||||
state="open", authenticated_profile=self.profile,
|
||||
local_remote_url=bad_url, user_context=None,
|
||||
corroboration_open_pr_counter=0, has_finality_metadata=False
|
||||
)
|
||||
self.assertEqual(res["status"], "untrusted_empty")
|
||||
self.assertIn("local remote URL does not match target repository 'Scaled-Tech-Consulting/Gitea-Tools'", res["reasons"])
|
||||
|
||||
def test_untrusted_empty_user_context_indicates_prs(self):
|
||||
res = pr_inventory_trust_gate(
|
||||
[], remote="prgs", org="Scaled-Tech-Consulting", repo="Gitea-Tools",
|
||||
state="open", authenticated_profile=self.profile,
|
||||
local_remote_url=self.local_url, user_context="please check open PR #181",
|
||||
corroboration_open_pr_counter=0, has_finality_metadata=False
|
||||
)
|
||||
self.assertEqual(res["status"], "untrusted_empty")
|
||||
self.assertTrue(any("user context indicates open PRs should exist" in r for r in res["reasons"]))
|
||||
|
||||
def test_trusted_empty_with_corroboration(self):
|
||||
res = pr_inventory_trust_gate(
|
||||
[], remote="prgs", org="Scaled-Tech-Consulting", repo="Gitea-Tools",
|
||||
state="open", authenticated_profile=self.profile,
|
||||
local_remote_url=self.local_url, user_context=None,
|
||||
corroboration_open_pr_counter=0, has_finality_metadata=False
|
||||
)
|
||||
self.assertEqual(res["status"], "trusted_empty")
|
||||
self.assertTrue(res["corroborated"])
|
||||
|
||||
def test_trusted_empty_with_finality_metadata(self):
|
||||
res = pr_inventory_trust_gate(
|
||||
[], remote="prgs", org="Scaled-Tech-Consulting", repo="Gitea-Tools",
|
||||
state="open", authenticated_profile=self.profile,
|
||||
local_remote_url=self.local_url, user_context=None,
|
||||
corroboration_open_pr_counter=None, has_finality_metadata=True
|
||||
)
|
||||
self.assertEqual(res["status"], "trusted_empty")
|
||||
self.assertTrue(res["corroborated"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user