仪表盘展示最新运行快照
This commit is contained in:
@@ -191,3 +191,71 @@ def test_dashboard_returns_news_and_github_signals_separately(monkeypatch) -> No
|
||||
assert [item["source_type"] for item in dashboard["github_signals"]] == ["github"]
|
||||
assert github_response.status_code == 200
|
||||
assert [item["title"] for item in github_response.json()] == ["example/agent-kit"]
|
||||
|
||||
|
||||
def test_dashboard_uses_latest_completed_run_signals(monkeypatch) -> None:
|
||||
# 情报页展示最新完成运行的快照,历史运行只保留在记录和明细接口里。
|
||||
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
|
||||
get_settings.cache_clear()
|
||||
engine = create_engine(
|
||||
"sqlite:///:memory:",
|
||||
connect_args={"check_same_thread": False},
|
||||
poolclass=StaticPool,
|
||||
future=True,
|
||||
)
|
||||
TestingSessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False, future=True)
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
with TestingSessionLocal() as session:
|
||||
old_run = AgentRun(status="completed", started_at=datetime(2026, 7, 8, 8, 0), request_payload={})
|
||||
new_run = AgentRun(status="completed", started_at=datetime(2026, 7, 8, 9, 0), request_payload={})
|
||||
session.add_all([old_run, new_run])
|
||||
session.flush()
|
||||
session.add_all(
|
||||
[
|
||||
Signal(
|
||||
run_id=old_run.id,
|
||||
source_type="news",
|
||||
topic="AI 新闻",
|
||||
title="Old signal",
|
||||
summary="旧运行信号。",
|
||||
source_url="https://example.com/old",
|
||||
source_url_hash="old-hash",
|
||||
source_name="Example",
|
||||
published_at=datetime(2026, 7, 8, 8, 0),
|
||||
importance=3,
|
||||
entities=[],
|
||||
),
|
||||
Signal(
|
||||
run_id=new_run.id,
|
||||
source_type="news",
|
||||
topic="AI 新闻",
|
||||
title="New signal",
|
||||
summary="新运行信号。",
|
||||
source_url="https://example.com/new",
|
||||
source_url_hash="new-hash",
|
||||
source_name="Example",
|
||||
published_at=datetime(2026, 7, 8, 9, 0),
|
||||
importance=4,
|
||||
entities=[],
|
||||
),
|
||||
]
|
||||
)
|
||||
session.commit()
|
||||
|
||||
def override_get_db():
|
||||
# 仪表盘快照测试使用内存库构造多运行场景。
|
||||
db = TestingSessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
app = create_app()
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/dashboard")
|
||||
get_settings.cache_clear()
|
||||
|
||||
assert response.status_code == 200
|
||||
assert [item["title"] for item in response.json()["news_signals"]] == ["New signal"]
|
||||
|
||||
Reference in New Issue
Block a user