Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions python/lib/sift_client/_tests/resources/test_runs_offline.py
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions python/lib/sift_client/resources/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions rust/crates/sift_mcp/src/tool/runs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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`,
Expand Down Expand Up @@ -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)
)]
Expand Down
Loading