fix(gateway): restore the lint gate after the messaging store migration
5713231 landed with golangci-lint red: scanSearchMessages was an exact copy
of scanMessages bar two error strings (dupl), and the pre-role schema
migration test seeded its fixture with db.Exec (noctx). task check has been
failing on main since.
Collapse the two scanners into one -- SearchMessages already selects the same
column order the history reads do, which the deleted function's own comment
said -- and seed the fixture through ExecContext.
No behaviour change: the gateway suite passes unchanged.
This commit is contained in:
1 parent
571323138d
commit
3ed17661b4
2 files changed
+7
-32
No files matched your search
@@ -994,6 +994,9 @@ func (s *sqliteSessionStore) MessageCount(ctx context.Context, sessionID string)
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// scanMessages scans rows shaped (message_id, source_id, sender, role, text,
|
||||
// ts, channel_id, thread_id). Both the history reads and SearchMessages select
|
||||
// that column order, so they share one scanner.
|
||||
func scanMessages(rows *sql.Rows) ([]messaging.Message, error) {
|
||||
defer func() { _ = rows.Close() }()
|
||||
var out []messaging.Message
|
||||
@@ -1071,7 +1074,7 @@ func (s *sqliteSessionStore) SearchMessages(ctx context.Context, sessionID strin
|
||||
if err != nil {
|
||||
return MessagePage{}, fmt.Errorf("sessionstore: search messages: %w", err)
|
||||
}
|
||||
msgs, err := scanSearchMessages(rows)
|
||||
msgs, err := scanMessages(rows)
|
||||
if err != nil {
|
||||
return MessagePage{}, err
|
||||
}
|
||||
@@ -1085,34 +1088,6 @@ func (s *sqliteSessionStore) SearchMessages(ctx context.Context, sessionID strin
|
||||
}, nil
|
||||
}
|
||||
|
||||
// scanSearchMessages scans rows shaped (message_id, source_id, sender,
|
||||
// role, text, ts, channel_id, thread_id) -- the same column order
|
||||
// SearchMessages selects.
|
||||
func scanSearchMessages(rows *sql.Rows) ([]messaging.Message, error) {
|
||||
defer func() { _ = rows.Close() }()
|
||||
var out []messaging.Message
|
||||
for rows.Next() {
|
||||
var (
|
||||
msg messaging.Message
|
||||
id string
|
||||
role string
|
||||
ts int64
|
||||
)
|
||||
if err := rows.Scan(&id, &msg.SourceID, &msg.Sender, &role, &msg.Text, &ts,
|
||||
&msg.ConversationID.ChannelID, &msg.ConversationID.ThreadID); err != nil {
|
||||
return nil, fmt.Errorf("sessionstore: scan search result: %w", err)
|
||||
}
|
||||
msg.ID = messaging.MessageID(id)
|
||||
msg.Role = messaging.Role(role)
|
||||
msg.At = time.UnixMilli(ts).UTC()
|
||||
out = append(out, msg)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("sessionstore: scan search results: %w", err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ftsMatchQuery turns free text into an FTS5 MATCH expression requiring
|
||||
// every term to be present. Each term is wrapped as a quoted phrase --
|
||||
// doubling any embedded quote to escape it -- so user input can never be
|
||||
|
||||
@@ -645,15 +645,15 @@ func TestSQLiteSessionStore_MigratesPreRoleDatabase(t *testing.T) {
|
||||
oldMessages := strings.Replace(sqliteSessionSchema,
|
||||
"\tsender TEXT NOT NULL DEFAULT '',\n\trole TEXT NOT NULL DEFAULT '',\n",
|
||||
"\tsender TEXT NOT NULL DEFAULT '',\n", 1)
|
||||
if _, err := db.Exec(oldMessages); err != nil {
|
||||
if _, err := db.ExecContext(t.Context(), oldMessages); err != nil {
|
||||
t.Fatalf("create old schema: %v", err)
|
||||
}
|
||||
millis := sqliteBase().UnixMilli()
|
||||
if _, err := db.Exec(`INSERT INTO sessions (session_id, platform, bot_user, channel_id, created_at, last_active_at)
|
||||
if _, err := db.ExecContext(t.Context(), `INSERT INTO sessions (session_id, platform, bot_user, channel_id, created_at, last_active_at)
|
||||
VALUES ('sess-old', 'telegram', 'archie', 'chat-1', ?, ?)`, millis, millis); err != nil {
|
||||
t.Fatalf("seed old session: %v", err)
|
||||
}
|
||||
if _, err := db.Exec(`INSERT INTO messages (message_id, session_id, source_id, sender, text, ts) VALUES
|
||||
if _, err := db.ExecContext(t.Context(), `INSERT INTO messages (message_id, session_id, source_id, sender, text, ts) VALUES
|
||||
('m-user', 'sess-old', 'tg-1', 'alice', 'hello', ?),
|
||||
('m-assistant', 'sess-old', '', 'archie', 'hi', ?)`, millis, millis+1); err != nil {
|
||||
t.Fatalf("seed old messages: %v", err)
|
||||
|
||||
Reference in new issue
Block a user