Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(agent): add repeat loop stop middleware tests

Steven Enamakela7d62a8312d5
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop_tests.rs
new file mode 100644
index 0000000000..913a06cc79
--- /dev/null
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeat_loop_stop_tests.rs
@@ -0,0 +1,54 @@
+use super::*;
+use crate::agent::session_host::stop_summary::StopReasonKind;
+
+#[test]
+fn only_an_identical_re_issue_counts_as_a_repeated_failure() {
+ let witness = RepeatLoopWitness::default();
+ assert!(!witness.record_failure("file_read", "a"));
+ assert!(!witness.record_failure("file_read", "b"));
+ assert!(!witness.record_failure("grep", "a"));
+ assert!(witness.record_failure("file_read", "a"));
+}
+
+#[test]
+fn a_success_clears_the_refusal_count() {
+ let witness = RepeatLoopWitness::default();
+ assert_eq!(witness.record_refusal(), 1);
+ assert_eq!(witness.record_refusal(), 2);
+ witness.record_success();
+ assert_eq!(witness.refusals(), 0);
+}
+
+#[test]
+fn security_and_side_effect_classes_keep_their_own_wording() {
+ for class in ["not_found", "missing_window", "validation", "invalid_arguments"] {
+ assert!(is_correctable_class(class), "{class}");
+ }
+ for class in [
+ "policy",
+ "blocked_by_policy",
+ "authentication",
+ "permission",
+ "uncertain_side_effect",
+ "transient",
+ "unavailable",
+ ] {
+ assert!(!is_correctable_class(class), "{class}");
+ }
+}
+
+#[test]
+fn the_repeat_loop_note_reads_as_a_repeating_step() {
+ let note = repeat_loop_halt_summary(
+ "file_read",
+ 2,
+ "Failed to resolve path 'src/lbi.rs': No such file or directory (os error 2)",
+ );
+ assert_eq!(
+ StopReasonKind::from_stop_note(&note),
+ StopReasonKind::RepeatingStep,
+ "{note}"
+ );
+ let stop = crate::agent::turn_stop::TurnStop::breaker(&note);
+ assert_eq!(stop.failure_class.as_deref(), Some("repeating_step"));
+}