44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.dialects import mysql
|
|
|
|
from app.gateway.routers.admin_users import _apply_run_scope, _apply_tool_scope
|
|
from deerflow.persistence.run.model import RunRow
|
|
from deerflow.persistence.tool_metrics.model import ToolCallMetricRow
|
|
|
|
|
|
def _mysql_sql(stmt) -> str:
|
|
return str(stmt.compile(dialect=mysql.dialect(), compile_kwargs={"literal_binds": True})).upper()
|
|
|
|
|
|
def test_excluding_scheduled_runs_uses_index_friendly_not_exists() -> None:
|
|
stmt = _apply_run_scope(
|
|
select(RunRow.run_id),
|
|
user_column=RunRow.user_id,
|
|
run_id_column=RunRow.run_id,
|
|
exclude_user_ids=set(),
|
|
include_admins=True,
|
|
include_failed=True,
|
|
include_scheduled=False,
|
|
)
|
|
sql = _mysql_sql(stmt)
|
|
|
|
assert "NOT (EXISTS" in sql
|
|
assert "SCHEDULED_TASK_RUNS" in sql
|
|
assert " NOT IN " not in sql
|
|
|
|
|
|
def test_tool_aggregation_does_not_join_the_full_runs_table() -> None:
|
|
stmt = _apply_tool_scope(
|
|
select(ToolCallMetricRow.tool_name),
|
|
exclude_user_ids=set(),
|
|
include_admins=True,
|
|
include_scheduled=False,
|
|
)
|
|
sql = _mysql_sql(stmt)
|
|
|
|
assert sql.count("NOT (EXISTS") == 2
|
|
assert "LEFT OUTER JOIN" not in sql
|
|
assert " NOT IN " not in sql
|