feat(users): add reset and delete safeguards#10
Conversation
Add dry-run-first user reset and delete-me commands with an explicit --apply gate, plus reset status reads and focused command-shape tests.
📝 WalkthroughWalkthroughThis PR adds a new ChangesUser Management Commands
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
cmd/sure-cli/root/users_cmd_test.go (1)
21-29: ⚡ Quick winAdd an explicit assertion for
delete-me --applyflag.This test confirms command discovery, but not the safeguard flag on
delete-me. Adding that check would better protect the destructive-path contract.Proposed test addition
func TestUsersCommandRegistered(t *testing.T) { cmd := New() for _, args := range [][]string{ {"users", "reset"}, {"users", "reset", "status"}, {"users", "delete-me"}, } { if _, _, err := cmd.Find(args); err != nil { t.Fatalf("expected command %v: %v", args, err) } } + + deleteMe, _, err := cmd.Find([]string{"users", "delete-me"}) + if err != nil { + t.Fatalf("find users delete-me command: %v", err) + } + if deleteMe.Flags().Lookup("apply") == nil { + t.Fatal("expected delete-me --apply flag") + } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/sure-cli/root/users_cmd_test.go` around lines 21 - 29, The test currently only verifies command discovery but not that the destructive "delete-me" command requires the safeguard flag; update users_cmd_test.go to explicitly assert the presence and type of the "apply" flag on the "delete-me" command by locating the command via cmd.Find (e.g., call cmd.Find with {"users","delete-me"} to get the *cobra.Command), then verify command.Flags().Lookup("apply") is not nil and that its Value/Type is the expected boolean flag (or that requiring "--apply" behavior is enforced), so the test fails if the "delete-me" command lacks the "--apply" safeguard.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/sure-cli/root/users_cmd.go`:
- Around line 13-47: The reset, its status subcommand, and delete-me cobra
commands accept unexpected positional args; update each command definition (the
reset cobra.Command, the inline status subcommand passed to reset.AddCommand,
and the deleteMe cobra.Command) to include Args: cobra.NoArgs so Cobra will
reject any positional arguments for these destructive operations and prevent
accidental execution with mistyped inputs.
In `@README.md`:
- Around line 124-129: Add the explicit execute form for the delete command by
appending the example "sure-cli users delete-me --apply" alongside the other
examples under the "Account reset and deletion" section so the
explicit-confirmation flow mirrors the reset command; update the block that
currently lists "sure-cli users delete-me" to include the dry-run and the
execute variant ("sure-cli users delete-me --apply") so readers see both forms.
---
Nitpick comments:
In `@cmd/sure-cli/root/users_cmd_test.go`:
- Around line 21-29: The test currently only verifies command discovery but not
that the destructive "delete-me" command requires the safeguard flag; update
users_cmd_test.go to explicitly assert the presence and type of the "apply" flag
on the "delete-me" command by locating the command via cmd.Find (e.g., call
cmd.Find with {"users","delete-me"} to get the *cobra.Command), then verify
command.Flags().Lookup("apply") is not nil and that its Value/Type is the
expected boolean flag (or that requiring "--apply" behavior is enforced), so the
test fails if the "delete-me" command lacks the "--apply" safeguard.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 70773dc3-27db-490b-801c-652db095b5f0
📒 Files selected for processing (5)
.gitignoreREADME.mdcmd/sure-cli/root/root.gocmd/sure-cli/root/users_cmd.gocmd/sure-cli/root/users_cmd_test.go
| reset := &cobra.Command{ | ||
| Use: "reset", | ||
| Short: "Queue account reset (default dry-run; use --apply to execute)", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| path := "/api/v1/users/reset" | ||
| if !applyReset { | ||
| printUsersDryRun("DELETE", path, nil) | ||
| return | ||
| } | ||
| printUsersDelete(path) | ||
| }, | ||
| } | ||
| reset.Flags().BoolVar(&applyReset, "apply", false, "execute the reset (otherwise dry-run)") | ||
| reset.AddCommand(&cobra.Command{ | ||
| Use: "status", | ||
| Short: "Show reset status", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| printUsersGet("/api/v1/users/reset/status") | ||
| }, | ||
| }) | ||
| cmd.AddCommand(reset) | ||
|
|
||
| var applyDelete bool | ||
| deleteMe := &cobra.Command{ | ||
| Use: "delete-me", | ||
| Short: "Delete current user account (default dry-run; use --apply to execute)", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| path := "/api/v1/users/me" | ||
| if !applyDelete { | ||
| printUsersDryRun("DELETE", path, nil) | ||
| return | ||
| } | ||
| printUsersDelete(path) | ||
| }, | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify users commands define strict no-arg validation.
rg -nP 'Use:\s+"(reset|status|delete-me)"|Args:\s*cobra\.NoArgs' cmd/sure-cli/root/users_cmd.goRepository: we-promise/sure-cli
Length of output: 131
🏁 Script executed:
cat -n cmd/sure-cli/root/users_cmd.goRepository: we-promise/sure-cli
Length of output: 3229
Add Args: cobra.NoArgs validators to destructive user commands.
The reset, status, and delete-me commands currently lack argument validators and silently accept unexpected positional arguments. For destructive operations, add Args: cobra.NoArgs to reject accidental mistyped commands.
Proposed fix
reset := &cobra.Command{
Use: "reset",
Short: "Queue account reset (default dry-run; use --apply to execute)",
+ Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
path := "/api/v1/users/reset"
if !applyReset {
printUsersDryRun("DELETE", path, nil)
return
}
printUsersDelete(path)
},
}
@@
reset.AddCommand(&cobra.Command{
Use: "status",
Short: "Show reset status",
+ Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
printUsersGet("/api/v1/users/reset/status")
},
})
@@
deleteMe := &cobra.Command{
Use: "delete-me",
Short: "Delete current user account (default dry-run; use --apply to execute)",
+ Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
path := "/api/v1/users/me"
if !applyDelete {
printUsersDryRun("DELETE", path, nil)
return
}
printUsersDelete(path)
},
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| reset := &cobra.Command{ | |
| Use: "reset", | |
| Short: "Queue account reset (default dry-run; use --apply to execute)", | |
| Run: func(cmd *cobra.Command, args []string) { | |
| path := "/api/v1/users/reset" | |
| if !applyReset { | |
| printUsersDryRun("DELETE", path, nil) | |
| return | |
| } | |
| printUsersDelete(path) | |
| }, | |
| } | |
| reset.Flags().BoolVar(&applyReset, "apply", false, "execute the reset (otherwise dry-run)") | |
| reset.AddCommand(&cobra.Command{ | |
| Use: "status", | |
| Short: "Show reset status", | |
| Run: func(cmd *cobra.Command, args []string) { | |
| printUsersGet("/api/v1/users/reset/status") | |
| }, | |
| }) | |
| cmd.AddCommand(reset) | |
| var applyDelete bool | |
| deleteMe := &cobra.Command{ | |
| Use: "delete-me", | |
| Short: "Delete current user account (default dry-run; use --apply to execute)", | |
| Run: func(cmd *cobra.Command, args []string) { | |
| path := "/api/v1/users/me" | |
| if !applyDelete { | |
| printUsersDryRun("DELETE", path, nil) | |
| return | |
| } | |
| printUsersDelete(path) | |
| }, | |
| } | |
| reset := &cobra.Command{ | |
| Use: "reset", | |
| Short: "Queue account reset (default dry-run; use --apply to execute)", | |
| Args: cobra.NoArgs, | |
| Run: func(cmd *cobra.Command, args []string) { | |
| path := "/api/v1/users/reset" | |
| if !applyReset { | |
| printUsersDryRun("DELETE", path, nil) | |
| return | |
| } | |
| printUsersDelete(path) | |
| }, | |
| } | |
| reset.Flags().BoolVar(&applyReset, "apply", false, "execute the reset (otherwise dry-run)") | |
| reset.AddCommand(&cobra.Command{ | |
| Use: "status", | |
| Short: "Show reset status", | |
| Args: cobra.NoArgs, | |
| Run: func(cmd *cobra.Command, args []string) { | |
| printUsersGet("/api/v1/users/reset/status") | |
| }, | |
| }) | |
| cmd.AddCommand(reset) | |
| var applyDelete bool | |
| deleteMe := &cobra.Command{ | |
| Use: "delete-me", | |
| Short: "Delete current user account (default dry-run; use --apply to execute)", | |
| Args: cobra.NoArgs, | |
| Run: func(cmd *cobra.Command, args []string) { | |
| path := "/api/v1/users/me" | |
| if !applyDelete { | |
| printUsersDryRun("DELETE", path, nil) | |
| return | |
| } | |
| printUsersDelete(path) | |
| }, | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/sure-cli/root/users_cmd.go` around lines 13 - 47, The reset, its status
subcommand, and delete-me cobra commands accept unexpected positional args;
update each command definition (the reset cobra.Command, the inline status
subcommand passed to reset.AddCommand, and the deleteMe cobra.Command) to
include Args: cobra.NoArgs so Cobra will reject any positional arguments for
these destructive operations and prevent accidental execution with mistyped
inputs.
| # Account reset and deletion | ||
| sure-cli users reset | ||
| sure-cli users reset --apply | ||
| sure-cli users reset status | ||
| sure-cli users delete-me | ||
|
|
There was a problem hiding this comment.
Document the execute form for users delete-me too.
Line 128 shows only dry-run. Add a sure-cli users delete-me --apply example to mirror reset and make the explicit-confirmation flow unambiguous.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@README.md` around lines 124 - 129, Add the explicit execute form for the
delete command by appending the example "sure-cli users delete-me --apply"
alongside the other examples under the "Account reset and deletion" section so
the explicit-confirmation flow mirrors the reset command; update the block that
currently lists "sure-cli users delete-me" to include the dry-run and the
execute variant ("sure-cli users delete-me --apply") so readers see both forms.
Summary
What changed
users resetas dry-run-first.users reset status.users delete-meas dry-run-first.--applyfor destructive calls.Why
Validation
go test -count=1 ./...go test -race ./...go vet ./...tools/validate-samples.shgit diff --checkgitleaks detect --no-git --redact --source . --verboseNotes
Summary by CodeRabbit
New Features
users reset,users delete-me, andusers reset status. Commands default to dry-run mode for safety; use the--applyflag to execute operations.Documentation
Tests
Chores
.gitignoreto properly exclude binary files.