(t *testing.T)
| 128 | } |
| 129 | |
| 130 | func TestWorkingMemoryManager_FindAndReplace(t *testing.T) { |
| 131 | ctx := context.Background() |
| 132 | backend := backends.NewStateBackend() |
| 133 | |
| 134 | manager, err := NewWorkingMemoryManager(&WorkingMemoryConfig{ |
| 135 | Backend: backend, |
| 136 | BasePath: "/working_memory/", |
| 137 | Scope: ScopeThread, |
| 138 | }) |
| 139 | if err != nil { |
| 140 | t.Fatalf("create manager: %v", err) |
| 141 | } |
| 142 | |
| 143 | threadID := "test-thread" |
| 144 | resourceID := "test-resource" |
| 145 | |
| 146 | // 初始内容 |
| 147 | initialContent := "Line 1\nLine 2\nLine 3" |
| 148 | err = manager.Update(ctx, threadID, resourceID, initialContent) |
| 149 | if err != nil { |
| 150 | t.Fatalf("update initial: %v", err) |
| 151 | } |
| 152 | |
| 153 | // Find and replace |
| 154 | err = manager.FindAndReplace(ctx, threadID, resourceID, "Line 2", "Line 2 (updated)") |
| 155 | if err != nil { |
| 156 | t.Fatalf("find and replace: %v", err) |
| 157 | } |
| 158 | |
| 159 | content, _ := manager.Get(ctx, threadID, resourceID) |
| 160 | if !strings.Contains(content, "Line 2 (updated)") { |
| 161 | t.Errorf("expected to find 'Line 2 (updated)', got: %s", content) |
| 162 | } |
| 163 | |
| 164 | // Append (empty search string) |
| 165 | err = manager.FindAndReplace(ctx, threadID, resourceID, "", "Line 4") |
| 166 | if err != nil { |
| 167 | t.Fatalf("append: %v", err) |
| 168 | } |
| 169 | |
| 170 | content, _ = manager.Get(ctx, threadID, resourceID) |
| 171 | if !strings.Contains(content, "Line 4") { |
| 172 | t.Errorf("expected to find 'Line 4', got: %s", content) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | func TestWorkingMemoryManager_TTL(t *testing.T) { |
| 177 | ctx := context.Background() |
nothing calls this directly
no test coverage detected