Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/fastcontext/agent/tool/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def run(directory: str, pattern: str, cwd: str) -> str:
command = [RG_PATH, "--files", directory, "--glob", pattern]
command = [RG_PATH, "--files", directory, "--glob", pattern, "--sort", "modified"]
timeout = 10 # seconds
try:
output = subprocess.run(
Expand Down
25 changes: 25 additions & 0 deletions tests/test_glob_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import asyncio
import json
import os
import tempfile
from pathlib import Path

from fastcontext.agent.tool.glob import GlobTool


def test_glob_sorts_by_modification_time():
"""glob.md promises results sorted by modification time. Create files out
of mtime order on disk and assert the output is ordered oldest -> newest
(rg --sort modified)."""
glob = GlobTool()
with tempfile.TemporaryDirectory() as cwd:
# Create in a deliberately non-mtime order, then stamp mtimes.
for name, mtime in [("new.txt", 3000), ("old.txt", 1000), ("mid.txt", 2000)]:
p = Path(cwd) / name
p.write_text("x", encoding="utf-8")
os.utime(p, (mtime, mtime))

out = asyncio.run(glob.call(json.dumps({"directory": cwd, "pattern": "*.txt"}), cwd=cwd))
names = [Path(line).name for line in out.splitlines()]

assert names == ["old.txt", "mid.txt", "new.txt"], f"expected mtime order, got {names}"