测试: bypass 标志测试统一串行闸

途经 is_authorized 的测试统一持锁,消除并行偶发红
This commit is contained in:
lxy
2026-10-01 08:28:07 +08:00
parent 04ce127a96
commit 57d9fd8ad3
3 changed files with 31 additions and 6 deletions
+4
View File
@@ -893,6 +893,8 @@ mod tests {
/// 锁定此差异:grep 与 read_file 同款授权弹窗语义。
#[test]
fn test_grep_unauthorized_path_triggers_auth_not_denied() {
// 途经 is_authorized 读进程级 bypass 标志,持串行闸防与写标志的测试并行互踩
let _guard = BLACKLIST_BYPASS_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
// 空白名单(不含 workspace_root 的目录):任何路径都未授权 → NeedsAuth
let allowed = crate::state::AllowedDirs::default();
let args = serde_json::json!({ "pattern": "foo", "path": "C:/some/unauthorized/dir" });
@@ -916,6 +918,8 @@ mod tests {
/// grep 黑名单路径(.ssh 等)直接 Denied(不申请授权),对齐 read_file。
#[test]
fn test_grep_blacklisted_path_denied() {
// 途经 is_authorized 读进程级 bypass 标志,持串行闸防与写标志的测试并行互踩
let _guard = BLACKLIST_BYPASS_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let allowed = crate::state::AllowedDirs::default_with_root();
// .ssh 命中系统黑名单(is_in_system_blacklist)
let args = serde_json::json!({ "pattern": "foo", "path": "/home/user/.ssh/config" });
@@ -181,6 +181,8 @@ mod tests {
/// bypass 关:黑名单行为不变(Denied 基线,与改造前一致)。
#[test]
fn test_bypass_off_blacklist_still_denied() {
// 途经 is_authorized 读进程级 bypass 标志,持串行闸防与写标志的测试并行互踩
let _guard = BLACKLIST_BYPASS_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let allowed = crate::state::AllowedDirs::default_with_root();
let args = serde_json::json!({ "path": "/home/user/.ssh/config" });
match check_file_tool_auth("read_file", &args, &allowed, false) {