Conversation
…ew coverage Agent-Logs-Url: https://github.com/github/gh-aw/sessions/4f410dc1-fcf0-49ef-961b-738282a6dcd6 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
Hey This PR looks well-structured and ready for maintainer review. 🎉
|
There was a problem hiding this comment.
Pull request overview
Updates pkg/agentdrain/miner_test.go to use testify assertions consistently (matching existing package test conventions) and adds new tests to cover previously untested coordinator/miner behaviors, including event training/routing, stage sequencing, and snapshot persistence.
Changes:
- Migrated existing tests from manual
t.Fatal/t.Errorfpatterns torequire/assert. - Refactored training-related tests into a single table-driven
TestTrainand added new tests forTrainEvent,Clusters, and coordinatorAnalyzeEvent. - Added persistence round-trip coverage via
SaveSnapshots/LoadSnapshotsand expanded stage-sequence coverage.
Show a summary per file
| File | Description |
|---|---|
| pkg/agentdrain/miner_test.go | Migrates tests to testify and adds new coverage for training, coordinator analysis, stage sequencing, and persistence. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (3)
pkg/agentdrain/miner_test.go:178
indexIndoes not compile:for i := range len(s) - len(substr) + 1attempts to range over anint. Usestrings.Index(and re-add thestringsimport) or a classicfor i := 0; i <= len(s)-len(substr); i++loop with a guard forlen(substr) > len(s).
func indexIn(s, substr string) int {
for i := range len(s) - len(substr) + 1 {
if s[i:i+len(substr)] == substr {
return i
}
pkg/agentdrain/miner_test.go:195
- This test won’t compile:
for g := range goroutines/for i := range linesEachattempt to range overintconstants. Use a counted loop (for g := 0; g < goroutines; g++ { ... }, similarly fori).
for g := range goroutines {
wg.Add(1)
go func(id int) {
defer wg.Done()
for i := range linesEach {
pkg/agentdrain/miner_test.go:199
assert.NoError(t, ...)is called from multiple goroutines;testing.T(and testify assertions that wrap it) are not safe to use concurrently and can race/panic. Collect errors in a channel/slice protected by a mutex and assert in the main goroutine afterwg.Wait(), or uset.Runsubtests instead of raw goroutines.
line := fmt.Sprintf("stage=work goroutine=%d iter=%d", id, i)
_, trainErr := m.Train(line)
assert.NoError(t, trainErr, "Train should not error during concurrent access")
}
- Files reviewed: 1/1 changed files
- Comments generated: 1
| assert.True(t, len(result) > 0 && | ||
| indexIn(result, "latency_ms=") < indexIn(result, "query=") && | ||
| indexIn(result, "query=") < indexIn(result, "tool="), |
There was a problem hiding this comment.
The key-order assertion can pass even if a key is missing because indexIn returns -1 and -1 < someIndex is true. Assert each required key exists (index != -1) before comparing order, or use strings.Index and explicitly check for -1.
This issue also appears in the following locations of the same file:
- line 174
- line 191
- line 196
| assert.True(t, len(result) > 0 && | |
| indexIn(result, "latency_ms=") < indexIn(result, "query=") && | |
| indexIn(result, "query=") < indexIn(result, "tool="), | |
| latencyIdx := indexIn(result, "latency_ms=") | |
| queryIdx := indexIn(result, "query=") | |
| toolIdx := indexIn(result, "tool=") | |
| assert.NotEqual(t, -1, latencyIdx, "flattened output should contain latency_ms: %q", result) | |
| assert.NotEqual(t, -1, queryIdx, "flattened output should contain query: %q", result) | |
| assert.NotEqual(t, -1, toolIdx, "flattened output should contain tool: %q", result) | |
| assert.True(t, len(result) > 0 && | |
| latencyIdx < queryIdx && | |
| queryIdx < toolIdx, |
miner_test.goused rawt.Fatal/t.Errorfthroughout while its siblinganomaly_test.goalready uses testify. This brings the file in line with package conventions and adds coverage for previously untested code paths.Refactoring
t.Fatal/t.Fatalfsetup checks withrequire.NoError/require.NotNilt.Errorfcomparisons withassert.Equal,assert.Contains,assert.InDelta,assert.Positive,assert.ErrorTestMergeTemplatewithassert.EqualTestTrain_ClusterCreation+TestTrain_ClusterMergeinto a single table-drivenTestTrain(4 subtests: create, no-merge, separate clusters, merge→wildcard)New tests
TestTrainEventMiner.TrainEventTestClustersMiner.Clusters()snapshot on empty and non-empty minerTestCoordinatorAnalyzeEventIsNewTemplate; repeat → not new; unknown stage → errorTestStageSequenceTestPersistenceRoundTripSaveSnapshots→LoadSnapshotspreserves per-stage cluster counts