From 7b93c37d365bc2a82fcf80de7313e2385634d08b Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 09:25:39 -0500 Subject: [PATCH 1/2] fix(calendar): truncate the series when updating future instances by ID calendar update --scope future resolves an instance ID to its series, but then truncated the recurrence of plan.EventID, the ID the user passed. With an instance ID from calendar events or calendar search, both PATCHes went to the instance and the original series kept every later occurrence. Return the whole scope resolution from applyUpdateScope and truncate ParentEventID, as calendar delete --scope future does. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 + internal/cmd/calendar_edit.go | 14 +-- internal/cmd/calendar_edit_scope_test.go | 11 ++- .../calendar_update_future_instance_test.go | 90 +++++++++++++++++++ 4 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 internal/cmd/calendar_update_future_instance_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..1270db5d0 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. — 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")) +} From bdca5656c4dac1e903449c0ca443cc8900a063be Mon Sep 17 00:00:00 2001 From: Bobby Bones <159389674+saariuslystoned@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:01:26 -0500 Subject: [PATCH 2/2] docs(changelog): reference #1317 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1270db5d0..86b2567ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 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. — thanks @saariuslystoned. +- 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