Skip to content

Commit f79f533

Browse files
committed
feat(tests): add unit tests for validate_submit function in subagent_runner
- Introduced multiple test cases to validate the behavior of the validate_submit function, covering scenarios for blocked submissions with and without workspace attempts, as well as completed submissions. - Ensured that the function correctly handles cases where roles lack workspace read permissions.
1 parent f50ec83 commit f79f533

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src-tauri/src/agent/subagent_runner.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,52 @@ async fn stream_openai_subagent_round(
10081008
.collect();
10091009
Ok(acc)
10101010
}
1011+
1012+
#[cfg(test)]
1013+
mod tests {
1014+
use super::*;
1015+
use std::collections::HashSet;
1016+
1017+
#[test]
1018+
fn validate_submit_rejects_blocked_without_workspace_attempt() {
1019+
let args = json!({ "status": "blocked", "summary": "no tools" });
1020+
let called: HashSet<String> = HashSet::new();
1021+
assert!(matches!(
1022+
validate_submit(&args, &called, true),
1023+
SubmitVerdict::RejectBlockedWithoutTrying { .. }
1024+
));
1025+
}
1026+
1027+
#[test]
1028+
fn validate_submit_accepts_blocked_after_workspace_attempt() {
1029+
let args = json!({ "status": "blocked", "summary": "denied" });
1030+
let mut called: HashSet<String> = HashSet::new();
1031+
called.insert("list_workspace_files".into());
1032+
assert_eq!(
1033+
validate_submit(&args, &called, true),
1034+
SubmitVerdict::Accept
1035+
);
1036+
}
1037+
1038+
#[test]
1039+
fn validate_submit_accepts_completed_regardless() {
1040+
let args = json!({ "status": "completed", "summary": "done" });
1041+
let called: HashSet<String> = HashSet::new();
1042+
assert_eq!(
1043+
validate_submit(&args, &called, true),
1044+
SubmitVerdict::Accept
1045+
);
1046+
}
1047+
1048+
#[test]
1049+
fn validate_submit_accepts_when_role_has_no_workspace_read() {
1050+
// If the role was never given workspace_read, a "blocked" claim
1051+
// about missing tools is honest — accept it.
1052+
let args = json!({ "status": "blocked", "summary": "no workspace tools" });
1053+
let called: HashSet<String> = HashSet::new();
1054+
assert_eq!(
1055+
validate_submit(&args, &called, false),
1056+
SubmitVerdict::Accept
1057+
);
1058+
}
1059+
}

0 commit comments

Comments
 (0)