fix(agent): fall back when rg is blocked for @folder references

This commit is contained in:
Ruzzgar 2026-04-17 23:43:01 +03:00 committed by Teknium
parent 8a6aa5882e
commit 60236862ee
2 changed files with 27 additions and 3 deletions

View file

@ -483,9 +483,7 @@ def _rg_files(path: Path, cwd: Path, limit: int) -> list[Path] | None:
text=True, text=True,
timeout=10, timeout=10,
) )
except FileNotFoundError: except (FileNotFoundError, OSError, subprocess.TimeoutExpired):
return None
except subprocess.TimeoutExpired:
return None return None
if result.returncode != 0: if result.returncode != 0:
return None return None

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import asyncio import asyncio
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from unittest.mock import patch
import pytest import pytest
@ -124,6 +125,31 @@ def test_expand_file_range_and_folder_listing(sample_repo: Path):
assert not result.warnings assert not result.warnings
def test_folder_listing_falls_back_when_rg_is_blocked(sample_repo: Path):
from agent.context_references import preprocess_context_references
real_run = subprocess.run
def blocked_rg(*args, **kwargs):
cmd = args[0] if args else kwargs.get("args")
if isinstance(cmd, list) and cmd and cmd[0] == "rg":
raise PermissionError("rg blocked by policy")
return real_run(*args, **kwargs)
with patch("agent.context_references.subprocess.run", side_effect=blocked_rg):
result = preprocess_context_references(
"Review @folder:src/",
cwd=sample_repo,
context_length=100_000,
)
assert result.expanded
assert "src/" in result.message
assert "main.py" in result.message
assert "helper.py" in result.message
assert not result.warnings
def test_expand_quoted_file_reference_with_spaces(tmp_path: Path): def test_expand_quoted_file_reference_with_spaces(tmp_path: Path):
from agent.context_references import preprocess_context_references from agent.context_references import preprocess_context_references