[CI] Add pre-commit hook to validate test/registered/ files have CI registry (#22308)

Co-authored-by: Alison Shao <alison.shao@Mac.attlocal.net>
Co-authored-by: Alison Shao <alison.shao@MacBook-Pro-D2W773R9CD.local>
This commit is contained in:
Alison Shao
2026-04-08 15:59:15 -07:00
committed by GitHub
co-authored by Alison Shao Alison Shao
parent 5e1a9834f9
commit e41647f52b
2 changed files with 62 additions and 0 deletions
+6
View File
@@ -87,6 +87,12 @@ repos:
language: system
files: ^\.github/workflows/.*\.yml$
pass_filenames: false
- id: check-registered-tests
name: check registered tests have CI registry
entry: python3 scripts/ci/check_registered_tests.py
language: system
files: ^test/registered/.*\.py$
pass_filenames: false
- repo: https://github.com/lycheeverse/lychee.git
rev: lychee-v0.22.0
hooks:
+56
View File
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
"""
Pre-commit hook: validate that all Python test files under test/registered/
contain a CI registry call (register_cuda_ci, register_amd_ci, etc.).
Reuses ut_parse_one_file() from ci_register.py (AST-based parsing)
to match the same logic used by run_suite.py's collect_tests().
"""
import glob
import importlib.util
import os
import sys
def main() -> int:
# Import ci_register directly to avoid pulling in all of sglang
spec = importlib.util.spec_from_file_location(
"ci_register",
os.path.join("python", "sglang", "test", "ci", "ci_register.py"),
)
ci_register = importlib.util.module_from_spec(spec)
spec.loader.exec_module(ci_register)
# Same filter as run_suite.py: skip conftest.py and __init__.py
files = sorted(
f
for f in glob.glob("test/registered/**/*.py", recursive=True)
if not f.endswith("/conftest.py") and not f.endswith("/__init__.py")
)
if not files:
return 0
errors = []
for f in files:
try:
registries = ci_register.ut_parse_one_file(f)
if len(registries) == 0:
errors.append(f)
except Exception:
# Skip files that can't be parsed (syntax errors, etc.)
pass
if errors:
print("ERROR: Files in test/registered/ missing CI registry call:")
print(" Move manual-only tests to test/manual/.\n")
for f in errors:
print(f" {f}")
print()
return 1
return 0
if __name__ == "__main__":
sys.exit(main())