From 5d301089851199059af8b23b9ebcd90bc49b4c8f Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Thu, 5 Nov 2026 14:39:20 -0800 Subject: [PATCH 1/2] fix(sites): keep requested false bools in sites get JSON Sites get encoded the Drive file without ForceSendFields. Boolean fields tagged omitempty dropped starred and hasThumbnail when false, and a custom mask dropped trashed the same way. Drive get already calls forceRequestedDriveFileBools before it writes JSON. The regression covers an unstarred site with no thumbnail and a custom mask that requests trashed. Signed-off-by: Sebastien Tardif --- CHANGELOG.md | 2 + internal/cmd/sites.go | 1 + internal/cmd/sites_test.go | 89 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 861521fad..7d1e09821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.48.1 - Unreleased +- Sites: preserve requested false booleans in `sites get` JSON. The default mask keeps `starred` and `hasThumbnail` when they are false, and a custom mask that names `trashed` keeps `trashed` when it is false. + ## 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/sites.go b/internal/cmd/sites.go index a271f1a41..fd696847c 100644 --- a/internal/cmd/sites.go +++ b/internal/cmd/sites.go @@ -129,6 +129,7 @@ func (c *SitesGetCmd) Run(ctx context.Context, flags *RootFlags) error { } if outfmt.IsJSON(ctx) { + forceRequestedDriveFileBools(f, mask) return outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{"site": f}) } diff --git a/internal/cmd/sites_test.go b/internal/cmd/sites_test.go index bc4cf047b..24ebce24e 100644 --- a/internal/cmd/sites_test.go +++ b/internal/cmd/sites_test.go @@ -181,3 +181,92 @@ func TestSitesGetRejectsNonSite(t *testing.T) { t.Fatalf("expected url not-site error, got %v", err) } } + +// TestSitesGet_JSONKeepsRequestedFalseBools proves sites get JSON keeps +// requested boolean fields when they are false. drive.File tags them +// omitempty, so starred and hasThumbnail disappear unless ForceSendFields +// is set. Drive get already does that; sites get must too. +func TestSitesGet_JSONKeepsRequestedFalseBools(t *testing.T) { + cases := []struct { + name string + args []string + body map[string]any + want map[string]bool + notWant []string + }{ + { + name: "default fields", + args: []string{"site1"}, + body: map[string]any{ + "id": "site1", + "name": "Team Site", + "mimeType": driveMimeGoogleSite, + "starred": false, + "hasThumbnail": false, + "trashed": false, + }, + want: map[string]bool{"starred": false, "hasThumbnail": false}, + notWant: []string{"trashed"}, + }, + { + name: "custom trashed mask", + args: []string{"site1", "--fields", "id,name,trashed"}, + body: map[string]any{ + "id": "site1", + "name": "Team Site", + "mimeType": driveMimeGoogleSite, + "starred": false, + "hasThumbnail": false, + "trashed": false, + }, + want: map[string]bool{"trashed": false}, + notWant: []string{"starred", "hasThumbnail"}, + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + svc, closeSrv := newDriveTestService(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !strings.Contains(r.URL.Path, "/files/site1") { + http.NotFound(w, r) + return + } + + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(tc.body) + })) + defer closeSrv() + + var stdout bytes.Buffer + ctx := withSitesDriveTestService(newCmdRuntimeJSONOutputContext(t, &stdout, io.Discard), svc) + flags := &RootFlags{Account: "a@b.com"} + + if err := runKong(t, &SitesGetCmd{}, tc.args, ctx, flags); err != nil { + t.Fatalf("run: %v", err) + } + + var envelope struct { + Site map[string]any `json:"site"` + } + if err := json.Unmarshal(stdout.Bytes(), &envelope); err != nil { + t.Fatalf("invalid JSON: %v\nraw: %s", err, stdout.String()) + } + + for key, want := range tc.want { + got, ok := envelope.Site[key] + if !ok { + t.Fatalf("missing %q in output: %s", key, stdout.String()) + } + + if got != want { + t.Fatalf("%q = %v, want %v", key, got, want) + } + } + + for _, key := range tc.notWant { + if _, ok := envelope.Site[key]; ok { + t.Fatalf("unexpected %q in output: %s", key, stdout.String()) + } + } + }) + } +} From 4376d004fd5f12f24951aee000b8909a31ced7f5 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Thu, 5 Nov 2026 15:00:11 -0800 Subject: [PATCH 2/2] docs: credit the sites get changelog entry AGENTS.md requires a pull request reference and contributor thanks on a user-visible Unreleased change. The sites get line had neither. Signed-off-by: Sebastien Tardif --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d1e09821..ee0de2f39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.48.1 - Unreleased -- Sites: preserve requested false booleans in `sites get` JSON. The default mask keeps `starred` and `hasThumbnail` when they are false, and a custom mask that names `trashed` keeps `trashed` when it is false. +- Sites: preserve requested false booleans in `sites get` JSON. The default mask keeps `starred` and `hasThumbnail` when they are false, and a custom mask that names `trashed` keeps `trashed` when it is false. (#1308) — thanks @SebTardif. ## 0.48.0 - 2026-11-05