From be20f9dc8733a7207d06db7114b8fabbe818dca5 Mon Sep 17 00:00:00 2001 From: hummbl-dev Date: Wed, 13 May 2026 09:08:26 -0400 Subject: [PATCH 1/3] fix: freeze datetime in test_recent_commit_scores_max_recency The test used datetime.now() without a mock, causing days_since_commit to grow past 30 as real time passed. Now freezes 'now' at 2026-04-19 (the date the test was authored for) using a patch on arbiter.git_vitality.datetime. Also tightened assertion to exact day count (9 days = Apr 10 -> Apr 19). --- tests/test_git_vitality.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/test_git_vitality.py b/tests/test_git_vitality.py index dad04c7..16a7c04 100644 --- a/tests/test_git_vitality.py +++ b/tests/test_git_vitality.py @@ -1,4 +1,5 @@ import pytest +from datetime import datetime, timezone from unittest.mock import MagicMock, patch from pathlib import Path from arbiter.git_vitality import score_git_vitality, GitVitalityReport @@ -33,15 +34,19 @@ def test_single_committer_scores_low_bus_factor(tmp_path, mock_commits): def test_recent_commit_scores_max_recency(tmp_path, mock_commits): (tmp_path / ".git").mkdir() - # Today is 2026-04-19 (from session context) - # mock_commits[0] is from 2026-04-10 (9 days ago) - with patch("arbiter.git_vitality.walk_commits", return_value=mock_commits): - with patch("subprocess.run") as mock_run: - mock_run.return_value.returncode = 0 - mock_run.return_value.stdout = "" - report = score_git_vitality(tmp_path) - assert report.days_since_commit <= 30 - # 25 points for recency + # Freeze "now" at 2026-04-19 so days_since stays deterministic + frozen_now = datetime(2026, 4, 19, tzinfo=timezone.utc) + with patch("arbiter.git_vitality.datetime") as mock_dt: + mock_dt.now.return_value = frozen_now + mock_dt.fromisoformat = datetime.fromisoformat + mock_dt.timezone = timezone + with patch("arbiter.git_vitality.walk_commits", return_value=mock_commits): + with patch("subprocess.run") as mock_run: + mock_run.return_value.returncode = 0 + mock_run.return_value.stdout = "" + report = score_git_vitality(tmp_path) + assert report.days_since_commit == 9 # Apr 10 → Apr 19 + assert report.score >= 25 # max recency points def test_semver_tags_detected(tmp_path, mock_commits): (tmp_path / ".git").mkdir() From 54ea3b54ce387bc9f709de3d4645596dfc9a01f1 Mon Sep 17 00:00:00 2001 From: hummbl-dev Date: Wed, 13 May 2026 12:50:01 -0400 Subject: [PATCH 2/3] test: align git vitality recency expectation --- tests/test_git_vitality.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/test_git_vitality.py b/tests/test_git_vitality.py index 16a7c04..187fa84 100644 --- a/tests/test_git_vitality.py +++ b/tests/test_git_vitality.py @@ -1,8 +1,7 @@ import pytest from datetime import datetime, timezone from unittest.mock import MagicMock, patch -from pathlib import Path -from arbiter.git_vitality import score_git_vitality, GitVitalityReport +from arbiter.git_vitality import score_git_vitality from arbiter.git_historian import CommitInfo @pytest.fixture @@ -34,18 +33,21 @@ def test_single_committer_scores_low_bus_factor(tmp_path, mock_commits): def test_recent_commit_scores_max_recency(tmp_path, mock_commits): (tmp_path / ".git").mkdir() - # Freeze "now" at 2026-04-19 so days_since stays deterministic + # Freeze "now" at 2026-04-19 so days_since stays deterministic. + # datetime.datetime is a C extension, so we patch the module binding + # rather than the classmethod (setattr fails on C types). frozen_now = datetime(2026, 4, 19, tzinfo=timezone.utc) - with patch("arbiter.git_vitality.datetime") as mock_dt: - mock_dt.now.return_value = frozen_now - mock_dt.fromisoformat = datetime.fromisoformat - mock_dt.timezone = timezone + mock_dt = MagicMock() + mock_dt.now = lambda tz=None: frozen_now + mock_dt.fromisoformat = lambda ts: datetime.fromisoformat(ts) + mock_dt.timezone = timezone + with patch("arbiter.git_vitality.datetime", mock_dt): with patch("arbiter.git_vitality.walk_commits", return_value=mock_commits): with patch("subprocess.run") as mock_run: mock_run.return_value.returncode = 0 mock_run.return_value.stdout = "" report = score_git_vitality(tmp_path) - assert report.days_since_commit == 9 # Apr 10 → Apr 19 + assert report.days_since_commit == 8 # Apr 10 10:00 -> Apr 19 00:00 assert report.score >= 25 # max recency points def test_semver_tags_detected(tmp_path, mock_commits): From 6bd0e68ecc147d77b023beb69d2f26ac0f2afc00 Mon Sep 17 00:00:00 2001 From: hummbl-dev Date: Wed, 13 May 2026 12:51:54 -0400 Subject: [PATCH 3/3] test: avoid unused timezone mock argument --- tests/test_git_vitality.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_git_vitality.py b/tests/test_git_vitality.py index 187fa84..8fa457a 100644 --- a/tests/test_git_vitality.py +++ b/tests/test_git_vitality.py @@ -38,7 +38,7 @@ def test_recent_commit_scores_max_recency(tmp_path, mock_commits): # rather than the classmethod (setattr fails on C types). frozen_now = datetime(2026, 4, 19, tzinfo=timezone.utc) mock_dt = MagicMock() - mock_dt.now = lambda tz=None: frozen_now + mock_dt.now = lambda *_args, **_kwargs: frozen_now mock_dt.fromisoformat = lambda ts: datetime.fromisoformat(ts) mock_dt.timezone = timezone with patch("arbiter.git_vitality.datetime", mock_dt):