test(agentdrain): rewrite anomaly_test.go with testify and table-driven tests#24470
Merged
test(agentdrain): rewrite anomaly_test.go with testify and table-driven tests#24470
Conversation
8 tasks
…en tests Agent-Logs-Url: https://github.com/github/gh-aw/sessions/8d060ef4-f24c-47af-9a01-22b9bf4e9dea Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve test quality for pkg/agentdrain/anomaly_test.go
test(agentdrain): rewrite anomaly_test.go with testify and table-driven tests
Apr 4, 2026
Closed
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors pkg/agentdrain/anomaly_test.go to make anomaly detection tests more readable and more complete by switching to testify assertions and consolidating scenarios into table-driven subtests.
Changes:
- Replaced multiple single-scenario anomaly tests with a single table-driven
TestAnomalyDetector_Analyze. - Added new sub-cases covering boundary conditions, combined flags, nil cluster handling, and score ceiling behavior.
- Updated
TestAnalyzeEventto userequire/assertfor clearer failure output and stronger precondition checks.
Show a summary per file
| File | Description |
|---|---|
| pkg/agentdrain/anomaly_test.go | Rewrites anomaly-related unit tests using testify + table-driven cases and adds additional coverage for scoring/flag edge cases. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
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.
pkg/agentdrain/anomaly_test.goused rawt.Error/t.Fatalcalls and four separate single-scenario test functions, making failures hard to read and edge cases uncovered.Changes
TestAnomalyDetection_NewTemplate/LowSimilarity/RareCluster/Normalinto a single table-drivenTestAnomalyDetector_Analyzewithrequire/assertand descriptive messages0.4 < 0.4 → false, boundary)0.39 < 0.4 → true, boundary)LowSimilarity + RareCluster(score = 0.5)nilcluster (guards theif cluster != nilbranch explicitly)IsNewTemplate + RareCluster→ 0.65 (with explanation thatLowSimilarityis mutually exclusive withisNew=true)TestAnalyzeEventtorequire.NoError/require.NotNil/assert.True/assert.Falsewith descriptive messagesAnomalyScoreassertions (assert.InDelta) instead of just> 0checks, pinning the weighted scoring math