Files
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
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.
2026-09-27 14:44:43 +09:00

48 lines
1.5 KiB
Go

package calendar
import (
"context"
"errors"
"strings"
"testing"
"github.com/google/uuid"
)
func TestTaskBlockGuardBeforeSnapshotAccess(t *testing.T) {
for _, mode := range []string{"external", "public", "shared", "other-owner"} {
t.Run(mode, func(t *testing.T) {
r, domain, actor, c := fixture(t)
dir, _ := r.dir(domain, c.ID)
// A deliberately absent snapshot detects ANY attempted refresh.
c.Months["2026-09"] = strings.Repeat("a", 64)
switch mode {
case "external":
c.Source = &Source{Kind: "ics", URL: "https://example.invalid/private.ics"}
case "public":
c.Public = true
case "shared":
c.Members = map[string]string{uuid.NewString(): "read"}
case "other-owner":
actor = "someone-else"
}
if err := saveMeta(dir, &c); err != nil {
t.Fatal(err)
}
_, _, err := r.TaskBlock(context.Background(), domain, c.ID, actor, "fake", nil)
if !errors.Is(err, ErrForbidden) && !errors.Is(err, ErrMissing) {
t.Fatalf("snapshot accessed: %v", err)
}
called := false
err = r.ReadPersonalLocalIndex(context.Background(), domain, c.ID, actor, func(Calendar) error { called = true; return nil })
if called || (!errors.Is(err, ErrForbidden) && !errors.Is(err, ErrMissing)) {
t.Fatalf("range projection accessed blocked snapshot: %v", err)
}
var n int
if err := r.DB.QueryRow(`SELECT count(*) FROM calendar_index_state`).Scan(&n); err != nil || n != 0 {
t.Fatalf("cache populated %d %v", n, err)
}
})
}
}