Feature: Filter search_file results by size, mtime and slim fields

Add four optional arguments to search_file that narrow the match list
after the client has returned it: min_size and max_size in bytes,
modified_after in either YYYY-MM-DD or YYYY-MM-DD HH:MM:SS form, and
name_only to keep just path and name per entry. The client still runs
the same name-matched recursive search, so these filters cut the
response size and the reasoning work on our side, not the scan time on
the host -- the summary sentence says so and totalAll keeps the
pre-filter count so a too-narrow condition is obvious. Invalid values
(negative sizes, an inverted range, a malformed timestamp) are rejected
with -32602 before any packet goes out.

The timestamp validator only accepted the ten-character form because
its shape loop never allowed the two colons, which rejected every
nineteen-character value; the loop now whitelists them.

Smoke tests cover the unchanged totalAll under a size filter, the slim
name_only payload and a rejected timestamp, for 33 checks when the
search path is supplied. Design notes are in section 11.4.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-10-25 14:41:52 +01:00
1 parent 929065e7be
commit 7c5bf3e73d
3 files changed
+127 -1

No files matched your search

+17
View File
@@ -200,6 +200,23 @@ if (-not $SkipHost) {
} else {
Check 'search_file 带 finished/truncated 字段' (($null -ne $ss.finished) -and ($null -ne $ss.truncated))
Check 'search_file 命中项字段完整' (@($ss.files | Where-Object { -not $_.path -or $null -eq $_.size }).Count -eq 0)
# C4:结果侧过滤(大小 / 修改时间 / 精简字段),全部在服务端做
$base0 = [int]$ss.totalAll
$big = Rpc '' $null 'search_file' @{ id = $HostId; path = $SearchPath; pattern = '*.exe';
limit = 3; timeout_ms = 5000; min_size = 1073741824 }
$bs = $big.result.structuredContent
Check 'search_file min_size 过滤后 totalAll 不变' `
($big.error -eq $null -and [int]$bs.totalAll -eq $base0 -and [int]$bs.total -le $base0)
$slim = Rpc '' $null 'search_file' @{ id = $HostId; path = $SearchPath; pattern = '*.exe';
limit = 3; timeout_ms = 5000; name_only = $true }
$sl = @($slim.result.structuredContent.files)
Check 'search_file name_only 只返回 path/name' `
($slim.error -eq $null -and @($sl | Where-Object { $_.size -or $_.modified -or $_.dir }).Count -eq 0)
$bad = Rpc '' $null 'search_file' @{ id = $HostId; path = $SearchPath; pattern = '*.exe';
modified_after = '2026/01/01' }
Check 'search_file 非法 modified_after 返回 -32602' `
($bad.error -and [int]$bad.error.code -eq -32602)
}
} else {
Write-Host " 未指定 -SearchPath,跳过 search_file 测试(深目录会触发客户端已知的 MAX_PATH 栈溢出)。" -ForegroundColor Yellow