Skip to content

Commit de5097d

Browse files
wesmclaude
andcommitted
fix: resolve CI lint errors and flaky tests
- analytics.go: use min() builtin, remove unused filteredSessions - codex.go: use strings.SplitSeq for efficiency (modernize lint) - server_test.go: remove unused seedSessionWithMessages - watcher_test.go: poll for nested path instead of counting onChange calls, fixing race on slow CI runners - db_test.go: close raw DB before concurrent Opens to avoid Windows file locking in TestMigrationRace Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f38045d commit de5097d

File tree

5 files changed

+27
-42
lines changed

5 files changed

+27
-42
lines changed

internal/db/analytics.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ func queryChunked(
3232
fn func(chunk []string) error,
3333
) error {
3434
for i := 0; i < len(ids); i += maxSQLVars {
35-
end := i + maxSQLVars
36-
if end > len(ids) {
37-
end = len(ids)
38-
}
35+
end := min(i+maxSQLVars, len(ids))
3936
if err := fn(ids[i:end]); err != nil {
4037
return err
4138
}
@@ -398,10 +395,7 @@ func (db *DB) GetAnalyticsSummary(
398395
counts = append(counts, c)
399396
}
400397
sort.Sort(sort.Reverse(sort.IntSlice(counts)))
401-
top := 3
402-
if len(counts) < top {
403-
top = len(counts)
404-
}
398+
top := min(3, len(counts))
405399
topSum := 0
406400
for _, c := range counts[:top] {
407401
topSum += c
@@ -1150,15 +1144,9 @@ func (db *DB) GetAnalyticsSessionShape(
11501144
}
11511145
defer rows.Close()
11521146

1153-
type sessInfo struct {
1154-
id string
1155-
mc int
1156-
}
1157-
11581147
lengthCounts := make(map[string]int)
11591148
durationCounts := make(map[string]int)
11601149
var sessionIDs []string
1161-
var filteredSessions []sessInfo
11621150
totalCount := 0
11631151

11641152
for rows.Next() {
@@ -1183,8 +1171,6 @@ func (db *DB) GetAnalyticsSessionShape(
11831171
totalCount++
11841172
lengthCounts[lengthBucket(mc)]++
11851173
sessionIDs = append(sessionIDs, id)
1186-
filteredSessions = append(filteredSessions,
1187-
sessInfo{id: id, mc: mc})
11881174

11891175
if startedAt != nil && endedAt != nil &&
11901176
*startedAt != "" && *endedAt != "" {

internal/db/db_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,6 @@ func TestMigrationRace(t *testing.T) {
13841384
if err != nil {
13851385
t.Fatalf("setup: %v", err)
13861386
}
1387-
defer rawDB.Close()
13881387

13891388
// Create sessions table without file_hash
13901389
_, err = rawDB.Exec(`
@@ -1407,6 +1406,10 @@ func TestMigrationRace(t *testing.T) {
14071406
t.Fatalf("setup schema: %v", err)
14081407
}
14091408

1409+
// Close the raw connection before concurrent opens to avoid
1410+
// holding a lock on Windows.
1411+
rawDB.Close()
1412+
14101413
// 2. Run concurrent Open
14111414
// Both should succeed. One will likely hit "duplicate column".
14121415
errCh := make(chan error, 2)

internal/parser/codex.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ func extractPatchedFiles(patch string) []string {
318318

319319
var files []string
320320
seen := make(map[string]struct{})
321-
lines := strings.Split(patch, "\n")
322-
for _, line := range lines {
321+
for line := range strings.SplitSeq(patch, "\n") {
323322
for _, prefix := range []string{
324323
"*** Add File: ",
325324
"*** Update File: ",

internal/server/server_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,6 @@ func (te *testEnv) seedSession(
217217
})
218218
}
219219

220-
func (te *testEnv) seedSessionWithMessages(
221-
t *testing.T, id, project string, msgCount int,
222-
opts ...func(*db.Session),
223-
) {
224-
t.Helper()
225-
te.seedSession(t, id, project, msgCount, opts...)
226-
te.seedMessages(t, id, msgCount)
227-
}
228-
229220
func (te *testEnv) seedMessages(
230221
t *testing.T, sessionID string, count int, mods ...func(i int, m *db.Message),
231222
) {

internal/sync/watcher_test.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,19 @@ func TestWatcherCallsOnChange(t *testing.T) {
139139
}
140140

141141
func TestWatcherAutoWatchesNewDirs(t *testing.T) {
142-
var called atomic.Bool
142+
var mu sync.Mutex
143+
var allPaths []string
143144
done := make(chan struct{}, 1)
144145

145-
callCount := atomic.Int32{}
146-
onChange := func(_ []string) {
147-
if callCount.Add(1) >= 2 {
148-
if !called.Load() {
149-
called.Store(true)
150-
done <- struct{}{}
151-
}
146+
w, dir := startTestWatcher(t, func(paths []string) {
147+
mu.Lock()
148+
allPaths = append(allPaths, paths...)
149+
mu.Unlock()
150+
select {
151+
case done <- struct{}{}:
152+
default:
152153
}
153-
}
154-
155-
w, dir := startTestWatcher(t, onChange)
154+
})
156155

157156
subdir := filepath.Join(dir, "newdir")
158157
if err := os.Mkdir(subdir, 0o755); err != nil {
@@ -166,14 +165,21 @@ func TestWatcherAutoWatchesNewDirs(t *testing.T) {
166165
},
167166
)
168167

169-
path := filepath.Join(subdir, "nested.jsonl")
168+
nestedPath := filepath.Join(subdir, "nested.jsonl")
170169
if err := os.WriteFile(
171-
path, []byte("nested"), 0o644,
170+
nestedPath, []byte("nested"), 0o644,
172171
); err != nil {
173172
t.Fatalf("WriteFile: %v", err)
174173
}
175174

176-
waitWithTimeout(t, done, 5*time.Second, "timed out waiting for nested file change")
175+
pollUntil(t, 5*time.Second, 50*time.Millisecond,
176+
"timed out waiting for nested file change",
177+
func() bool {
178+
mu.Lock()
179+
defer mu.Unlock()
180+
return slices.Contains(allPaths, nestedPath)
181+
},
182+
)
177183
}
178184

179185
func TestWatcherStopIsClean(t *testing.T) {

0 commit comments

Comments
 (0)