返回 DeepSeek-Reasonix
branch_sanitize_test.go
根目录 / internal / agent / branch_sanitize_test.go
1 package agent
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7 "time"
8 )
9
10 // Older builds persisted display fields polluted with internal wrappers.
11 // LoadBranchMeta is the single read boundary, so it must return the
12 // user-authored text instead (#5666).
13 func TestLoadBranchMetaSanitizesPollutedDisplayFields(t *testing.T) {
14 dir := t.TempDir()
15 path := filepath.Join(dir, "s.jsonl")
16 if err := os.WriteFile(path, []byte(`{"role":"user","content":"hi"}`+"\n"), 0o644); err != nil {
17 t.Fatal(err)
18 }
19 polluted := realContract("fix the login bug")
20 if err := SaveBranchMeta(path, BranchMeta{
21 CreatedAt: time.Now(),
22 UpdatedAt: time.Now(),
23 TopicTitle: polluted,
24 CustomTitle: polluted,
25 Preview: polluted,
26 }); err != nil {
27 t.Fatalf("SaveBranchMeta: %v", err)
28 }
29
30 meta, ok, err := LoadBranchMeta(path)
31 if err != nil || !ok {
32 t.Fatalf("LoadBranchMeta: ok=%v err=%v", ok, err)
33 }
34 for name, got := range map[string]string{
35 "TopicTitle": meta.TopicTitle,
36 "CustomTitle": meta.CustomTitle,
37 "Preview": meta.Preview,
38 } {
39 if got != "fix the login bug" {
40 t.Errorf("%s = %q, want the unwrapped user prompt", name, got)
41 }
42 }
43
44 // Clean values pass through untouched.
45 if err := SaveBranchMeta(path, BranchMeta{CreatedAt: time.Now(), UpdatedAt: time.Now(), TopicTitle: "My topic"}); err != nil {
46 t.Fatalf("SaveBranchMeta clean: %v", err)
47 }
48 meta, _, err = LoadBranchMeta(path)
49 if err != nil {
50 t.Fatalf("LoadBranchMeta clean: %v", err)
51 }
52 if meta.TopicTitle != "My topic" {
53 t.Errorf("clean TopicTitle = %q, want unchanged", meta.TopicTitle)
54 }
55 }
56
56 lines GO