Skip to content

Commit a5b5acc

Browse files
committed
fix: log idle-reminder task-count failures; test grep fallback via public API
Address two CodeRabbit review findings on PR #13: - ui/shell: replace contextlib.suppress(Exception) around the idle-reminder active-task count with a try/except that logs at debug (active_running still falls back to 0), so background-task introspection failures are no longer invisible. - tests/tools/test_grep: exercise the Python fallback's wall-clock bound through the public Grep() API with a forced ripgrep-unavailable path instead of calling _python_grep directly, and drop the now-unused import.
1 parent 2f7afee commit a5b5acc

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/pythinker_code/ui/shell/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,12 +795,18 @@ def _can_auto_trigger_pending() -> bool:
795795
resume_prompt.set()
796796
active_running = 0
797797
if isinstance(self.soul, PythinkerSoul):
798-
with contextlib.suppress(Exception):
798+
try:
799799
active_running = len(
800800
list_task_views(
801801
self.soul.runtime.background_tasks, active_only=True
802802
)
803803
)
804+
except Exception:
805+
logger.debug(
806+
"Failed to compute active background task count for "
807+
"idle reminder",
808+
exc_info=True,
809+
)
804810
ok = await self.run_soul_command(_background_idle_reminder(active_running))
805811
console.print()
806812
if not ok:

tests/tools/test_grep.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Params,
1616
_build_rg_args,
1717
_find_existing_rg,
18-
_python_grep,
1918
_rg_binary_name,
2019
_strip_path_prefix,
2120
)
@@ -1041,24 +1040,33 @@ async def test_grep_allows_env_example(grep_tool: Grep):
10411040
assert ".env.example" in result.output
10421041

10431042

1044-
def test_python_fallback_bounds_wall_clock(monkeypatch, tmp_path):
1043+
async def test_python_fallback_bounds_wall_clock(monkeypatch, tmp_path):
10451044
"""The Python fallback caps total wall-clock like the ripgrep path, and
10461045
surfaces a partial-results notice when it does."""
1046+
1047+
async def fail_rg_path() -> str:
1048+
raise RuntimeError("Failed to download ripgrep binary")
1049+
1050+
monkeypatch.setattr("pythinker_code.tools.file.grep_local._ensure_rg_path", fail_rg_path)
1051+
10471052
(tmp_path / "a.txt").write_text("needle\n")
10481053
(tmp_path / "b.txt").write_text("needle\n")
10491054

1050-
# First monotonic() reading establishes the deadline; every later reading is
1051-
# far in the future, so the deadline is already blown on the first file.
1052-
readings = iter([0.0])
1055+
# A strictly increasing clock: the first reading inside the fallback sets the
1056+
# deadline, and the next reading (during the file walk) is far enough ahead to
1057+
# blow it immediately. The +1e9 step keeps that true regardless of any other
1058+
# monotonic() calls made elsewhere on the public Grep() path.
1059+
ticks = [0.0]
10531060

10541061
def _fake_monotonic() -> float:
1055-
return next(readings, 1e9)
1062+
value = ticks[0]
1063+
ticks[0] += 1e9
1064+
return value
10561065

10571066
monkeypatch.setattr(grep_module.time, "monotonic", _fake_monotonic)
10581067

1059-
result = _python_grep(
1060-
Params(pattern="needle", path=str(tmp_path), output_mode="files_with_matches"),
1061-
"forced fallback",
1068+
result = await Grep()(
1069+
Params(pattern="needle", path=str(tmp_path), output_mode="files_with_matches")
10621070
)
10631071

10641072
assert f"Search exceeded {grep_module.RG_TIMEOUT}s" in result.message

0 commit comments

Comments
 (0)