返回 DeepSeek-Reasonix
convention_test.go
根目录 / internal / memory / convention_test.go
1 package memory
2
3 import (
4 "os"
5 "path/filepath"
6 "strings"
7 "testing"
8 )
9
10 func TestClaudeMdDiscovered(t *testing.T) {
11 proj := t.TempDir()
12 mustMkdir(t, filepath.Join(proj, ".git"))
13 mustWrite(t, filepath.Join(proj, "CLAUDE.md"), "Rule from CLAUDE.md")
14
15 set := Load(Options{CWD: proj})
16 if !strings.Contains(set.Block(), "Rule from CLAUDE.md") {
17 t.Fatalf("CLAUDE.md should be discovered and folded in:\n%s", set.Block())
18 }
19 }
20
21 func TestSymlinkedAgentAndClaudeDocsComposeOnce(t *testing.T) {
22 proj := t.TempDir()
23 mustMkdir(t, filepath.Join(proj, ".git"))
24 mustWrite(t, filepath.Join(proj, "CLAUDE.md"), "Shared symlink guidance")
25 if err := os.Symlink("CLAUDE.md", filepath.Join(proj, "AGENTS.md")); err != nil {
26 t.Skipf("symlink unsupported: %v", err)
27 }
28
29 prompt := Compose("BASE", Load(Options{CWD: proj}))
30 if got := strings.Count(prompt, "Shared symlink guidance"); got != 1 {
31 t.Fatalf("symlinked memory should be composed once, got %d occurrences:\n%s", got, prompt)
32 }
33 }
34
35 func TestDocPathDefaultsToAgents(t *testing.T) {
36 proj := t.TempDir()
37 set := Load(Options{CWD: proj})
38 if got := set.DocPath(ScopeProject); filepath.Base(got) != "AGENTS.md" {
39 t.Errorf("fresh project should default to AGENTS.md, got %s", got)
40 }
41 if got := set.DocPath(ScopeLocal); filepath.Base(got) != "AGENTS.local.md" {
42 t.Errorf("fresh local should default to AGENTS.local.md, got %s", got)
43 }
44 }
45
46 func TestDocPathPrefersExisting(t *testing.T) {
47 proj := t.TempDir()
48 // An existing REASONIX.md should keep receiving notes (no split to AGENTS.md).
49 if err := os.WriteFile(filepath.Join(proj, "REASONIX.md"), []byte("x"), 0o644); err != nil {
50 t.Fatal(err)
51 }
52 set := Load(Options{CWD: proj})
53 if got := set.DocPath(ScopeProject); filepath.Base(got) != "REASONIX.md" {
54 t.Errorf("should append to the existing REASONIX.md, got %s", got)
55 }
56
57 // With only a CLAUDE.md present, that's the target.
58 proj2 := t.TempDir()
59 if err := os.WriteFile(filepath.Join(proj2, "CLAUDE.md"), []byte("y"), 0o644); err != nil {
60 t.Fatal(err)
61 }
62 set2 := Load(Options{CWD: proj2})
63 if got := set2.DocPath(ScopeProject); filepath.Base(got) != "CLAUDE.md" {
64 t.Errorf("should append to the existing CLAUDE.md, got %s", got)
65 }
66 }
67
67 lines GO