Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
86 lines
2.9 KiB
Go
86 lines
2.9 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"pageswiki/internal/store"
|
|
)
|
|
|
|
func TestTaskFocusCrossDomainRecovery(t *testing.T) {
|
|
s, _, domain, actor := taskFixture(t)
|
|
ctx := context.Background()
|
|
now := time.Now()
|
|
d, err := s.store.GetDomainByUUID(domain)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = s.store.CreateDomain(d.CampusUUID, "focus-other", "Other", "focus-other", "local", "", "", true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
domains, err := s.store.ListDomains()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
other := ""
|
|
for _, d := range domains {
|
|
if d.Name == "focus-other" {
|
|
other = d.UUID
|
|
}
|
|
}
|
|
if other == "" {
|
|
t.Fatal("missing domain")
|
|
}
|
|
if _, err = s.store.DB.Exec(`INSERT OR IGNORE INTO domain_memberships(uuid,domain_uuid,principal_uuid,state,created_at_ms) VALUES(?,?,?,'active',0)`, uuid.NewString(), other, actor); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f, err := s.store.ChangeTaskFocus(ctx, domain, actor, "start", store.TaskFocus{UUID: uuid.NewString(), Phase: "focus", DurationMS: 60000}, 0, now)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
f, err = s.store.ChangeTaskFocus(ctx, domain, actor, "pause", f, f.Version, now.Add(time.Second))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
draft := store.TaskFocus{UUID: uuid.NewString(), Phase: "focus", DurationMS: 60000}
|
|
if _, err = s.store.ChangeTaskFocus(ctx, other, actor, "start", draft, 0, now); !errors.Is(err, store.ErrTaskConflict) {
|
|
t.Fatal("multiple active domains", err)
|
|
}
|
|
if _, err = s.store.DB.Exec(`UPDATE domain_memberships SET state='suspended' WHERE domain_uuid=? AND principal_uuid=?`, domain, actor); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err = s.store.ChangeTaskFocus(ctx, other, actor, "start", draft, 0, now.Add(2*time.Second)); err != nil {
|
|
t.Fatal("stranded timer blocked start", err)
|
|
}
|
|
var state, action string
|
|
s.store.DB.QueryRow(`SELECT state FROM organizer_focus WHERE uuid=?`, f.UUID).Scan(&state)
|
|
s.store.DB.QueryRow(`SELECT action FROM organizer_focus_changes WHERE session_uuid=? ORDER BY version DESC LIMIT 1`, f.UUID).Scan(&action)
|
|
if state != "cancelled" || action != "revoked" {
|
|
t.Fatal(state, action)
|
|
}
|
|
latest, err := s.store.LatestTaskFocus(ctx, other, actor)
|
|
if err != nil || latest.UUID != draft.UUID {
|
|
t.Fatal(latest, err)
|
|
}
|
|
}
|
|
|
|
func TestTaskFocusSchedulePreservesAdminSettings(t *testing.T) {
|
|
s, _, _, _ := taskFixture(t)
|
|
if err := s.store.EnsureTaskFocusEvent(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := s.store.DB.Exec(`UPDATE event_definitions SET enabled=0,interval_seconds=120 WHERE uuid='builtin.task.focus'`); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.store.EnsureTaskFocusEvent(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var enabled, interval int
|
|
if err := s.store.DB.QueryRow(`SELECT enabled,interval_seconds FROM event_definitions WHERE uuid='builtin.task.focus'`).Scan(&enabled, &interval); err != nil || enabled != 0 || interval != 120 {
|
|
t.Fatal(enabled, interval, err)
|
|
}
|
|
}
|