Skip to content

test: add unit tests for repeatingDetector and clearCallArguments#180

Merged
asdek merged 2 commits intovxcontrol:feature/next_releasefrom
mason5052:test/repeating-detector-and-iteration-cap
Mar 11, 2026
Merged

test: add unit tests for repeatingDetector and clearCallArguments#180
asdek merged 2 commits intovxcontrol:feature/next_releasefrom
mason5052:test/repeating-detector-and-iteration-cap

Conversation

@mason5052
Copy link
Contributor

@mason5052 mason5052 commented Mar 6, 2026

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

Copilot AI review requested due to automatic review settings March 6, 2026 02:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unit test coverage for the repeating tool-call detection and argument-normalization logic in backend/pkg/providers/helpers.go, which is used as safety logic to identify repeated tool calls.

Changes:

  • Add table-driven tests for repeatingDetector.detect covering threshold behavior, reset behavior, and argument normalization effects.
  • Add tests for repeatingDetector.clearCallArguments covering message stripping, key ordering, and invalid JSON passthrough.
  • Introduce a small test helper (makeToolCall) to build llms.ToolCall inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Add comprehensive test coverage for the repeating tool call detection
logic that guards against infinite agent chain loops (related to vxcontrol#175).

TestRepeatingDetector (9 cases):
- nil function call, first/second/third identical calls
- threshold triggering at RepeatingToolCallThreshold (3)
- funcCalls reset on different call
- escalation threshold validation (6 vs 7 consecutive calls)
- argument normalization (message field stripping, key ordering)

TestRepeatingDetectorEscalationThreshold:
- Validates escalation math: abort at len >= threshold + 4 = 7

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

Signed-off-by: mason5052 <ehehwnwjs5052@gmail.com>
- Replace hardcoded +4 with testMaxSoftDetectionsBeforeAbort constant
  with sync comment pointing to performer.go
- Add test case for same function name with different non-message args
  resetting funcCalls (covers the other reset condition in detect())

Signed-off-by: mason5052 <ehehwnwjs5052@gmail.com>
@mason5052 mason5052 force-pushed the test/repeating-detector-and-iteration-cap branch from 5fd3504 to 0ffe6a4 Compare March 10, 2026 15:35
@asdek asdek changed the base branch from master to feature/next_release March 11, 2026 13:37
@asdek asdek merged commit 2e2dbab into vxcontrol:feature/next_release Mar 11, 2026
@asdek
Copy link
Contributor

asdek commented Mar 11, 2026

tnx for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants