(cfg: ToolConfig, records: list[FileRecord])
| 989 | # Check enforcement |
| 990 | # ----------------------------- |
| 991 | def enforce(cfg: ToolConfig, records: list[FileRecord]) -> list[str]: |
| 992 | pol = cfg.policy |
| 993 | violations: list[str] = [] |
| 994 | today = _iso_today() |
| 995 | |
| 996 | for r in records: |
| 997 | if r.meta and r.meta.ignore: |
| 998 | continue |
| 999 | if r.kind not in {"ipynb", "md"}: |
| 1000 | continue |
| 1001 | |
| 1002 | has_invalid_metadata = "invalid_metadata" in (r.warnings or []) |
| 1003 | |
| 1004 | if match_allowlist(r.path, pol.require_metadata): |
| 1005 | if has_invalid_metadata: |
| 1006 | violations.append(f"{r.path}: invalid metadata") |
| 1007 | elif r.meta is None: |
| 1008 | violations.append(f"{r.path}: missing metadata") |
| 1009 | |
| 1010 | if match_allowlist(r.path, pol.require_recent_verification): |
| 1011 | if has_invalid_metadata: |
| 1012 | violations.append(f"{r.path}: invalid metadata") |
| 1013 | else: |
| 1014 | lv = r.meta.last_verified if r.meta else None |
| 1015 | if lv is None: |
| 1016 | violations.append(f"{r.path}: missing last_verified") |
| 1017 | else: |
| 1018 | days = (today - lv).days |
| 1019 | if days > pol.warn_if_verified_older_than_days: |
| 1020 | violations.append( |
| 1021 | f"{r.path}: last_verified is {days}d old (> {pol.warn_if_verified_older_than_days}d)" |
| 1022 | ) |
| 1023 | |
| 1024 | if r.kind == "ipynb" and match_allowlist(r.path, pol.require_notebook_normalized): |
| 1025 | if "notebook_not_normalized" in (r.warnings or []): |
| 1026 | violations.append(f"{r.path}: notebook is not normalized (run update/format)") |
| 1027 | |
| 1028 | return violations |
| 1029 | |
| 1030 | |
| 1031 | # ----------------------------- |
no test coverage detected