Skip to content

Commit 0ca5a38

Browse files
DotNetAgeclaude
andcommitted
fix: session Clear walk fix, WatchService nil check, modelselect test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 61d466f commit 0ca5a38

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

internal/setup/component/modelselect/modelselect_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
package modelselect
22

33
import (
4+
"regexp"
45
"strings"
56
"testing"
67

78
setupdata "github.com/DotNetAge/mindx/internal/setup/data"
89
)
910

11+
func stripANSI(s string) string {
12+
re := regexp.MustCompile("\x1b\\[[0-9;]*[a-zA-Z]")
13+
return re.ReplaceAllString(s, "")
14+
}
15+
1016
func TestViewContainsGradientTitle(t *testing.T) {
1117
items := []setupdata.ModelItem{
1218
{Name: "GPT-4o", Desc: "OpenAI 最新多模态模型", BaseURL: "https://api.openai.com/v1", CredRef: "openai"},
@@ -18,10 +24,11 @@ func TestViewContainsGradientTitle(t *testing.T) {
1824
view := m.View()
1925
t.Logf("\n=== View Output ===\n%s\n=== End ===", view)
2026

21-
if !strings.Contains(view, "选择 AI 模型") {
22-
t.Error("View output does NOT contain '选择 AI 模型'")
27+
plain := stripANSI(view)
28+
if !strings.Contains(plain, "选择一个 AI 模型") {
29+
t.Error("View output does NOT contain '选择一个 AI 模型'")
2330
} else {
24-
t.Log("✅ View output contains '选择 AI 模型'")
31+
t.Log("✅ View output contains '选择一个 AI 模型'")
2532
}
2633

2734
if strings.Contains(view, "\x1b[") {

pkg/memory/watch_service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ func (s *FileWatchService) Start(ctx context.Context) error {
142142
// Stop gracefully shuts down the file watch service.
143143
func (s *FileWatchService) Stop() {
144144
s.cancel()
145-
_ = s.watcher.Close()
145+
if s.watcher != nil {
146+
_ = s.watcher.Close()
147+
}
146148
<-s.done
147149
s.wg.Wait()
148150
}

pkg/session/file_store.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,22 @@ func (s *FileSessionStore) Delete(ctx context.Context, timestamp int64, sessionI
338338
}
339339

340340
func (s *FileSessionStore) Clear(ctx context.Context, sessionID string) error {
341-
dirPath := s.findSessionDir(sessionID)
341+
var dirPath string
342+
_ = filepath.Walk(s.rootDir, func(path string, info os.FileInfo, err error) error {
343+
if err != nil || info.IsDir() || info.Name() != "session.yml" {
344+
return nil
345+
}
346+
parentDir := filepath.Base(filepath.Dir(path))
347+
if parentDir == sessionID {
348+
dirPath = filepath.Dir(path)
349+
return filepath.SkipAll
350+
}
351+
return nil
352+
})
342353
if dirPath == "" {
343354
return nil
344355
}
345-
346-
_ = os.RemoveAll(dirPath)
347-
return nil
356+
return os.RemoveAll(dirPath)
348357
}
349358

350359
// DeleteSession removes the entire session directory and all its contents.

0 commit comments

Comments
 (0)