From 1711a53221c2b5c4606fc98334dc01e9bda48972 Mon Sep 17 00:00:00 2001 From: clawbot <35+clawbot@noreply.example.org> Date: Fri, 2 Oct 2026 17:22:31 +0000 Subject: [PATCH] Route the delivery tests' gorm.Open through gormlog (closes #462) The six gorm.Open calls in the internal/delivery tests passed a bare gorm.Config, which installs GORM's default logger; they now pass gormlog.New over a logger that discards, as every production call does, so the unfiltered form is no longer in the tree to be copied. The README and the ParamsFilter comment said (*gorm.DB).Scan had one test-only caller; there are more. Both now say only tests call it, with fixture data. Model: opus-5-5 --- README.md | 9 ++++----- internal/delivery/archive_sweeper_test.go | 10 +++++++--- internal/delivery/engine_integration_test.go | 4 +++- internal/delivery/engine_test.go | 4 +++- internal/delivery/target_database_test.go | 4 +++- internal/gormlog/gormlog.go | 6 +++--- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1f845f4..c39247a 100644 --- a/README.md +++ b/README.md @@ -2609,11 +2609,10 @@ on all three arms of `Trace`, including the routine one an operator reaches at `DEBUG`, which is the only level at which a successful `INSERT` is written at all. One GORM path does not consult the filter — `(*gorm.DB).Scan`, which records the statement through GORM's own trace -recorder. No production code path calls it; its one caller is -`internal/database/database_test.go:91`, whose `SELECT 1` binds -nothing, and `internal/gormlog/scan_guard_test.go` fails if a non-test -file calls it. `Pluck`, `Row` and `Raw` all run through the normal -callback processor and are filtered. +recorder. No production code path calls it; only tests do, and what a +test binds is fixture data. `internal/gormlog/scan_guard_test.go` fails +if a non-test file calls it. `Pluck`, `Row` and `Raw` all run through +the normal callback processor and are filtered. See `#### What DEBUG=true exposes` under Configuration. What that ceiling does **not** cover, stated here so the figure is not diff --git a/internal/delivery/archive_sweeper_test.go b/internal/delivery/archive_sweeper_test.go index 0135890..c596692 100644 --- a/internal/delivery/archive_sweeper_test.go +++ b/internal/delivery/archive_sweeper_test.go @@ -22,6 +22,7 @@ import ( _ "modernc.org/sqlite" // Pure Go SQLite driver. "sneak.berlin/go/webhooker/internal/database" "sneak.berlin/go/webhooker/internal/delivery" + "sneak.berlin/go/webhooker/internal/gormlog" ) const ( @@ -70,7 +71,8 @@ func setupArchiveTest(t *testing.T) *archiveEnv { t.Cleanup(func() { _ = sqlDB.Close() }) gdb, err := gorm.Open( - sqlite.Dialector{Conn: sqlDB}, &gorm.Config{}, + sqlite.Dialector{Conn: sqlDB}, + &gorm.Config{Logger: gormlog.New(slog.New(slog.DiscardHandler))}, ) require.NoError(t, err) @@ -168,7 +170,8 @@ func (env *archiveEnv) seedArchiveRows( require.NoError(t, err) gdb, err := gorm.Open( - sqlite.Dialector{Conn: sqlDB}, &gorm.Config{}, + sqlite.Dialector{Conn: sqlDB}, + &gorm.Config{Logger: gormlog.New(slog.New(slog.DiscardHandler))}, ) require.NoError(t, err) @@ -227,7 +230,8 @@ func countArchivedRows(path string) (int64, error) { defer func() { _ = sqlDB.Close() }() gdb, err := gorm.Open( - sqlite.Dialector{Conn: sqlDB}, &gorm.Config{}, + sqlite.Dialector{Conn: sqlDB}, + &gorm.Config{Logger: gormlog.New(slog.New(slog.DiscardHandler))}, ) if err != nil { return 0, err diff --git a/internal/delivery/engine_integration_test.go b/internal/delivery/engine_integration_test.go index a902a9a..e74d4f3 100644 --- a/internal/delivery/engine_integration_test.go +++ b/internal/delivery/engine_integration_test.go @@ -23,6 +23,7 @@ import ( _ "modernc.org/sqlite" "sneak.berlin/go/webhooker/internal/database" "sneak.berlin/go/webhooker/internal/delivery" + "sneak.berlin/go/webhooker/internal/gormlog" ) // iSetup holds common integration test dependencies. @@ -80,7 +81,8 @@ func iMainDB(t *testing.T) *gorm.DB { t.Cleanup(func() { _ = sqlDB.Close() }) db, err := gorm.Open( - sqlite.Dialector{Conn: sqlDB}, &gorm.Config{}, + sqlite.Dialector{Conn: sqlDB}, + &gorm.Config{Logger: gormlog.New(slog.New(slog.DiscardHandler))}, ) require.NoError(t, err) diff --git a/internal/delivery/engine_test.go b/internal/delivery/engine_test.go index d91fbd0..c06a772 100644 --- a/internal/delivery/engine_test.go +++ b/internal/delivery/engine_test.go @@ -26,6 +26,7 @@ import ( _ "modernc.org/sqlite" "sneak.berlin/go/webhooker/internal/database" "sneak.berlin/go/webhooker/internal/delivery" + "sneak.berlin/go/webhooker/internal/gormlog" "sneak.berlin/go/webhooker/internal/metrics" ) @@ -50,7 +51,8 @@ func testWebhookDB(t *testing.T) *gorm.DB { t.Cleanup(func() { _ = sqlDB.Close() }) db, err := gorm.Open( - sqlite.Dialector{Conn: sqlDB}, &gorm.Config{}, + sqlite.Dialector{Conn: sqlDB}, + &gorm.Config{Logger: gormlog.New(slog.New(slog.DiscardHandler))}, ) require.NoError(t, err) diff --git a/internal/delivery/target_database_test.go b/internal/delivery/target_database_test.go index ed7fb24..4a12dc7 100644 --- a/internal/delivery/target_database_test.go +++ b/internal/delivery/target_database_test.go @@ -17,6 +17,7 @@ import ( _ "modernc.org/sqlite" // Pure Go SQLite driver. "sneak.berlin/go/webhooker/internal/database" "sneak.berlin/go/webhooker/internal/delivery" + "sneak.berlin/go/webhooker/internal/gormlog" ) func archiveTestLogger() *slog.Logger { @@ -42,7 +43,8 @@ func openArchiveDBForRead( t.Cleanup(func() { _ = sqlDB.Close() }) gdb, err := gorm.Open( - sqlite.Dialector{Conn: sqlDB}, &gorm.Config{}, + sqlite.Dialector{Conn: sqlDB}, + &gorm.Config{Logger: gormlog.New(slog.New(slog.DiscardHandler))}, ) require.NoError(t, err) diff --git a/internal/gormlog/gormlog.go b/internal/gormlog/gormlog.go index 3e17f75..07f5bd6 100644 --- a/internal/gormlog/gormlog.go +++ b/internal/gormlog/gormlog.go @@ -111,9 +111,9 @@ func (l *Logger) LogMode(gormlogger.LogLevel) gormlogger.Interface { // // One GORM path does not consult this: (*gorm.DB).Scan records the // statement through gorm's own traceRecorder, which does not implement -// this interface. No production code path calls it; its one caller is -// internal/database/database_test.go:91, whose SELECT 1 binds nothing. -// scan_guard_test.go fails if a non-test file calls it. +// this interface. No production code path calls it; only tests do, and +// what a test binds is fixture data. scan_guard_test.go fails if a +// non-test file calls it. // (*gorm.DB).Pluck, Row and Raw all run through the normal callback // processor and are filtered. func (l *Logger) ParamsFilter(