()
| 1316 | |
| 1317 | #[tokio::test] |
| 1318 | async fn test_eval_perm() { |
| 1319 | const DENIED_PATH_ONE: &str = "/some/denied/path"; |
| 1320 | const DENIED_PATH_GLOB: &str = "/denied/glob/**/path"; |
| 1321 | const ALLOW_PATH_ONE: &str = "/some/allow/path"; |
| 1322 | const ALLOW_PATH_GLOB: &str = "/allowed/glob/**/path"; |
| 1323 | |
| 1324 | let mut agent = Agent { |
| 1325 | name: "test_agent".to_string(), |
| 1326 | tools_settings: { |
| 1327 | let mut map = HashMap::<ToolSettingTarget, serde_json::Value>::new(); |
| 1328 | map.insert( |
| 1329 | ToolSettingTarget("fs_write".to_string()), |
| 1330 | serde_json::json!({ |
| 1331 | "allowedPaths": [ALLOW_PATH_ONE, ALLOW_PATH_GLOB], |
| 1332 | "deniedPaths": [DENIED_PATH_ONE, DENIED_PATH_GLOB] |
| 1333 | }), |
| 1334 | ); |
| 1335 | map |
| 1336 | }, |
| 1337 | ..Default::default() |
| 1338 | }; |
| 1339 | |
| 1340 | let os = Os::new().await.unwrap(); |
| 1341 | |
| 1342 | // Test path not matching any patterns - should ask |
| 1343 | let tool_should_ask = serde_json::from_value::<FsWrite>(serde_json::json!({ |
| 1344 | "path": "/not/a/denied/path/file.txt", |
| 1345 | "command": "create", |
| 1346 | "file_text": "content in nested path" |
| 1347 | })) |
| 1348 | .unwrap(); |
| 1349 | |
| 1350 | let res = tool_should_ask.eval_perm(&os, &agent); |
| 1351 | assert!(matches!(res, PermissionEvalResult::Ask)); |
| 1352 | |
| 1353 | // Test path matching denied pattern - should deny |
| 1354 | let tool_should_deny = serde_json::from_value::<FsWrite>(serde_json::json!({ |
| 1355 | "path": "/some/denied/path/file.txt", |
| 1356 | "command": "create", |
| 1357 | "file_text": "content in nested path" |
| 1358 | })) |
| 1359 | .unwrap(); |
| 1360 | |
| 1361 | let res = tool_should_deny.eval_perm(&os, &agent); |
| 1362 | assert!( |
| 1363 | matches!(res, PermissionEvalResult::Deny(ref deny_list) if deny_list.contains(&DENIED_PATH_ONE.to_string())) |
| 1364 | ); |
| 1365 | |
| 1366 | let tool_should_deny = serde_json::from_value::<FsWrite>(serde_json::json!({ |
| 1367 | "path": "/some/denied/path/subdir/", |
| 1368 | "command": "create", |
| 1369 | "file_text": "content in nested path" |
| 1370 | })) |
| 1371 | .unwrap(); |
| 1372 | |
| 1373 | let res = tool_should_deny.eval_perm(&os, &agent); |
| 1374 | assert!(matches!(res, PermissionEvalResult::Deny(ref deny_list) if |
| 1375 | deny_list.contains(&DENIED_PATH_ONE.to_string()))); |
nothing calls this directly
no test coverage detected