返回 DeepSeek-Reasonix
bounded_name_test.go
根目录 / internal / memory / bounded_name_test.go
1 package memory
2
3 import (
4 "strings"
5 "testing"
6 )
7
8 // TestSaveBoundsLongNames: a memory name distilled from a long
9 // title/description used to fail the write with ENAMETOOLONG because
10 // slug(name)+".md" exceeded the 255-byte filename component limit.
11 func TestSaveBoundsLongNames(t *testing.T) {
12 s := StoreFor(t.TempDir(), t.TempDir())
13 long := strings.Repeat("always-verify-the-desktop-session-lease-before-rebuild-", 8) + "end"
14 path, err := s.Save(Memory{Name: long, Description: "d", Type: TypeProject, Body: "b"})
15 if err != nil {
16 t.Fatalf("Save long name: %v", err)
17 }
18 if path == "" {
19 t.Fatal("Save returned empty path")
20 }
21 // Distinct long names must persist as distinct files.
22 other := strings.Repeat("always-verify-the-desktop-session-lease-before-rebuild-", 8) + "other"
23 path2, err := s.Save(Memory{Name: other, Description: "d", Type: TypeProject, Body: "b2"})
24 if err != nil {
25 t.Fatalf("Save second long name: %v", err)
26 }
27 if path2 == path {
28 t.Fatalf("distinct long names collapsed to one file: %q", path)
29 }
30 if got := s.List(); len(got) != 2 {
31 t.Fatalf("List() = %d memories, want 2", len(got))
32 }
33 }
34
35 // TestSlugShortNamesUnchanged: short names keep their historical slug so
36 // existing memory files keep resolving after upgrade.
37 func TestSlugShortNamesUnchanged(t *testing.T) {
38 if got := slug("My Setting: prefer 中文"); got != "my-setting-prefer-中文" {
39 t.Fatalf("short slug changed: %q", got)
40 }
41 }
42
42 lines GO