暂停情报采集任务

This commit is contained in:
Codex
2026-07-10 13:27:53 +08:00
parent 0a045a0c4b
commit bc4bbe0dde
8 changed files with 45 additions and 63 deletions
+18 -3
View File
@@ -36,15 +36,16 @@ def test_home_page_returns_dashboard_shell(monkeypatch) -> None:
assert response.status_code == 200
assert "SignalScout" in response.text
assert "今日 AI 信号" in response.text
assert "手动搜索" in response.text
assert "手动搜索" not in response.text
assert "renderMarkdownReport" in response.text
assert "自动记录" not in response.text
assert "采集今日情报" not in response.text
def test_manual_agent_run_endpoint_starts_background_job(monkeypatch) -> None:
# 手动搜索入口复用调度任务,方便验证每轮候选和入库数量。
def test_manual_agent_run_endpoint_starts_background_job_when_enabled(monkeypatch) -> None:
# 启用采集后手动入口复用调度任务,方便验证每轮候选和入库数量。
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
monkeypatch.setenv("SIGNALSCOUT_AGENT_ENABLED", "true")
get_settings.cache_clear()
started = []
engine = create_engine(
@@ -82,6 +83,7 @@ def test_manual_agent_run_endpoint_starts_background_job(monkeypatch) -> None:
def test_manual_agent_run_endpoint_uses_scheduler_when_available(monkeypatch) -> None:
# 生产环境手动搜索投递到常驻调度器,避免HTTP请求承载长时间联网搜索。
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
monkeypatch.setenv("SIGNALSCOUT_AGENT_ENABLED", "true")
get_settings.cache_clear()
engine = create_engine(
"sqlite:///:memory:",
@@ -121,6 +123,19 @@ def test_manual_agent_run_endpoint_uses_scheduler_when_available(monkeypatch) ->
assert scheduled[0]["run_date"].tzinfo is not None
def test_manual_agent_run_endpoint_rejects_requests_when_disabled(monkeypatch) -> None:
# 采集暂停时接口拒绝请求,避免其他调用方绕过页面入口消耗模型额度。
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
monkeypatch.setenv("SIGNALSCOUT_AGENT_ENABLED", "false")
get_settings.cache_clear()
with TestClient(create_app()) as client:
response = client.post("/agent/runs/daily")
get_settings.cache_clear()
assert response.status_code == 503
assert response.json()["detail"] == "情报采集当前已暂停"
def test_dashboard_returns_news_and_github_signals_separately(monkeypatch) -> None:
# 仪表盘接口直接返回分组后的业务数据,前端不再用标题或来源名自行猜测分类。
monkeypatch.setenv("SIGNALSCOUT_ENV", "test")
+9 -2
View File
@@ -3,10 +3,17 @@ from app.core.config import Settings
def test_scheduler_runs_on_interval() -> None:
# Agent默认按固定间隔自动运行,避免产品依赖用户手动触发。
scheduler = build_scheduler(Settings(agent_interval_minutes=30))
# 启用采集后按固定间隔自动运行,避免产品依赖用户手动触发。
scheduler = build_scheduler(Settings(agent_enabled=True, agent_interval_minutes=30))
job = scheduler.get_job("continuous-intelligence")
assert job is not None
assert job.trigger.interval.total_seconds() == 1800
assert job.max_instances == 1
def test_scheduler_skips_periodic_job_when_agent_is_disabled() -> None:
# 采集暂停时不注册任务,确保调度器没有可执行的外部模型调用。
scheduler = build_scheduler(Settings(agent_enabled=False))
assert scheduler.get_job("continuous-intelligence") is None