Print an empty unlocker or vault list as [] in JSON #178

Merged
clawbot merged 1 commits from fix/148-empty-list-json into next 2026-10-15 04:48:47 +02:00
Collaborator

Fixes #148.

secret unlocker list --json printed "unlockers": null for a vault with no unlockers, as after its last unlocker is removed. secret vault list --json printed "vaults": null when vaults.d held no vaults. Both lists were nil slices, and encoding/json writes a nil slice as null. Each is now made as an empty slice before it is filled, so an empty list prints as [].

The vault fix is in vault.ListVaults, which shell completion, secret move and secret vault remove also call. They only range over the result, check its length or look a name up in it, so an empty slice in place of nil changes nothing for them.

Two regression tests, one per command, list an empty vault's unlockers and an empty vaults.d in JSON form and expect [].

Model: opus-5-5

Fixes https://git.eeqj.de/sneak/secret/issues/148. `secret unlocker list --json` printed `"unlockers": null` for a vault with no unlockers, as after its last unlocker is removed. `secret vault list --json` printed `"vaults": null` when `vaults.d` held no vaults. Both lists were nil slices, and `encoding/json` writes a nil slice as `null`. Each is now made as an empty slice before it is filled, so an empty list prints as `[]`. The vault fix is in `vault.ListVaults`, which shell completion, `secret move` and `secret vault remove` also call. They only range over the result, check its length or look a name up in it, so an empty slice in place of nil changes nothing for them. Two regression tests, one per command, list an empty vault's unlockers and an empty `vaults.d` in JSON form and expect `[]`. Model: opus-5-5
clawbot added the needs-review label 2026-10-15 01:07:17 +02:00
clawbot self-assigned this 2026-10-15 01:07:17 +02:00
clawbot force-pushed fix/148-empty-list-json from 8949a61f5c to b75d9342eb 2026-10-15 01:35:08 +02:00 Compare
Author
Collaborator

internal/cli/unlockers_list_test.go, lines 3 to 12: the opening comment says the tests it lists cover secret unlocker list when an unlocker's metadata cannot be read or used, and the PR adds TestUnlockersListEmptyJSON to that list, though that test is about a vault with no unlockers. Acceptable: an opening sentence that covers every test listed under it (for example "Tests for secret unlocker list:"), or the new test kept out of that list.

Model: opus-5-5

`internal/cli/unlockers_list_test.go`, lines 3 to 12: the opening comment says the tests it lists cover `secret unlocker list` when an unlocker's metadata cannot be read or used, and the PR adds `TestUnlockersListEmptyJSON` to that list, though that test is about a vault with no unlockers. Acceptable: an opening sentence that covers every test listed under it (for example "Tests for `secret unlocker list`:"), or the new test kept out of that list. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-15 02:20:10 +02:00
clawbot force-pushed fix/148-empty-list-json from b75d9342eb to 7787609d2e 2026-10-15 02:54:34 +02:00 Compare
Author
Collaborator

Opening comment of internal/cli/unlockers_list_test.go: its first sentence now reads "Tests for secret unlocker list:", which covers all three tests listed under it.

Model: opus-5-5

Opening comment of `internal/cli/unlockers_list_test.go`: its first sentence now reads "Tests for `secret unlocker list`:", which covers all three tests listed under it. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-15 02:54:39 +02:00
clawbot force-pushed fix/148-empty-list-json from 7787609d2e to a1938ba137 2026-10-15 03:53:07 +02:00 Compare
clawbot added 1 commit 2026-10-15 04:17:41 +02:00
`secret unlocker list --json` printed "unlockers": null for a vault with
no unlockers, and `secret vault list --json` printed "vaults": null when
vaults.d held no vaults. Both lists were nil slices, which encoding/json
writes as null. Each is now made as an empty slice before it is filled,
so an empty list prints as [].

vault.ListVaults therefore returns an empty slice instead of nil for an
empty vaults.d; its other callers only range over the result or check
its length.

Model: opus-5-5
clawbot force-pushed fix/148-empty-list-json from a1938ba137 to 8d5ed1ba4c 2026-10-15 04:17:41 +02:00 Compare
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit 0ffffd5e3f into next 2026-10-15 04:48:47 +02:00
clawbot deleted branch fix/148-empty-list-json 2026-10-15 04:48:47 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/secret#178