Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(github-source): refresh unchanged sync state (#1490)

AoHanBei9d25cb264e61
diff --git a/tests/services/test_github_source_unchanged_sync.py b/tests/services/test_github_source_unchanged_sync.py
index f886c7b72..a42470e80 100644
--- a/tests/services/test_github_source_unchanged_sync.py
+++ b/tests/services/test_github_source_unchanged_sync.py
@@ -10,11 +10,13 @@ source current (#1489).
from __future__ import annotations
+from datetime import datetime
from pathlib import Path
from typing import Any
import pytest
+from deeptutor.services.base_sync import is_stale
from deeptutor.services.github_source import sync as sync_module
@@ -25,6 +27,8 @@ class _Client:
self.sha = sha
async def get_latest_commit_sha(self, repo: str, branch: str) -> str:
+ assert repo == "owner/repo"
+ assert branch == "main"
return self.sha
async def get_tree(self, *args: Any, **kwargs: Any):
@@ -33,6 +37,9 @@ class _Client:
async def compare_commits(self, *args: Any, **kwargs: Any):
raise AssertionError("an unchanged source must not compare commits")
+ async def download_file(self, *args: Any, **kwargs: Any):
+ raise AssertionError("an unchanged source must not download files")
+
@pytest.fixture
def recorded_state(monkeypatch: pytest.MonkeyPatch) -> list[dict[str, Any]]:
@@ -50,6 +57,11 @@ def recorded_state(monkeypatch: pytest.MonkeyPatch) -> list[dict[str, Any]]:
"deeptutor.services.rag.provider_binding.resolve_bound_provider",
lambda base_dir, kb_name: "llamaindex",
)
+
+ async def fail_index(*args: Any, **kwargs: Any) -> None:
+ raise AssertionError("an unchanged source must not update the index")
+
+ monkeypatch.setattr(sync_module, "_index_files", fail_index)
return writes
@@ -78,5 +90,11 @@ async def test_unchanged_source_is_marked_fresh_and_its_old_error_cleared(
assert written["last_sync_error"] is None
assert written["last_synced_sha"] == "deadbeef"
assert written["last_synced_at"] > "2020-01-01T00:00:00Z"
+ assert datetime.fromisoformat(written["last_synced_at"]).tzinfo is not None
# Nothing was transferred, so the last real transfer's count must survive.
assert "files_synced" not in written
+
+ refreshed_source = source | {
+ key: value for key, value in written.items() if key not in {"kb_name", "source_id"}
+ }
+ assert is_stale(refreshed_source, stale_hours=24) is False