Files
antigravity-skills-reference/tools/scripts/tests/test_sync_contributors.py
sickn33 694721223c feat(repo): Add contributor sync and consistency audits
Add maintainer automation for repo-state hygiene so contributor acknowledgements, count-sensitive docs, and GitHub About metadata stay aligned from the same workflow.

Cover the new scripts with regression tests and wire them into the local test suite to keep future maintenance changes from drifting silently.
2026-03-21 10:48:00 +01:00

87 lines
3.0 KiB
Python

import importlib.util
import sys
import unittest
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[3]
TOOLS_SCRIPTS_DIR = REPO_ROOT / "tools" / "scripts"
if str(TOOLS_SCRIPTS_DIR) not in sys.path:
sys.path.insert(0, str(TOOLS_SCRIPTS_DIR))
def load_module(relative_path: str, module_name: str):
module_path = REPO_ROOT / relative_path
spec = importlib.util.spec_from_file_location(module_name, module_path)
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module
sync_contributors = load_module(
"tools/scripts/sync_contributors.py",
"sync_contributors_test",
)
class SyncContributorsTests(unittest.TestCase):
def test_parse_existing_contributor_links_preserves_custom_urls(self):
content = """## Repo Contributors
- [@alice](https://github.com/alice)
- [@github-actions[bot]](https://github.com/apps/github-actions)
- [@Copilot](https://github.com/apps/copilot-swe-agent)
"""
links = sync_contributors.parse_existing_contributor_links(content)
self.assertEqual(links["alice"], "https://github.com/alice")
self.assertEqual(links["github-actions[bot]"], "https://github.com/apps/github-actions")
self.assertEqual(links["Copilot"], "https://github.com/apps/copilot-swe-agent")
def test_update_repo_contributors_section_renders_latest_contributors(self):
content = """## Repo Contributors
<a href="https://github.com/sickn33/antigravity-awesome-skills/graphs/contributors">
<img src="https://contrib.rocks/image?repo=sickn33/antigravity-awesome-skills" alt="Repository contributors" />
</a>
Made with [contrib.rocks](https://contrib.rocks).
We officially thank the following contributors for their help in making this repository awesome!
- [@alice](https://github.com/alice)
- [@Copilot](https://github.com/apps/copilot-swe-agent)
## License
"""
updated = sync_contributors.update_repo_contributors_section(
content,
["alice", "github-actions[bot]", "Copilot", "new-user"],
)
self.assertIn("- [@alice](https://github.com/alice)", updated)
self.assertIn("- [@github-actions[bot]](https://github.com/apps/github-actions)", updated)
self.assertIn("- [@Copilot](https://github.com/apps/copilot-swe-agent)", updated)
self.assertIn("- [@new-user](https://github.com/new-user)", updated)
self.assertEqual(updated.count("## Repo Contributors"), 1)
self.assertEqual(updated.count("## License"), 1)
def test_parse_contributors_response_dedupes_and_sorts_order(self):
payload = [
{"login": "alice"},
{"login": "bob"},
{"login": "alice"},
{"login": "github-actions[bot]"},
]
contributors = sync_contributors.parse_contributors_response(payload)
self.assertEqual(contributors, ["alice", "bob", "github-actions[bot]"])
if __name__ == "__main__":
unittest.main()