Skip to content

Commit 277a2c4

Browse files
committed
fix(tape): align tape.search match count with output
1 parent f72bf9c commit 277a2c4

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/bub/builtin/tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async def tape_search(param: SearchInput, *, context: ToolContext) -> str:
206206
if "[tape.search]" in entry_str:
207207
continue
208208
lines.append(entry_str)
209-
return f"[tape.search]: {len(entries)} matches" + "".join(f"\n{line}" for line in lines)
209+
return f"[tape.search]: {len(lines)} matches ({len(entries) - len(lines)} filtered)" + "".join(f"\n{line}" for line in lines)
210210

211211

212212
@tool(context=True, name="tape.reset")

tests/test_tape_search_output.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass
4+
5+
import pytest
6+
from republic import ToolContext
7+
8+
import bub.builtin.tools as builtin_tools
9+
from bub.builtin.tools import tape_search
10+
11+
12+
@dataclass(frozen=True)
13+
class _FakeEntry:
14+
date: str
15+
payload: object
16+
17+
18+
class _FakeTapes:
19+
def __init__(self, entries: list[_FakeEntry]) -> None:
20+
self._entries = entries
21+
self._store = object()
22+
23+
async def search(self, _query: object) -> list[_FakeEntry]:
24+
return list(self._entries)
25+
26+
27+
class _FakeAgent:
28+
def __init__(self, entries: list[_FakeEntry]) -> None:
29+
self.tapes = _FakeTapes(entries)
30+
31+
32+
@pytest.mark.asyncio
33+
async def test_tape_search_reports_shown_matches_and_filtered_count(monkeypatch) -> None:
34+
entries = [
35+
_FakeEntry(date="2026-01-01T00:00:00Z", payload={"content": "ok"}),
36+
_FakeEntry(date="2026-01-01T00:00:01Z", payload={"content": "[tape.search]: 1 matches"}),
37+
]
38+
monkeypatch.setattr(builtin_tools, "_get_agent", lambda _context: _FakeAgent(entries))
39+
40+
output = await tape_search.run(query="x", context=ToolContext(tape="tape", run_id="run", state={}))
41+
42+
assert output.splitlines()[0] == "[tape.search]: 1 matches (1 filtered)"
43+
44+
45+
@pytest.mark.asyncio
46+
async def test_tape_search_reports_zero_filtered_explicitly(monkeypatch) -> None:
47+
entries = [
48+
_FakeEntry(date="2026-01-01T00:00:00Z", payload={"content": "a"}),
49+
_FakeEntry(date="2026-01-01T00:00:01Z", payload={"content": "b"}),
50+
]
51+
monkeypatch.setattr(builtin_tools, "_get_agent", lambda _context: _FakeAgent(entries))
52+
53+
output = await tape_search.run(query="x", context=ToolContext(tape="tape", run_id="run", state={}))
54+
55+
assert output.splitlines()[0] == "[tape.search]: 2 matches (0 filtered)"

0 commit comments

Comments
 (0)