Merge remote-tracking branch 'origin/master' into xuhd
# Conflicts: # offline-backend-20260512/backend/config.yaml
This commit is contained in:
commit
bd0eceda61
267 files changed
+41209
-14541
No files matched your search
@@ -3,9 +3,14 @@ from __future__ import annotations
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from app.gateway.routers.agents import _load_config_extras, _write_agent_config
|
||||
from app.gateway.routers.agents import (
|
||||
_backfill_listing_cache,
|
||||
_load_config_extras,
|
||||
_write_agent_config,
|
||||
)
|
||||
from app.gateway.services import build_run_config
|
||||
from deerflow.config import paths as paths_module
|
||||
from deerflow.config.agents_config import AgentConfig
|
||||
from deerflow.persistence.agents import MemoryAgentStore
|
||||
|
||||
|
||||
@@ -198,3 +203,46 @@ def test_write_agent_config_omits_skills_when_none(isolated_paths) -> None:
|
||||
assert "skills" not in raw
|
||||
assert "model" not in raw
|
||||
assert "tool_groups" not in raw
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_backfill_listing_cache_mirrors_config_values() -> None:
|
||||
store = MemoryAgentStore()
|
||||
cfg = AgentConfig(id="a1", name="Agent", skills=["s1", "s2"], tool_groups=["g1"], model="m1")
|
||||
await _backfill_listing_cache(store, [("a1", cfg)])
|
||||
|
||||
extras = await store.get_extras_for(["a1"])
|
||||
assert extras["a1"]["skills"] == ["s1", "s2"]
|
||||
assert extras["a1"]["tool_groups"] == ["g1"]
|
||||
assert extras["a1"]["model"] == "m1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_backfill_listing_cache_is_idempotent_and_skips_unchanged(monkeypatch) -> None:
|
||||
store = MemoryAgentStore()
|
||||
cfg = AgentConfig(id="a1", name="Agent", skills=["s1"], tool_groups=None, model=None)
|
||||
await _backfill_listing_cache(store, [("a1", cfg)])
|
||||
|
||||
# On a second run with identical config, no re-write should occur.
|
||||
calls = {"replace": 0, "set": 0}
|
||||
orig_replace = store.replace_skills
|
||||
orig_set = store.set_extras
|
||||
|
||||
async def _replace(agent_id, skills):
|
||||
calls["replace"] += 1
|
||||
await orig_replace(agent_id, skills)
|
||||
|
||||
async def _set(agent_id, *, tool_groups, model):
|
||||
calls["set"] += 1
|
||||
await orig_set(agent_id, tool_groups=tool_groups, model=model)
|
||||
|
||||
monkeypatch.setattr(store, "replace_skills", _replace)
|
||||
monkeypatch.setattr(store, "set_extras", _set)
|
||||
|
||||
await _backfill_listing_cache(store, [("a1", cfg)])
|
||||
assert calls == {"replace": 0, "set": 0}
|
||||
|
||||
# Changing the config triggers a re-write.
|
||||
cfg2 = AgentConfig(id="a1", name="Agent", skills=["s1", "s2"], tool_groups=None, model=None)
|
||||
await _backfill_listing_cache(store, [("a1", cfg2)])
|
||||
assert calls["replace"] == 1
|
||||
@@ -217,6 +217,29 @@ async def test_sql_store_filters_errors_only(sql_store):
|
||||
assert only_errors[0]["error_type"] == "APITimeoutError"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sql_store_filters_by_user_ids(sql_store):
|
||||
"""``user_ids`` (set by a fuzzy username search) matches several accounts."""
|
||||
base = datetime.now(UTC)
|
||||
for uid in ("alice", "alicia", "bob"):
|
||||
await sql_store.record(
|
||||
LlmMetricRecord(
|
||||
id=uuid.uuid4().hex,
|
||||
created_at=base,
|
||||
user_id=uid,
|
||||
duration_ms=1,
|
||||
status="success",
|
||||
)
|
||||
)
|
||||
# Fuzzy "ali" → {alice, alicia}; bob must be excluded.
|
||||
rows = await sql_store.list(LlmMetricsQuery(user_ids=["alice", "alicia"], limit=10))
|
||||
assert {r["user_id"] for r in rows} == {"alice", "alicia"}
|
||||
assert await sql_store.count(LlmMetricsQuery(user_ids=["alice", "alicia"])) == 2
|
||||
# user_ids takes precedence over a single user_id.
|
||||
rows = await sql_store.list(LlmMetricsQuery(user_id="bob", user_ids=["alice"], limit=10))
|
||||
assert {r["user_id"] for r in rows} == {"alice"}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sql_store_iter_all_paginates(sql_store):
|
||||
base = datetime.now(UTC)
|
||||
|
||||
Reference in new issue
Block a user