MCPcopy Create free account
hub / github.com/compozy/agh / TestHealthIncludesMemoryStats

Function TestHealthIncludesMemoryStats

internal/api/httpapi/memory_test.go:489–543  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

487}
488
489func TestHealthIncludesMemoryStats(t *testing.T) {
490 t.Parallel()
491
492 store, workspace := newTestMemoryStore(t)
493 mustWriteMemory(t, store, memcontract.ScopeGlobal, "", "health-global.md", memcontract.TypeUser, "global")
494 mustWriteMemory(
495 t,
496 store,
497 memcontract.ScopeWorkspace,
498 workspace,
499 "health-workspace.md",
500 memcontract.TypeProject,
501 "workspace",
502 )
503
504 last := time.Date(2026, 4, 4, 3, 30, 0, 0, time.UTC)
505 trigger := &stubDreamTrigger{enabled: true, last: last}
506 manager := stubSessionManager{
507 ListAllFn: func(context.Context) ([]*session.Info, error) {
508 info := newSessionInfo("sess-1")
509 info.Workspace = workspace
510 return []*session.Info{info}, nil
511 },
512 }
513 observer := stubObserver{
514 HealthFn: func(context.Context) (observe.Health, error) {
515 return observe.Health{Status: "ok", ActiveSessions: 1}, nil
516 },
517 }
518
519 handlers := newTestMemoryHandlers(t, manager, observer, store, trigger)
520 engine := newTestRouter(t, handlers)
521
522 resp := performRequest(t, engine, http.MethodGet, "/api/status", nil)
523 if resp.Code != http.StatusOK {
524 t.Fatalf("status = %d, want %d; body=%s", resp.Code, http.StatusOK, resp.Body.String())
525 }
526
527 var payload struct {
528 Memory memoryHealthPayload `json:"memory"`
529 }
530 decodeJSONResponse(t, resp, &payload)
531 if payload.Memory.GlobalFiles != 1 || payload.Memory.WorkspaceFiles != 1 || !payload.Memory.DreamEnabled {
532 t.Fatalf("memory health = %#v", payload.Memory)
533 }
534 if payload.Memory.LastConsolidation == nil || !payload.Memory.LastConsolidation.Equal(last) {
535 t.Fatalf("last consolidation = %#v, want %s", payload.Memory.LastConsolidation, last)
536 }
537 if !payload.Memory.Enabled || payload.Memory.IndexedFiles != 2 || payload.Memory.OrphanedFiles != 0 {
538 t.Fatalf("memory health catalog stats = %#v, want enabled+indexed stats", payload.Memory)
539 }
540 if payload.Memory.LastReindex == nil {
541 t.Fatalf("last reindex = %#v, want non-nil", payload.Memory.LastReindex)
542 }
543}
544
545func TestMemoryHelpersResolveLocationAndScope(t *testing.T) {
546 t.Parallel()

Callers

nothing calls this directly

Calls 8

newTestMemoryStoreFunction · 0.70
mustWriteMemoryFunction · 0.70
newSessionInfoFunction · 0.70
newTestMemoryHandlersFunction · 0.70
newTestRouterFunction · 0.70
performRequestFunction · 0.70
decodeJSONResponseFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected