diff --git a/backend/tests/test_local_dev_loopback_bind.py b/backend/tests/test_local_dev_loopback_bind.py index 84eec16ea7..47295b86e5 100644 --- a/backend/tests/test_local_dev_loopback_bind.py +++ b/backend/tests/test_local_dev_loopback_bind.py @@ -246,7 +246,7 @@ def test_default_bind_host_removes_a_config_rendered_for_an_earlier_bind_host(ch result = _run(checkout, bind_host) assert result.returncode == 0, result.stderr - assert Path(result.stdout.strip()) == (checkout / "docker" / "nginx" / "nginx.local.conf").resolve() + assert Path(_normalize_rendered_path(result.stdout.strip())) == (checkout / "docker" / "nginx" / "nginx.local.conf").resolve() assert not rendered.exists(), "a stale render with the old listen lines should not be left behind" diff --git a/backend/tests/test_multi_worker_run_ownership.py b/backend/tests/test_multi_worker_run_ownership.py index 645c702224..f9e1a9402b 100644 --- a/backend/tests/test_multi_worker_run_ownership.py +++ b/backend/tests/test_multi_worker_run_ownership.py @@ -972,6 +972,10 @@ async def test_transient_renewal_exception_before_deadline_keeps_run_alive(): return await original_update_lease(*args, **kwargs) store.update_lease = fail_once_then_renew + # Keep the confirmed deadline inside the 30-second lease window. Renewal + # computes a fresh now+lease value; Windows' coarse clock can otherwise make + # two immediate samples identical and defeat the strict > below. + record.lease_expires_at = (datetime.now(UTC) + timedelta(seconds=10)).isoformat() original_expiry = record.lease_expires_at try: diff --git a/backend/tests/test_project_documents_repo.py b/backend/tests/test_project_documents_repo.py index 2f4f28999c..894b5c8cb4 100644 --- a/backend/tests/test_project_documents_repo.py +++ b/backend/tests/test_project_documents_repo.py @@ -11,7 +11,7 @@ concurrent upload vs project delete, and concurrent duplicate upload. from __future__ import annotations import asyncio -from datetime import UTC, datetime +from datetime import UTC, datetime, timedelta import pytest @@ -137,6 +137,23 @@ class TestReadsFilterTrashed: assert total == 0 +async def _stamp_updated_at(docs: ProjectDocumentRepository, stamps: dict[str, datetime]) -> None: + """Pin ``updated_at`` so ordering tests do not depend on the wall clock. + + Rows inserted back to back can share a timestamp on hosts with a coarse + clock (Windows ticks at ~15.6 ms), which silently falls through to the + ``id`` tie-break. + """ + import sqlalchemy as sa + + from deerflow.persistence.projects.model import ProjectDocumentRow + + async with docs._sf() as session: + for doc_id, updated_at in stamps.items(): + await session.execute(sa.update(ProjectDocumentRow).where(ProjectDocumentRow.id == doc_id).values(updated_at=updated_at)) + await session.commit() + + class TestShelfSnapshot: async def test_ordering_is_updated_desc_id_asc_with_one_round_trip_shape(self, repos): projects, docs = repos @@ -146,13 +163,10 @@ class TestShelfSnapshot: rows.append(await _insert(docs, project["id"], sha=f"{i}" * 64, name=f"f{i}.txt", doc_id=f"d{i}")) # Re-touch d2 so it becomes the most recently updated row. await _insert(docs, project["id"], sha="e" * 64, name="f5.txt", doc_id="d5") - import sqlalchemy as sa - - from deerflow.persistence.projects.model import ProjectDocumentRow - - async with docs._sf() as session: - await session.execute(sa.update(ProjectDocumentRow).where(ProjectDocumentRow.id == "d2").values(updated_at=datetime(2999, 1, 1, tzinfo=UTC))) - await session.commit() + base = datetime(2026, 1, 1, tzinfo=UTC) + stamps = {f"d{i}": base + timedelta(seconds=i) for i in range(6)} + stamps["d2"] = datetime(2999, 1, 1, tzinfo=UTC) + await _stamp_updated_at(docs, stamps) snapshot_rows, total = await docs.shelf_snapshot(project["id"], limit=3, user_id="u1") assert total == 6 @@ -168,6 +182,8 @@ class TestShelfSnapshot: project = await _project(projects) for i in range(7): await _insert(docs, project["id"], sha=f"{i}" * 64, name=f"f{i}.txt", doc_id=f"d{i}") + base = datetime(2026, 1, 1, tzinfo=UTC) + await _stamp_updated_at(docs, {f"d{i}": base + timedelta(seconds=i) for i in range(7)}) seen: list[str] = [] offset = 0 while True: