diff --git a/python/lib/sift_client/_tests/resources/test_runs_offline.py b/python/lib/sift_client/_tests/resources/test_runs_offline.py new file mode 100644 index 000000000..6aad5f103 --- /dev/null +++ b/python/lib/sift_client/_tests/resources/test_runs_offline.py @@ -0,0 +1,44 @@ +"""Offline tests for archive compatibility in the Runs API.""" + +from __future__ import annotations + +from unittest.mock import AsyncMock, MagicMock + +import pytest + +from sift_client.resources.runs import RunsAPIAsync +from sift_client.util import cel_utils as cel + + +def _api(mock_client) -> tuple[RunsAPIAsync, AsyncMock]: + api = RunsAPIAsync(mock_client) + api._low_level_client = MagicMock() + list_all_runs = AsyncMock(return_value=[]) + api._low_level_client.list_all_runs = list_all_runs + return api, list_all_runs + + +@pytest.mark.asyncio +async def test_list_include_archived_builds_both_state_filter(mock_client): + api, list_all_runs = _api(mock_client) + + await api.list_(include_archived=True) + + call = list_all_runs.await_args + assert call is not None + query_filter = call.kwargs["query_filter"] + assert query_filter == cel.parens( + cel.or_(cel.equals("is_archived", True), cel.equals("is_archived", False)) + ) + + +@pytest.mark.asyncio +async def test_list_excludes_archived_by_default(mock_client): + api, list_all_runs = _api(mock_client) + + await api.list_() + + call = list_all_runs.await_args + assert call is not None + query_filter = call.kwargs["query_filter"] + assert query_filter == cel.equals("is_archived", False) diff --git a/python/lib/sift_client/resources/runs.py b/python/lib/sift_client/resources/runs.py index efba8c6b3..1092def26 100644 --- a/python/lib/sift_client/resources/runs.py +++ b/python/lib/sift_client/resources/runs.py @@ -152,6 +152,12 @@ async def list_( filter_query=filter_query, ), ] + if include_archived: + filter_parts.append( + cel.parens( + cel.or_(cel.equals("is_archived", True), cel.equals("is_archived", False)) + ) + ) if run_ids: filter_parts.append(cel.in_("run_id", run_ids)) if client_keys: diff --git a/rust/crates/sift_mcp/src/tool/runs/mod.rs b/rust/crates/sift_mcp/src/tool/runs/mod.rs index 123f22342..fd0ca9f9e 100644 --- a/rust/crates/sift_mcp/src/tool/runs/mod.rs +++ b/rust/crates/sift_mcp/src/tool/runs/mod.rs @@ -35,7 +35,7 @@ impl SiftMcpServer { #[tool( name = "list_runs", description = " - List runs in Sift, optionally filtered by a CEL expression and ordered by one or more fields. + List runs in Sift, optionally filtered by a CEL expression and ordered by one or more fields. Default nonarchived. Output: - `{ \"runs\": [Run, ...] }`. Each item is the full Sift `Run` shape including `run_id`, `name`, @@ -53,7 +53,8 @@ impl SiftMcpServer { `has_more` is `true` — narrow `filter` or raise `limit` and ask again. Parameters: - - `filter`: CEL expression. Pass an empty string to list everything. Filterable fields: + - `filter`: CEL expression. An empty string uses the default. Use `is_archived == true` for archive-only + runs or `(is_archived == true || is_archived == false)` for both states. Filterable fields: `run_id`, `organization_id`, `asset_id`, `asset_name`, `client_key`, `name`, `description`, `start_time`, `stop_time`, `duration`, `duration_string`, `tag_id`, `asset_tag_id`, `annotation_comments_count`, `annotation_state`, `created_date`, `modified_date`, `archived_date`, @@ -90,8 +91,6 @@ impl SiftMcpServer { - To find runs covering a specific moment, filter on both `start_time` and `stop_time` rather than pulling everything and filtering client-side. - Order by `start_time desc` when surfacing the most recent runs to a user. - - Default add `is_archived == false` to the filter. Include archived runs only when the user - explicitly asks for them. ", annotations(title = "runs/list_runs", read_only_hint = true) )]