diff --git a/internal/modules/dispatcher.go b/internal/modules/dispatcher.go index 9be4e0b..64ca910 100644 --- a/internal/modules/dispatcher.go +++ b/internal/modules/dispatcher.go @@ -68,6 +68,9 @@ func Install(b *bot.Bot, reg *Registry, auth Auth) { } metrics.IncCommand(cmdCopy.Name) go func() { + // context.Background is intentional: the hook must outlive the request + // context so stats writes complete even after the handler returns. + //nolint:gosec // G118: goroutine intentionally detached from request context hookCtx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() reg.RunCommandHooks(hookCtx, cmdCopy.Name) diff --git a/internal/modules/stats/stats_test.go b/internal/modules/stats/stats_test.go index d7f5e80..831e05d 100644 --- a/internal/modules/stats/stats_test.go +++ b/internal/modules/stats/stats_test.go @@ -110,7 +110,7 @@ func TestStats_ShowsCountsSortedByPopularity(t *testing.T) { if wordlePos < 0 || loLdlePos < 0 || pingPos < 0 { t.Fatalf("reply missing expected commands: %q", got) } - if !(wordlePos < loLdlePos && loLdlePos < pingPos) { + if wordlePos >= loLdlePos || loLdlePos >= pingPos { t.Errorf("commands not in descending count order: wordle=%d loldle=%d ping=%d in %q", wordlePos, loLdlePos, pingPos, got) }