diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..86b2567ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- Calendar: make `calendar update --scope future` end the original series when given an instance ID, such as one from `calendar events` or `calendar search`, as `calendar delete --scope future` already does. It previously sent the series truncation to the instance itself and exited 0, so the original series kept every later occurrence. (#1317) — thanks @saariuslystoned. + ## 0.48.0 - 2026-11-05 **Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates. diff --git a/internal/cmd/calendar_edit.go b/internal/cmd/calendar_edit.go index 38dcb3a5e..c83463790 100644 --- a/internal/cmd/calendar_edit.go +++ b/internal/cmd/calendar_edit.go @@ -399,10 +399,11 @@ func (c *CalendarUpdateCmd) Run(ctx context.Context, kctx *kong.Context, flags * } } - targetEventID, parentRecurrence, err := applyUpdateScope(ctx, mutation.svc, mutation.calendarID, plan.EventID, plan.Scope, plan.OriginalStartTime, patch) + scoped, err := applyUpdateScope(ctx, mutation.svc, mutation.calendarID, plan.EventID, plan.Scope, plan.OriginalStartTime, patch) if err != nil { return err } + targetEventID := scoped.TargetEventID if patch.ConferenceData != nil && !fields.RegenerateMeet && !fields.zoomMutation() { existing, getErr := mutation.svc.Events.Get(mutation.calendarID, targetEventID).Context(ctx).Do() if getErr != nil { @@ -432,7 +433,7 @@ func (c *CalendarUpdateCmd) Run(ctx context.Context, kctx *kong.Context, flags * return err } if plan.Scope == scopeFuture { - if err := truncateParentRecurrence(ctx, mutation.svc, mutation.calendarID, plan.EventID, parentRecurrence, plan.OriginalStartTime, plan.SendUpdates); err != nil { + if err := truncateParentRecurrence(ctx, mutation.svc, mutation.calendarID, scoped.ParentEventID, scoped.ParentRecurrence, plan.OriginalStartTime, plan.SendUpdates); err != nil { return err } } @@ -545,10 +546,13 @@ func (c *CalendarUpdateCmd) prepareZoomConferencePatch( return patch, changed, nil } -func applyUpdateScope(ctx context.Context, svc *calendar.Service, calendarID, eventID, scope, originalStartTime string, patch *calendar.Event) (string, []string, error) { +// applyUpdateScope resolves which event a scoped update patches and, for +// scope=future, which series it truncates. eventID may be a series ID or an +// instance ID from a listing; ParentEventID is the series either way. +func applyUpdateScope(ctx context.Context, svc *calendar.Service, calendarID, eventID, scope, originalStartTime string, patch *calendar.Event) (recurringScopeResolution, error) { resolution, err := resolveRecurringScopeResolution(ctx, svc, calendarID, eventID, scope, originalStartTime) if err != nil { - return "", nil, err + return recurringScopeResolution{}, err } if scope == scopeFuture { @@ -567,7 +571,7 @@ func applyUpdateScope(ctx context.Context, svc *calendar.Service, calendarID, ev } } - return resolution.TargetEventID, resolution.ParentRecurrence, nil + return resolution, nil } func truncateParentRecurrence(ctx context.Context, svc *calendar.Service, calendarID, eventID string, parentRecurrence []string, originalStartTime, sendUpdates string) error { diff --git a/internal/cmd/calendar_edit_scope_test.go b/internal/cmd/calendar_edit_scope_test.go index a0b3ca37d..08b176bed 100644 --- a/internal/cmd/calendar_edit_scope_test.go +++ b/internal/cmd/calendar_edit_scope_test.go @@ -63,7 +63,8 @@ func TestApplyUpdateScopeFuture_UsesParentRecurrence(t *testing.T) { } patch := &calendar.Event{Summary: "updated"} - targetID, parentRecurrence, err := applyUpdateScope(context.Background(), svc, "cal", "ev", scopeFuture, originalStart, patch) + scoped, err := applyUpdateScope(context.Background(), svc, "cal", "ev", scopeFuture, originalStart, patch) + targetID, parentRecurrence := scoped.TargetEventID, scoped.ParentRecurrence if err != nil { t.Fatalf("applyUpdateScope: %v", err) } @@ -109,7 +110,7 @@ func TestApplyUpdateScopeFuture_NonRecurring(t *testing.T) { } patch := &calendar.Event{Summary: "updated"} - if _, _, err := applyUpdateScope(context.Background(), svc, "cal", "ev", scopeFuture, "2025-01-02T10:00:00Z", patch); err == nil { + if _, err := applyUpdateScope(context.Background(), svc, "cal", "ev", scopeFuture, "2025-01-02T10:00:00Z", patch); err == nil { t.Fatalf("expected error for non-recurring event") } } @@ -160,7 +161,11 @@ func TestApplyUpdateScopeFuture_RecurringInstanceID(t *testing.T) { } patch := &calendar.Event{Summary: "updated"} - targetID, parentRecurrence, err := applyUpdateScope(context.Background(), svc, "cal", "ev_instance", scopeFuture, originalStart, patch) + scoped, err := applyUpdateScope(context.Background(), svc, "cal", "ev_instance", scopeFuture, originalStart, patch) + targetID, parentRecurrence := scoped.TargetEventID, scoped.ParentRecurrence + if scoped.ParentEventID != "ev_master" { + t.Fatalf("ParentEventID = %q, want ev_master", scoped.ParentEventID) + } if err != nil { t.Fatalf("applyUpdateScope: %v", err) } diff --git a/internal/cmd/calendar_update_future_instance_test.go b/internal/cmd/calendar_update_future_instance_test.go new file mode 100644 index 000000000..64b0ac0fb --- /dev/null +++ b/internal/cmd/calendar_update_future_instance_test.go @@ -0,0 +1,90 @@ +package cmd + +import ( + "encoding/json" + "io" + "net/http" + "net/http/httptest" + "strings" + "testing" +) + +type recordedPatch struct { + eventID string + recurrence []string +} + +// runCalendarUpdateFuture serves a daily series "ser1" whose 2025-01-02 instance +// is "ser1_20250102T100000Z", runs calendar update --scope future with eventID, +// and records every PATCH. +func runCalendarUpdateFuture(t *testing.T, eventID string) []recordedPatch { + t.Helper() + const instanceID = "ser1_20250102T100000Z" + var patches []recordedPatch + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + path := strings.TrimPrefix(r.URL.Path, "/calendar/v3") + w.Header().Set("Content-Type", "application/json") + switch { + case r.Method == http.MethodGet && path == "/calendars/cal/events/"+instanceID: + _, _ = io.WriteString(w, `{"id":"`+instanceID+`","recurringEventId":"ser1"}`) + case r.Method == http.MethodGet && path == "/calendars/cal/events/ser1": + _, _ = io.WriteString(w, `{"id":"ser1","recurrence":["RRULE:FREQ=DAILY"],"start":{"dateTime":"2025-01-01T10:00:00Z","timeZone":"UTC"},"end":{"dateTime":"2025-01-01T10:30:00Z","timeZone":"UTC"}}`) + case r.Method == http.MethodGet && path == "/calendars/cal/events/ser1/instances": + _, _ = io.WriteString(w, `{"items":[{"id":"`+instanceID+`","originalStartTime":{"dateTime":"2025-01-02T10:00:00Z"}}]}`) + case r.Method == http.MethodPatch && strings.HasPrefix(path, "/calendars/cal/events/"): + var body struct { + Recurrence []string `json:"recurrence"` + } + _ = json.NewDecoder(r.Body).Decode(&body) + id := strings.TrimPrefix(path, "/calendars/cal/events/") + patches = append(patches, recordedPatch{eventID: id, recurrence: body.Recurrence}) + _, _ = io.WriteString(w, `{"id":"`+id+`","summary":"Renamed"}`) + case r.Method == http.MethodGet && path == "/users/me/calendarList": + _, _ = io.WriteString(w, `{"items":[{"id":"cal","summary":"cal","timeZone":"UTC"}]}`) + case r.Method == http.MethodGet && path == "/calendars/cal": + _, _ = io.WriteString(w, `{"id":"cal","timeZone":"UTC"}`) + default: + t.Logf("unexpected %s %s", r.Method, r.URL.String()) + http.NotFound(w, r) + } + })) + t.Cleanup(srv.Close) + + ctx := withCalendarTestService(newCmdRuntimeJSONOutputContext(t, io.Discard, io.Discard), newCalendarServiceFromServer(t, srv)) + if err := runKong(t, &CalendarUpdateCmd{}, []string{ + "cal", eventID, + "--scope", "future", + "--original-start", "2025-01-02T10:00:00Z", + "--summary", "Renamed", + }, ctx, &RootFlags{Account: "a@b.com"}); err != nil { + t.Fatalf("update %s: %v", eventID, err) + } + return patches +} + +func assertFutureScopePatches(t *testing.T, patches []recordedPatch) { + t.Helper() + if len(patches) != 2 { + t.Fatalf("PATCHes = %#v, want instance then series", patches) + } + if patches[0].eventID != "ser1_20250102T100000Z" { + t.Fatalf("first PATCH went to %q, want the instance", patches[0].eventID) + } + if patches[1].eventID != "ser1" { + t.Fatalf("series truncation PATCH went to %q, want ser1", patches[1].eventID) + } + if len(patches[1].recurrence) != 1 || !strings.Contains(patches[1].recurrence[0], "UNTIL=20250102T095959Z") { + t.Fatalf("series recurrence = %q, want UNTIL just before the instance", patches[1].recurrence) + } +} + +func TestCalendarUpdateCmd_ScopeFutureFromSeriesID(t *testing.T) { + assertFutureScopePatches(t, runCalendarUpdateFuture(t, "ser1")) +} + +// calendar events and calendar search list expanded instances, so the ID a +// user has is usually the instance ID. --scope future must still end the old +// series, as calendar delete --scope future already does. +func TestCalendarUpdateCmd_ScopeFutureFromInstanceID(t *testing.T) { + assertFutureScopePatches(t, runCalendarUpdateFuture(t, "ser1_20250102T100000Z")) +}