[PR #180] [MERGED] test: add unit tests for repeatingDetector and clearCallArguments #217

Closed
opened 2026-06-06 22:09:44 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/180
Author: @mason5052
Created: 3/5/2026
Status: Merged
Merged: 3/11/2026
Merged by: @asdek

Base: feature/next_releaseHead: test/repeating-detector-and-iteration-cap


📝 Commits (2)

  • fc90e9d test: add unit tests for repeatingDetector and clearCallArguments
  • 0ffe6a4 fix: add named test constant and same-name-different-args edge case

📊 Changes

1 file changed (+210 additions, -0 deletions)

View changed files

📝 backend/pkg/providers/helpers_test.go (+210 -0)

📄 Description

Dependency: Merge #178 first -- this PR tests the iteration cap and repeating escalation logic introduced in #178.

Description of the Change

Problem

The repeatingDetector and clearCallArguments functions in helpers.go had no unit test coverage despite being critical safety logic for preventing infinite agent chain loops (#175, #178).

Solution

Add 12 test cases covering the full behavior of repeating tool call detection:

  • TestRepeatingDetector (9 cases): nil function call handling, threshold triggering at RepeatingToolCallThreshold=3, funcCalls accumulation and reset on different calls, escalation threshold validation (6 vs 7 consecutive calls), argument normalization (message field stripping, JSON key ordering)

  • TestRepeatingDetectorEscalationThreshold: Validates the escalation math used in performer.go -- abort triggers when len(funcCalls) >= RepeatingToolCallThreshold + 4 = 7, confirming 4 soft warnings before abort on the 7th consecutive identical call

  • TestClearCallArguments (3 cases): message field stripping, alphabetical key sorting, invalid JSON passthrough

All tests follow the existing table-driven pattern in helpers_test.go using testify/assert.

Related to #175
Adds test coverage for #178

Type of Change

  • Tests (adding or updating tests)

Areas Affected

  • Core Services (Backend API)

Testing and Verification

Test Configuration

  • PentAGI Version: master
  • Go Version: 1.24

Test Steps

  1. go test ./pkg/providers/ -run "TestRepeatingDetector|TestClearCallArguments" -v -- all 12 tests pass
  2. go test ./pkg/providers/ -v -- all existing tests continue to pass (no regressions)
  3. go vet ./pkg/providers/ -- no warnings

Security Considerations

No security impact. Test-only change.

Checklist

  • My code follows the project's coding standards
  • All new and existing tests pass
  • I have run go fmt and go vet
  • Security implications considered
  • Changes are backward compatible

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/vxcontrol/pentagi/pull/180 **Author:** [@mason5052](https://github.com/mason5052) **Created:** 3/5/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@asdek](https://github.com/asdek) **Base:** `feature/next_release` ← **Head:** `test/repeating-detector-and-iteration-cap` --- ### 📝 Commits (2) - [`fc90e9d`](https://github.com/vxcontrol/pentagi/commit/fc90e9d2081c81e2f3227d2a59806f90cf003be0) test: add unit tests for repeatingDetector and clearCallArguments - [`0ffe6a4`](https://github.com/vxcontrol/pentagi/commit/0ffe6a4639c5d7cadc2a6e7af3071a1036be5f99) fix: add named test constant and same-name-different-args edge case ### 📊 Changes **1 file changed** (+210 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `backend/pkg/providers/helpers_test.go` (+210 -0) </details> ### 📄 Description > **Dependency:** Merge #178 first -- this PR tests the iteration cap and repeating escalation logic introduced in #178. ### Description of the Change #### Problem The `repeatingDetector` and `clearCallArguments` functions in `helpers.go` had no unit test coverage despite being critical safety logic for preventing infinite agent chain loops (#175, #178). #### Solution Add 12 test cases covering the full behavior of repeating tool call detection: - **TestRepeatingDetector** (9 cases): nil function call handling, threshold triggering at `RepeatingToolCallThreshold=3`, funcCalls accumulation and reset on different calls, escalation threshold validation (6 vs 7 consecutive calls), argument normalization (message field stripping, JSON key ordering) - **TestRepeatingDetectorEscalationThreshold**: Validates the escalation math used in `performer.go` -- abort triggers when `len(funcCalls) >= RepeatingToolCallThreshold + 4 = 7`, confirming 4 soft warnings before abort on the 7th consecutive identical call - **TestClearCallArguments** (3 cases): message field stripping, alphabetical key sorting, invalid JSON passthrough All tests follow the existing table-driven pattern in `helpers_test.go` using `testify/assert`. Related to #175 Adds test coverage for #178 ### Type of Change - [x] Tests (adding or updating tests) ### Areas Affected - [x] Core Services (Backend API) ### Testing and Verification #### Test Configuration - PentAGI Version: master - Go Version: 1.24 #### Test Steps 1. `go test ./pkg/providers/ -run "TestRepeatingDetector|TestClearCallArguments" -v` -- all 12 tests pass 2. `go test ./pkg/providers/ -v` -- all existing tests continue to pass (no regressions) 3. `go vet ./pkg/providers/` -- no warnings ### Security Considerations No security impact. Test-only change. ### Checklist - [x] My code follows the project's coding standards - [x] All new and existing tests pass - [x] I have run `go fmt` and `go vet` - [x] Security implications considered - [x] Changes are backward compatible --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-06 22:09:44 -04:00
yindo closed this issue 2026-06-06 22:09:44 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#217