test: add unit tests for repeatingDetector and clearCallArguments#180
Merged
asdek merged 2 commits intovxcontrol:feature/next_releasefrom Mar 11, 2026
Conversation
There was a problem hiding this comment.
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.detectcovering threshold behavior, reset behavior, and argument normalization effects. - Add tests for
repeatingDetector.clearCallArgumentscovering message stripping, key ordering, and invalid JSON passthrough. - Introduce a small test helper (
makeToolCall) to buildllms.ToolCallinputs.
💡 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>
5fd3504 to
0ffe6a4
Compare
7 tasks
Contributor
|
tnx for the PR! |
36 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of the Change
Problem
The
repeatingDetectorandclearCallArgumentsfunctions inhelpers.gohad 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 whenlen(funcCalls) >= RepeatingToolCallThreshold + 4 = 7, confirming 4 soft warnings before abort on the 7th consecutive identical callTestClearCallArguments (3 cases): message field stripping, alphabetical key sorting, invalid JSON passthrough
All tests follow the existing table-driven pattern in
helpers_test.gousingtestify/assert.Related to #175
Adds test coverage for #178
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
go test ./pkg/providers/ -run "TestRepeatingDetector|TestClearCallArguments" -v-- all 12 tests passgo test ./pkg/providers/ -v-- all existing tests continue to pass (no regressions)go vet ./pkg/providers/-- no warningsSecurity Considerations
No security impact. Test-only change.
Checklist
go fmtandgo vet