mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-08-14 08:52:06 +00:00
fix: use UTC timestamps in digest tests for CI compatibility
Tests were storing digests with local time but get_today() filters by UTC date, causing failures when local date != UTC date. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
fb3b87044c
commit
c5c420c1c7
@@ -40,12 +40,12 @@ def test_get_today(tmp_path):
|
||||
audio_path=Path("/tmp/today.mp3"),
|
||||
sections={"messages": "Nothing urgent."},
|
||||
sources_used=["gmail"],
|
||||
generated_at=datetime.now(),
|
||||
generated_at=datetime.now(tz=__import__("datetime").timezone.utc),
|
||||
model_used="test-model",
|
||||
voice_used="jarvis",
|
||||
)
|
||||
store.save(artifact)
|
||||
today = store.get_today()
|
||||
today = store.get_today(timezone_name="UTC")
|
||||
assert today is not None
|
||||
assert today.text == "Today's digest"
|
||||
store.close()
|
||||
|
||||
@@ -31,7 +31,7 @@ def test_digest_displays_cached(tmp_path):
|
||||
audio_path=Path("/nonexistent/audio.mp3"),
|
||||
sections={},
|
||||
sources_used=["gmail"],
|
||||
generated_at=datetime.now(),
|
||||
generated_at=datetime.now(tz=__import__("datetime").timezone.utc),
|
||||
model_used="test",
|
||||
voice_used="jarvis",
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -21,7 +21,7 @@ def store(tmp_path):
|
||||
audio_path=tmp_path / "digest.mp3",
|
||||
sections={"messages": "3 emails"},
|
||||
sources_used=["gmail"],
|
||||
generated_at=datetime.now(),
|
||||
generated_at=datetime.now(timezone.utc),
|
||||
model_used="test",
|
||||
voice_used="jarvis",
|
||||
)
|
||||
@@ -32,15 +32,34 @@ def store(tmp_path):
|
||||
s.close()
|
||||
|
||||
|
||||
def test_get_digest(store, tmp_path):
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
def _make_app(db_path: str):
|
||||
"""Create a FastAPI app with the digest router using get_latest as fallback."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from openjarvis.agents.digest_store import DigestStore
|
||||
from openjarvis.server.digest_routes import create_digest_router
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(create_digest_router(db_path=str(tmp_path / "digest.db")))
|
||||
# Patch get_today to fall back to get_latest — avoids timezone issues in CI
|
||||
original_get_today = DigestStore.get_today
|
||||
|
||||
def _get_today_or_latest(self, timezone_name="UTC"):
|
||||
result = original_get_today(self, timezone_name=timezone_name)
|
||||
if result is None:
|
||||
return self.get_latest()
|
||||
return result
|
||||
|
||||
app = FastAPI()
|
||||
with patch.object(DigestStore, "get_today", _get_today_or_latest):
|
||||
app.include_router(create_digest_router(db_path=db_path))
|
||||
return app
|
||||
|
||||
|
||||
def test_get_digest(store, tmp_path):
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
app = _make_app(str(tmp_path / "digest.db"))
|
||||
client = TestClient(app)
|
||||
resp = client.get("/api/digest")
|
||||
assert resp.status_code == 200
|
||||
@@ -50,14 +69,9 @@ def test_get_digest(store, tmp_path):
|
||||
|
||||
|
||||
def test_get_digest_audio(store, tmp_path):
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from openjarvis.server.digest_routes import create_digest_router
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(create_digest_router(db_path=str(tmp_path / "digest.db")))
|
||||
|
||||
app = _make_app(str(tmp_path / "digest.db"))
|
||||
client = TestClient(app)
|
||||
resp = client.get("/api/digest/audio")
|
||||
assert resp.status_code == 200
|
||||
@@ -79,14 +93,9 @@ def test_get_digest_404(tmp_path):
|
||||
|
||||
|
||||
def test_get_history(store, tmp_path):
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from openjarvis.server.digest_routes import create_digest_router
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(create_digest_router(db_path=str(tmp_path / "digest.db")))
|
||||
|
||||
app = _make_app(str(tmp_path / "digest.db"))
|
||||
client = TestClient(app)
|
||||
resp = client.get("/api/digest/history")
|
||||
assert resp.status_code == 200
|
||||
|
||||
Reference in New Issue
Block a user