mirror of
https://github.com/elementalsouls/Claude-BugHunter.git
synced 2026-12-06 21:16:56 +08:00
Refresh stale skill/command/hunt/regex counts and dead links across README, banner, engagement-flow SVGs, cbh-cli, credits, and the issue template. check_doc_counts now validates the home.html count-up data-to AND fallback values and the web-capability card's hunt count, so a count bump can't drift them silently. lint_skills enforces report_count against the HackerOne report URLs its disclosed- reports file actually cites, with a count-convention note for CVE-only cases.
117 lines
5.3 KiB
Python
117 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Regression tests for the documentation count checker and its CI triggers."""
|
|
import re
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
import check_doc_counts as counts
|
|
|
|
|
|
class DocCountTests(unittest.TestCase):
|
|
def check_hero(self, skills, commands):
|
|
hero = f"**{skills} skills** · {commands} slash commands · details"
|
|
checks = [check for check in counts.CHECKS if check[3].startswith("hero line")]
|
|
self.assertEqual(len(checks), 2)
|
|
with patch.object(counts, "CHECKS", checks), patch.object(
|
|
counts, "read", return_value=hero
|
|
):
|
|
return counts.check_assertions({"total": 85, "commands": 17})
|
|
|
|
def test_command_count_can_increase(self):
|
|
self.assertEqual(self.check_hero(85, 17), [])
|
|
|
|
def test_stale_command_count_is_reported(self):
|
|
errors = self.check_hero(85, 16)
|
|
self.assertEqual(len(errors), 1)
|
|
self.assertIn("says 16 but actual commands count is 17", errors[0])
|
|
|
|
def test_stale_skill_count_is_reported(self):
|
|
errors = self.check_hero(84, 17)
|
|
self.assertEqual(len(errors), 1)
|
|
self.assertIn("says 84 but actual total count is 85", errors[0])
|
|
|
|
def check_home_tiles(self, skills=(85, 85), hunt=(58, 58), commands=(16, 16)):
|
|
html = "\n".join(
|
|
[
|
|
f'<div class="stat"><div class="n" data-to="{skills[0]}">{skills[1]}</div><div class="l">Skills</div></div>',
|
|
f'<div class="stat"><div class="n" data-to="{hunt[0]}">{hunt[1]}</div><div class="l">Hunt modules</div></div>',
|
|
f'<div class="stat"><div class="n" data-to="{commands[0]}">{commands[1]}</div><div class="l">Slash commands</div></div>',
|
|
]
|
|
)
|
|
checks = [
|
|
check for check in counts.CHECKS if check[3].startswith("home.html count-up")
|
|
]
|
|
self.assertEqual(len(checks), 3)
|
|
with patch.object(counts, "CHECKS", checks), patch.object(
|
|
counts, "read", return_value=html
|
|
):
|
|
return counts.check_assertions({"total": 85, "hunt": 58, "commands": 16})
|
|
|
|
def check_home_web_card(self, hunt):
|
|
html = f"<h3>{hunt} vuln-class skills</h3>"
|
|
checks = [
|
|
check
|
|
for check in counts.CHECKS
|
|
if check[3] == "home.html web capability card hunt count"
|
|
]
|
|
self.assertEqual(len(checks), 1)
|
|
with patch.object(counts, "CHECKS", checks), patch.object(
|
|
counts, "read", return_value=html
|
|
):
|
|
return counts.check_assertions({"total": 85, "hunt": 58, "commands": 16})
|
|
|
|
def test_home_count_up_tiles_match(self):
|
|
self.assertEqual(self.check_home_tiles(), [])
|
|
|
|
def test_home_count_up_tiles_report_data_to_and_fallback_drift(self):
|
|
cases = [
|
|
("skills data-to", {"skills": (84, 85)}, "home.html count-up Skills tile", "says 84 but actual total count is 85"),
|
|
("skills fallback", {"skills": (85, 84)}, "home.html count-up Skills tile", "says 84 but actual total count is 85"),
|
|
("hunt data-to", {"hunt": (57, 58)}, "home.html count-up Hunt-modules tile", "says 57 but actual hunt count is 58"),
|
|
("hunt fallback", {"hunt": (58, 57)}, "home.html count-up Hunt-modules tile", "says 57 but actual hunt count is 58"),
|
|
("commands data-to", {"commands": (15, 16)}, "home.html count-up Slash-commands tile", "says 15 but actual commands count is 16"),
|
|
("commands fallback", {"commands": (16, 15)}, "home.html count-up Slash-commands tile", "says 15 but actual commands count is 16"),
|
|
]
|
|
for case_name, kwargs, label, expected_msg in cases:
|
|
with self.subTest(case=case_name):
|
|
errors = self.check_home_tiles(**kwargs)
|
|
self.assertEqual(len(errors), 1)
|
|
self.assertIn(label, errors[0])
|
|
self.assertIn(expected_msg, errors[0])
|
|
|
|
def test_home_web_card_hunt_count(self):
|
|
self.assertEqual(self.check_home_web_card(58), [])
|
|
errors = self.check_home_web_card(57)
|
|
self.assertEqual(len(errors), 1)
|
|
self.assertIn("home.html web capability card hunt count", errors[0])
|
|
self.assertIn("says 57 but actual hunt count is 58", errors[0])
|
|
|
|
def test_ci_covers_every_checked_file(self):
|
|
workflow = (Path(counts.REPO) / ".github/workflows/doc-count-check.yml").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
required = {check[0] for check in counts.CHECKS} | {
|
|
"README.md",
|
|
"docs/skills.md",
|
|
"skills/**",
|
|
"commands/**",
|
|
"scripts/check_doc_counts.py",
|
|
"scripts/test_doc_counts.py",
|
|
".github/workflows/doc-count-check.yml",
|
|
}
|
|
# The workflow deliberately uses explicit, quoted path filters for
|
|
# both events. Check that contract without adding a YAML dependency.
|
|
for event in ("pull_request", "push"):
|
|
with self.subTest(event=event):
|
|
block = re.search(
|
|
rf"^ {event}:\n((?: .*\n)+)", workflow, re.MULTILINE
|
|
)
|
|
self.assertIsNotNone(block)
|
|
paths = set(re.findall(r'^ - "([^"]+)"$', block.group(1), re.MULTILINE))
|
|
self.assertEqual(required - paths, set())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|