package api import ( "droboticflow/internal/domain" "testing" "time" ) func TestWorkBufferDisplayCacheCopiesAndExpires(t *testing.T) { var cache workBufferDisplayCache now := time.Unix(1700000000, 0) item := domain.HumanItemRecord{OrganizationID: "org", ID: "item", RunID: "run", ProjectID: "project", WorkflowID: "workflow", LegacyTaskID: "task"} key := workBufferDisplayKey(item) cache.set(key, &domain.HumanTaskDisplayContext{ProjectName: "P", CaptureDirectories: []string{"A"}}, now) got := cache.get(key, now.Add(time.Minute)) if got == nil || got.ProjectName != "P" || len(got.CaptureDirectories) != 1 { t.Fatalf("cached display = %+v", got) } got.CaptureDirectories[0] = "mutated" if again := cache.get(key, now); again.CaptureDirectories[0] != "A" { t.Fatal("callers must not share the cached slice") } item.RunID = "other-run" if cache.get(workBufferDisplayKey(item), now) != nil { t.Fatal("a different run must not reuse the display") } if cache.get(key, now.Add(workBufferDisplayTTL+time.Second)) != nil { t.Fatal("display must expire") } }