(t *testing.T)
| 174 | } |
| 175 | |
| 176 | func TestWorkingMemoryManager_TTL(t *testing.T) { |
| 177 | ctx := context.Background() |
| 178 | backend := backends.NewStateBackend() |
| 179 | |
| 180 | // 创建带 TTL 的管理器(1 秒过期) |
| 181 | manager, err := NewWorkingMemoryManager(&WorkingMemoryConfig{ |
| 182 | Backend: backend, |
| 183 | BasePath: "/working_memory/", |
| 184 | Scope: ScopeThread, |
| 185 | DefaultTTL: 1 * time.Second, |
| 186 | }) |
| 187 | if err != nil { |
| 188 | t.Fatalf("create manager: %v", err) |
| 189 | } |
| 190 | |
| 191 | threadID := "test-thread" |
| 192 | resourceID := "test-resource" |
| 193 | |
| 194 | // 更新内容 |
| 195 | err = manager.Update(ctx, threadID, resourceID, "Temporary content") |
| 196 | if err != nil { |
| 197 | t.Fatalf("update: %v", err) |
| 198 | } |
| 199 | |
| 200 | // 立即读取应该成功 |
| 201 | content, _ := manager.Get(ctx, threadID, resourceID) |
| 202 | if content == "" { |
| 203 | t.Error("expected content immediately after update") |
| 204 | } |
| 205 | |
| 206 | // 等待过期 |
| 207 | time.Sleep(2 * time.Second) |
| 208 | |
| 209 | // 过期后应该返回空 |
| 210 | content, err = manager.Get(ctx, threadID, resourceID) |
| 211 | if err != nil { |
| 212 | t.Fatalf("get after expiry: %v", err) |
| 213 | } |
| 214 | if content != "" { |
| 215 | t.Errorf("expected empty content after expiry, got: %s", content) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | func TestWorkingMemoryManager_Schema(t *testing.T) { |
| 220 | ctx := context.Background() |
nothing calls this directly
no test coverage detected