fix(sandbox): honor data directories in explicit search globs (#8408)

This commit is contained in:
ZephyrWang 2026-11-21 15:37:07 +08:00 committed by GitHub
parent 40ef4f6ac1
commit 2abcfa4250
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 2 deletions

View File

@ -118,8 +118,7 @@ def should_ignore_name(name: str) -> bool:
def _names_user_data(pattern: str) -> bool:
name = pattern.rsplit("/", 1)[-1]
return any(fnmatch.fnmatchcase(name, candidate) for candidate in USER_DATA_PATTERNS)
return any(fnmatch.fnmatchcase(part, candidate) for part in pattern.split("/") for candidate in USER_DATA_PATTERNS)
def ignore_rules_for(search_root: Path, *, glob: str | None = None, user_data: bool = False) -> IgnoreRules:

View File

@ -12,6 +12,8 @@ from __future__ import annotations
from pathlib import Path
from types import SimpleNamespace
import pytest
from deerflow.sandbox.local.list_dir import list_dir
from deerflow.sandbox.local.local_sandbox import LocalSandbox, PathMapping
from deerflow.sandbox.search import (
@ -79,6 +81,33 @@ def test_an_explicit_glob_wins_inside_a_checkout(tmp_path: Path) -> None:
assert [Path(match.path).name for match in matches] == ["app.log"]
@pytest.mark.parametrize("directory", ["logs", ".cache", "reports.log"])
@pytest.mark.parametrize("recursive", [False, True])
def test_explicit_data_directory_globs_reach_local_sandbox_files(tmp_path: Path, directory: str, recursive: bool) -> None:
checkout = tmp_path / "checkout"
target = checkout / directory / "report.txt"
target.parent.mkdir(parents=True)
target.write_bytes(b"FATAL diagnostic\n")
for hidden in (".git", "node_modules"):
noise = checkout / hidden / directory / "noise.txt"
noise.parent.mkdir(parents=True)
noise.write_bytes(b"FATAL repository noise\n")
(target.parent / ".upload-pending.part").write_bytes(b"FATAL incomplete\n")
sandbox = LocalSandbox("local", [PathMapping("/mnt/skills/public", str(checkout))])
root = "/mnt/skills/public"
pattern = f"{'**/' if recursive else ''}{directory}/*"
files, truncated = sandbox.glob(root, pattern)
assert files == [f"{root}/{directory}/report.txt"]
assert not truncated
matches, truncated = sandbox.grep(root, "FATAL", glob=pattern)
assert [(match.path, match.line) for match in matches] == [(f"{root}/{directory}/report.txt", "FATAL diagnostic")]
assert not truncated
# An unfiltered search still treats these directories as repository noise.
assert sandbox.glob(root, "**/*")[0] == []
assert sandbox.grep(root, "FATAL")[0] == []
def test_a_file_named_as_the_root_is_read_above_the_size_bound(tmp_path: Path) -> None:
uploads = tmp_path / "uploads"
uploads.mkdir()

View File

@ -26,6 +26,12 @@ filtering and read-only mounts still apply. Configured category mounts such as
category mount stops the root search, and the Gateway warning log identifies its
virtual path.
Explicit `glob` patterns and `grep` file filters can name data directories such
as `logs/*.txt`, `**/logs/*.txt` or `.cache/*.txt`, even outside the user-data
mounts. Generic searches keep ignoring those directories outside user data.
Repository metadata, dependency directories and in-flight `.upload-*.part`
files remain filtered.
Sandbox references in conversation state are server-owned. External run and
thread-state APIs reject caller-supplied `sandbox` values; when restoring a
checkpoint, the runtime resolves the reference against the authenticated user