drift.py
python
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83
chore(governance): sync handover+roadmap to 84db8c8 (drift:…
Human
1 day ago
| 1 | """Kit drift computation for ``overseer status``.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from cli.footprint import FootprintFile |
| 6 | from cli.sync_classify import Classification, classify_footprint |
| 7 | from cli.version_lock import VersionLock |
| 8 | |
| 9 | |
| 10 | def parse_semver(version: str) -> tuple[int, int, int]: |
| 11 | """Parse a simple ``major.minor.patch`` semver string.""" |
| 12 | parts = version.strip().split(".") |
| 13 | if len(parts) != 3: |
| 14 | raise ValueError(f"invalid semver: {version!r}") |
| 15 | return int(parts[0]), int(parts[1]), int(parts[2]) |
| 16 | |
| 17 | |
| 18 | def compare_semver(left: str, right: str) -> int: |
| 19 | """Compare semver strings; return -1, 0, or 1.""" |
| 20 | lv = parse_semver(left) |
| 21 | rv = parse_semver(right) |
| 22 | if lv < rv: |
| 23 | return -1 |
| 24 | if lv > rv: |
| 25 | return 1 |
| 26 | return 0 |
| 27 | |
| 28 | |
| 29 | def compute_drift( |
| 30 | *, |
| 31 | cli_version: str, |
| 32 | lock: VersionLock | None, |
| 33 | rendered: list[FootprintFile], |
| 34 | repo_root, |
| 35 | ) -> dict: |
| 36 | """Return the frozen drift report object.""" |
| 37 | if lock is None: |
| 38 | return { |
| 39 | "status": "behind", |
| 40 | "kit_version": cli_version, |
| 41 | "lock_version": None, |
| 42 | "changed_files": [f.destination for f in rendered], |
| 43 | } |
| 44 | |
| 45 | cmp_result = compare_semver(lock.kit_version, cli_version) |
| 46 | if cmp_result == 0: |
| 47 | status = "current" |
| 48 | changed: list[str] = [] |
| 49 | elif cmp_result < 0: |
| 50 | status = "behind" |
| 51 | classified = classify_footprint(rendered, lock, repo_root) |
| 52 | changed = [ |
| 53 | row.destination |
| 54 | for row in classified |
| 55 | if row.classification |
| 56 | in {Classification.KIT_UPDATED, Classification.BOTH_CHANGED, Classification.MISSING} |
| 57 | ] |
| 58 | else: |
| 59 | status = "ahead" |
| 60 | changed = [] |
| 61 | |
| 62 | return { |
| 63 | "status": status, |
| 64 | "kit_version": cli_version, |
| 65 | "lock_version": lock.kit_version, |
| 66 | "changed_files": changed, |
| 67 | } |
File History
1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199
fix(ISR): default require_independent_second_reviewer to require
Human
minor
⚠
1 day ago