Skip to content

feat(users): add reset and delete safeguards#10

Open
JSONbored wants to merge 1 commit into
we-promise:mainfrom
JSONbored:codex/feat-cli-users-admin
Open

feat(users): add reset and delete safeguards#10
JSONbored wants to merge 1 commit into
we-promise:mainfrom
JSONbored:codex/feat-cli-users-admin

Conversation

@JSONbored
Copy link
Copy Markdown

@JSONbored JSONbored commented May 6, 2026

Summary

  • Add destructive user/account maintenance commands with explicit apply safeguards.

What changed

  • Adds users reset as dry-run-first.
  • Adds users reset status.
  • Adds users delete-me as dry-run-first.
  • Requires explicit --apply for destructive calls.
  • Adds focused command-shape tests and README examples.

Why

  • Sure exposes account reset/delete surfaces that need clear CLI support without making destructive calls easy to run accidentally.

Validation

  • go test -count=1 ./...
  • go test -race ./...
  • go vet ./...
  • tools/validate-samples.sh
  • git diff --check
  • gitleaks detect --no-git --redact --source . --verbose

Notes

  • Draft for review. No live destructive smoke test was run.

Summary by CodeRabbit

  • New Features

    • Added user account management commands: users reset, users delete-me, and users reset status. Commands default to dry-run mode for safety; use the --apply flag to execute operations.
  • Documentation

    • Updated README with new account reset and deletion usage examples.
  • Tests

    • Added test coverage for the new user account commands.
  • Chores

    • Updated .gitignore to properly exclude binary files.

Add dry-run-first user reset and delete-me commands with an explicit --apply gate, plus reset status reads and focused command-shape tests.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a new users subcommand to the CLI enabling account reset and deletion operations. The feature includes command registration, implementation with dry-run support via --apply flag, comprehensive tests, and documentation updates.

Changes

User Management Commands

Layer / File(s) Summary
CLI Command Registration
cmd/sure-cli/root/root.go
The users command is registered in New() via newUsersCmd() alongside existing commands.
Users Command Implementation
cmd/sure-cli/root/users_cmd.go
New module with reset, delete-me, and reset status subcommands. Both default to dry-run mode; --apply flag executes API calls to /api/v1/users/reset (DELETE) and /api/v1/users/me (DELETE). Helper functions printUsersGet, printUsersDelete, and printUsersDryRun handle API requests, error handling, and output formatting.
Command Tests
cmd/sure-cli/root/users_cmd_test.go
Two tests validate command structure: TestUsersResetCommandShape checks the reset command and its subcommands exist with the --apply flag; TestUsersCommandRegistered confirms all three command paths register in the root command tree.
Documentation
README.md
New "Account reset and deletion" section documents usage of sure-cli users reset, sure-cli users reset --apply, sure-cli users reset status, and sure-cli users delete-me.
Build Configuration
.gitignore
Updated to ignore the compiled binary at /sure-cli (repository root) instead of the unscoped pattern.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hops with glee, a new command takes flight,
Reset and delete, with --apply just right,
Dry-run first, then execute with care,
User accounts managed with binary flair!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(users): add reset and delete safeguards' directly corresponds to the main change: adding user account reset and delete functionality with dry-run safeguards (--apply flag). It is clear, specific, and accurately summarizes the primary feature addition.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@JSONbored JSONbored marked this pull request as ready for review May 7, 2026 06:29
@superagent-security superagent-security Bot added contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis. labels May 7, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
cmd/sure-cli/root/users_cmd_test.go (1)

21-29: ⚡ Quick win

Add an explicit assertion for delete-me --apply flag.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 48830d1 and bc7347c.

📒 Files selected for processing (5)
  • .gitignore
  • README.md
  • cmd/sure-cli/root/root.go
  • cmd/sure-cli/root/users_cmd.go
  • cmd/sure-cli/root/users_cmd_test.go

Comment on lines +13 to +47
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)
},
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 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.go

Repository: we-promise/sure-cli

Length of output: 131


🏁 Script executed:

cat -n cmd/sure-cli/root/users_cmd.go

Repository: 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.

Suggested change
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.

Comment thread README.md
Comment on lines +124 to +129
# Account reset and deletion
sure-cli users reset
sure-cli users reset --apply
sure-cli users reset status
sure-cli users delete-me

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants