#!/usr/bin/env python3 """Direct recommendation to include tests when source files change. Always exits 0 (non-blocking). Prints an assertive warning when source files are staged without any test files. """ import sys from pathlib import Path # Allow importing sibling module sys.path.insert(0, str(Path(__file__).resolve().parent)) from _commit_analysis import analyze_commit, suggest_test_path def main(): analysis = analyze_commit() # Silent exit: no source files staged if not analysis.source_files: return 0 # Silent exit: tests already included if analysis.has_tests: return 0 # Print assertive warning print() print(" \033[33mTest Coverage Recommendation\033[0m") print(" " + "-" * 40) print( f" You're committing {len(analysis.source_files)} source file(s) " "with no test files." ) print() print(" Source files and suggested tests:") for f in analysis.source_files: suggested = suggest_test_path(f.path) print(f" {f.path} (+{f.added} lines)") print(f" -> {suggested}") print() print(" Adding tests helps catch regressions and documents behavior.") print() return 0 if __name__ == "__main__": sys.exit(main())