(t *testing.T)
| 336 | } |
| 337 | |
| 338 | func TestMemoryHandlersSearchAndReindex(t *testing.T) { |
| 339 | t.Parallel() |
| 340 | |
| 341 | store, workspace := newTestMemoryStore(t) |
| 342 | mustWriteMemory( |
| 343 | t, |
| 344 | store, |
| 345 | memcontract.ScopeGlobal, |
| 346 | "", |
| 347 | "prefs.md", |
| 348 | memcontract.TypeUser, |
| 349 | "User prefers concise answers", |
| 350 | ) |
| 351 | mustWriteMemory( |
| 352 | t, |
| 353 | store, |
| 354 | memcontract.ScopeWorkspace, |
| 355 | workspace, |
| 356 | "auth.md", |
| 357 | memcontract.TypeProject, |
| 358 | "Auth migration uses sessions", |
| 359 | ) |
| 360 | |
| 361 | handlers := newTestMemoryHandlers(t, stubSessionManager{}, stubObserver{}, store, &stubDreamTrigger{}) |
| 362 | engine := newTestRouter(t, handlers) |
| 363 | |
| 364 | search := performRequest( |
| 365 | t, |
| 366 | engine, |
| 367 | http.MethodPost, |
| 368 | "/api/memory/search", |
| 369 | []byte(`{"query_text":"auth migration sessions","workspace_id":"`+escapeJSON(workspace)+`"}`), |
| 370 | ) |
| 371 | if search.Code != http.StatusOK { |
| 372 | t.Fatalf("search status = %d, want %d; body=%s", search.Code, http.StatusOK, search.Body.String()) |
| 373 | } |
| 374 | |
| 375 | var searchPayload memorySearchResponse |
| 376 | decodeJSONResponse(t, search, &searchPayload) |
| 377 | if len(searchPayload.Results) == 0 || searchPayload.Results[0].Memory.Scope != memcontract.ScopeWorkspace { |
| 378 | t.Fatalf("search results = %#v, want workspace hit first", searchPayload.Results) |
| 379 | } |
| 380 | |
| 381 | globalOnly := performRequest( |
| 382 | t, |
| 383 | engine, |
| 384 | http.MethodPost, |
| 385 | "/api/memory/search", |
| 386 | []byte(`{"scope":"global","workspace_id":"`+escapeJSON(workspace)+`","query_text":"sessions"}`), |
| 387 | ) |
| 388 | if globalOnly.Code != http.StatusOK { |
| 389 | t.Fatalf( |
| 390 | "global-only search status = %d, want %d; body=%s", |
| 391 | globalOnly.Code, |
| 392 | http.StatusOK, |
| 393 | globalOnly.Body.String(), |
| 394 | ) |
| 395 | } |
nothing calls this directly
no test coverage detected