69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
import pathlib
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'scripts'))
|
|
|
|
import agent_pr_gate # noqa: E402
|
|
|
|
|
|
class TestAgentPrGate(unittest.TestCase):
|
|
def test_classify_risk_low_for_docs_and_tests_only(self):
|
|
level = agent_pr_gate.classify_risk([
|
|
'docs/runbook.md',
|
|
'reports/daily-summary.md',
|
|
'tests/test_agent_pr_gate.py',
|
|
])
|
|
self.assertEqual(level, 'low')
|
|
|
|
def test_classify_risk_high_for_operational_paths(self):
|
|
level = agent_pr_gate.classify_risk([
|
|
'scripts/failover_monitor.py',
|
|
'deploy/playbook.yml',
|
|
])
|
|
self.assertEqual(level, 'high')
|
|
|
|
def test_validate_pr_body_requires_issue_ref_and_verification(self):
|
|
ok, details = agent_pr_gate.validate_pr_body(
|
|
'feat: add thing',
|
|
'What changed only\n\nNo verification section here.'
|
|
)
|
|
self.assertFalse(ok)
|
|
self.assertIn('issue reference', ' '.join(details).lower())
|
|
self.assertIn('verification', ' '.join(details).lower())
|
|
|
|
def test_validate_pr_body_accepts_issue_ref_and_verification(self):
|
|
ok, details = agent_pr_gate.validate_pr_body(
|
|
'feat: add thing (#562)',
|
|
'Refs #562\n\nVerification:\n- pytest -q\n'
|
|
)
|
|
self.assertTrue(ok)
|
|
self.assertEqual(details, [])
|
|
|
|
def test_build_comment_body_reports_failures_and_human_review(self):
|
|
body = agent_pr_gate.build_comment_body(
|
|
syntax_status='success',
|
|
tests_status='failure',
|
|
criteria_status='success',
|
|
risk_level='high',
|
|
)
|
|
self.assertIn('tests', body.lower())
|
|
self.assertIn('failure', body.lower())
|
|
self.assertIn('human review', body.lower())
|
|
|
|
def test_changed_files_file_loader_ignores_blanks(self):
|
|
with tempfile.NamedTemporaryFile('w+', delete=False) as handle:
|
|
handle.write('docs/one.md\n\nreports/two.md\n')
|
|
path = handle.name
|
|
try:
|
|
files = agent_pr_gate.read_changed_files(path)
|
|
finally:
|
|
pathlib.Path(path).unlink(missing_ok=True)
|
|
self.assertEqual(files, ['docs/one.md', 'reports/two.md'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|