ci: add go lint and race test workflow (#187)

This commit is contained in:
BBQ
2026-03-05 11:25:33 +08:00
committed by GitHub
parent 387ac50030
commit 3feb03aca7
192 changed files with 2245 additions and 2028 deletions
+12 -12
View File
@@ -2,7 +2,7 @@ package provider
import (
"context"
"fmt"
"errors"
"log/slog"
"sort"
"strings"
@@ -65,7 +65,7 @@ func NewBuiltinProvider(log *slog.Logger, service any, chatAccessor conversation
}
}
func (p *BuiltinProvider) Type() string { return BuiltinType }
func (*BuiltinProvider) Type() string { return BuiltinType }
// --- Conversation Hooks ---
@@ -305,7 +305,7 @@ func (p *BuiltinProvider) canAccessChat(ctx context.Context, chatID, channelIden
}
}
if p.chatAccessor == nil {
return false, fmt.Errorf("chat service not available")
return false, errors.New("chat service not available")
}
return p.chatAccessor.IsParticipant(ctx, chatID, channelIdentityID)
}
@@ -314,63 +314,63 @@ func (p *BuiltinProvider) canAccessChat(ctx context.Context, chatID, channelIden
func (p *BuiltinProvider) Add(ctx context.Context, req AddRequest) (SearchResponse, error) {
if p.service == nil {
return SearchResponse{}, fmt.Errorf("memory runtime not configured")
return SearchResponse{}, errors.New("memory runtime not configured")
}
return p.service.Add(ctx, req)
}
func (p *BuiltinProvider) Search(ctx context.Context, req SearchRequest) (SearchResponse, error) {
if p.service == nil {
return SearchResponse{}, fmt.Errorf("memory runtime not configured")
return SearchResponse{}, errors.New("memory runtime not configured")
}
return p.service.Search(ctx, req)
}
func (p *BuiltinProvider) GetAll(ctx context.Context, req GetAllRequest) (SearchResponse, error) {
if p.service == nil {
return SearchResponse{}, fmt.Errorf("memory runtime not configured")
return SearchResponse{}, errors.New("memory runtime not configured")
}
return p.service.GetAll(ctx, req)
}
func (p *BuiltinProvider) Update(ctx context.Context, req UpdateRequest) (MemoryItem, error) {
if p.service == nil {
return MemoryItem{}, fmt.Errorf("memory runtime not configured")
return MemoryItem{}, errors.New("memory runtime not configured")
}
return p.service.Update(ctx, req)
}
func (p *BuiltinProvider) Delete(ctx context.Context, memoryID string) (DeleteResponse, error) {
if p.service == nil {
return DeleteResponse{}, fmt.Errorf("memory runtime not configured")
return DeleteResponse{}, errors.New("memory runtime not configured")
}
return p.service.Delete(ctx, memoryID)
}
func (p *BuiltinProvider) DeleteBatch(ctx context.Context, memoryIDs []string) (DeleteResponse, error) {
if p.service == nil {
return DeleteResponse{}, fmt.Errorf("memory runtime not configured")
return DeleteResponse{}, errors.New("memory runtime not configured")
}
return p.service.DeleteBatch(ctx, memoryIDs)
}
func (p *BuiltinProvider) DeleteAll(ctx context.Context, req DeleteAllRequest) (DeleteResponse, error) {
if p.service == nil {
return DeleteResponse{}, fmt.Errorf("memory runtime not configured")
return DeleteResponse{}, errors.New("memory runtime not configured")
}
return p.service.DeleteAll(ctx, req)
}
func (p *BuiltinProvider) Compact(ctx context.Context, filters map[string]any, ratio float64, decayDays int) (CompactResult, error) {
if p.service == nil {
return CompactResult{}, fmt.Errorf("memory runtime not configured")
return CompactResult{}, errors.New("memory runtime not configured")
}
return p.service.Compact(ctx, filters, ratio, decayDays)
}
func (p *BuiltinProvider) Usage(ctx context.Context, filters map[string]any) (UsageResponse, error) {
if p.service == nil {
return UsageResponse{}, fmt.Errorf("memory runtime not configured")
return UsageResponse{}, errors.New("memory runtime not configured")
}
return p.service.Usage(ctx, filters)
}
+2 -1
View File
@@ -1,6 +1,7 @@
package provider
import (
"errors"
"fmt"
"log/slog"
"strings"
@@ -50,7 +51,7 @@ func (r *Registry) Register(id string, provider Provider) {
func (r *Registry) Get(id string) (Provider, error) {
id = strings.TrimSpace(id)
if id == "" {
return nil, fmt.Errorf("provider id is required")
return nil, errors.New("provider id is required")
}
r.mu.RLock()
p, ok := r.instances[id]
+1 -1
View File
@@ -23,7 +23,7 @@ func NewService(log *slog.Logger, queries *sqlc.Queries) *Service {
}
}
func (s *Service) ListMeta(_ context.Context) []ProviderMeta {
func (*Service) ListMeta(_ context.Context) []ProviderMeta {
return []ProviderMeta{
{
Provider: string(ProviderBuiltin),
+1 -1
View File
@@ -23,7 +23,7 @@ type AfterChatRequest struct {
Messages []Message
}
// LLM is the interface for LLM operations needed by memory service
// LLM is the interface for LLM operations needed by memory service.
type LLM interface {
Extract(ctx context.Context, req ExtractRequest) (ExtractResponse, error)
Decide(ctx context.Context, req DecideRequest) (DecideResponse, error)
+1 -1
View File
@@ -177,7 +177,7 @@ func formatDayMarkdown(date string, records []writeRecord) string {
})
var b strings.Builder
b.WriteString(fmt.Sprintf(memFileHeaderTemplate, date))
fmt.Fprintf(&b, memFileHeaderTemplate, date)
for _, r := range records {
meta := map[string]string{"id": r.ID}
if r.Topic != "" {
-1
View File
@@ -112,4 +112,3 @@ func TestRenderMemoryDayForDisplay_NonMemoryPathUnchanged(t *testing.T) {
t.Fatalf("non-memory path should be unchanged, got: %s", out)
}
}
+7 -6
View File
@@ -80,7 +80,7 @@ func (s *Service) readFile(ctx context.Context, botID, filePath string) (string,
if err != nil {
return "", err
}
defer reader.Close()
defer func() { _ = reader.Close() }()
data, err := io.ReadAll(reader)
if err != nil {
return "", err
@@ -449,6 +449,7 @@ func memoryDirPath() string { return path.Join(config.DefaultDataMount, "me
func memoryDayPath(date string) string {
return path.Join(memoryDirPath(), strings.TrimSpace(date)+".md")
}
func memoryLegacyItemPath(id string) string {
return path.Join(memoryDirPath(), strings.TrimSpace(id)+".md")
}
@@ -499,7 +500,7 @@ func formatMemoryDayMD(date string, items []MemoryItem) string {
func parseMemoryDayMD(content string) ([]MemoryItem, error) {
content = strings.TrimSpace(content)
if content == "" {
return nil, fmt.Errorf("empty memory file")
return nil, errors.New("empty memory file")
}
lines := strings.Split(content, "\n")
items := make([]MemoryItem, 0, 8)
@@ -536,7 +537,7 @@ func parseMemoryDayMD(content string) ([]MemoryItem, error) {
i = end
}
if len(items) == 0 {
return nil, fmt.Errorf("no memory entries found")
return nil, errors.New("no memory entries found")
}
return items, nil
}
@@ -544,11 +545,11 @@ func parseMemoryDayMD(content string) ([]MemoryItem, error) {
func parseLegacyMemoryMD(content string) (MemoryItem, error) {
content = strings.TrimSpace(content)
if !strings.HasPrefix(content, "---") {
return MemoryItem{}, fmt.Errorf("missing frontmatter")
return MemoryItem{}, errors.New("missing frontmatter")
}
parts := strings.SplitN(content[3:], "---", 2)
if len(parts) < 2 {
return MemoryItem{}, fmt.Errorf("incomplete frontmatter")
return MemoryItem{}, errors.New("incomplete frontmatter")
}
item := MemoryItem{Memory: strings.TrimSpace(parts[1])}
for _, line := range strings.Split(strings.TrimSpace(parts[0]), "\n") {
@@ -568,7 +569,7 @@ func parseLegacyMemoryMD(content string) (MemoryItem, error) {
}
}
if item.ID == "" {
return MemoryItem{}, fmt.Errorf("missing id in frontmatter")
return MemoryItem{}, errors.New("missing id in frontmatter")
}
return item, nil
}