diff options
| author | Christian Cleberg <[email protected]> | 2026-05-03 19:39:08 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-05-03 19:39:08 -0500 |
| commit | fdfb7831fe7dba6d17a1697c7cbb731fd008ba7b (patch) | |
| tree | a161d0840809bcdd1f64e5da74fb93b1aea3faaa /tests | |
| parent | 4390684995c9933f213faec2cb20f39af6d506d2 (diff) | |
| download | hutch-stats-fdfb7831fe7dba6d17a1697c7cbb731fd008ba7b.tar.gz hutch-stats-fdfb7831fe7dba6d17a1697c7cbb731fd008ba7b.tar.bz2 hutch-stats-fdfb7831fe7dba6d17a1697c7cbb731fd008ba7b.zip | |
fix: ensure git crawling accounts for all branches
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_git_repository_cache.py | 3 | ||||
| -rw-r--r-- | tests/test_ingestion.py | 55 |
2 files changed, 54 insertions, 4 deletions
diff --git a/tests/test_git_repository_cache.py b/tests/test_git_repository_cache.py index 98a3db3..9326e6f 100644 --- a/tests/test_git_repository_cache.py +++ b/tests/test_git_repository_cache.py @@ -96,6 +96,7 @@ def test_git_poll_reuses_cached_discovered_repositories(db_session) -> None: poller = PollerService(todo_service=todo_service, git_service=git_service, settings=settings) first_inserted = poller.poll_all(db_session, "~ccleberg") + first_poll_user_repository_calls = [call for call in client.calls if "query UserRepositories" in call[0]] second_inserted = poller.poll_all(db_session, "~ccleberg") user_repository_calls = [call for call in client.calls if "query UserRepositories" in call[0]] @@ -103,5 +104,5 @@ def test_git_poll_reuses_cached_discovered_repositories(db_session) -> None: assert first_inserted == 1 assert second_inserted == 0 - assert len(user_repository_calls) == 1 + assert len(user_repository_calls) == len(first_poll_user_repository_calls) assert cached_names == ["~ccleberg/Hutch"] diff --git a/tests/test_ingestion.py b/tests/test_ingestion.py index 6c06359..dc96354 100644 --- a/tests/test_ingestion.py +++ b/tests/test_ingestion.py @@ -210,7 +210,7 @@ def test_todo_ingestion_is_idempotent(db_session) -> None: "results": [ { "id": "1001", - "created": "2026-03-29T10:00:00Z", + "created": "2026-05-01T10:00:00Z", "ticket": { "id": "123", "ref": "~ccleberg/todo/123", @@ -229,7 +229,7 @@ def test_todo_ingestion_is_idempotent(db_session) -> None: }, { "id": "1002", - "created": "2026-03-30T09:00:00Z", + "created": "2026-05-02T09:00:00Z", "ticket": { "id": "123", "ref": "~ccleberg/todo/123", @@ -248,7 +248,7 @@ def test_todo_ingestion_is_idempotent(db_session) -> None: }, { "id": "1003", - "created": "2026-03-30T10:00:00Z", + "created": "2026-05-02T10:00:00Z", "ticket": { "id": "123", "ref": "~ccleberg/todo/123", @@ -507,6 +507,55 @@ def test_git_ingestion_auto_discovers_owned_repositories(db_session) -> None: assert any("query UserRepositories" in call[0] for call in client.calls) +def test_git_ingestion_reads_repository_log_from_default_head_branch(db_session) -> None: + settings = make_settings( + ACTOR_ALIASES_JSON={"~ccleberg": ["[email protected]", "Chris Cleberg"]}, + GIT_TRACKED_REPOSITORIES=["Hutch"], + ) + git_payload = { + "user": { + "repository": { + "name": "Hutch", + "owner": {"canonicalName": "~ccleberg"}, + "HEAD": {"name": "refs/heads/trunk", "target": "abc123"}, + "log": { + "results": [ + { + "id": "abc123", + "shortId": "abc123", + "author": { + "name": "Chris Cleberg", + "email": "[email protected]", + "time": "2026-03-30T12:00:00Z", + }, + "committer": { + "name": "Chris Cleberg", + "email": "[email protected]", + "time": "2026-03-30T12:00:00Z", + }, + "message": "Commit on non-standard default branch", + } + ], + "cursor": None, + }, + } + } + } + client = StubClient(payloads_by_query={"query RepositoryLog": git_payload}) + git_service = GitIngestionService(client, settings) + + result = git_service.fetch_recent_events("~ccleberg", since=datetime(2026, 3, 1, tzinfo=UTC)) + + repository_log_calls = [call for call in client.calls if "query RepositoryLog" in call[0]] + assert len(result.events) == 1 + assert repository_log_calls[0][1] == { + "username": "ccleberg", + "repoName": "Hutch", + "cursor": None, + "from": "HEAD", + } + + def test_sync_overlap_reuses_cursor_window_and_suppresses_duplicates(db_session) -> None: settings = make_settings() event = NormalizedEvent( |
