Repository navigation
Conversation
After flag update, flag enable or flag disable succeeds, print the command
that puts the flag back, on stderr under the confirmation:
✓ Set max_items to 30 in environment Production (…)
Undo: flagsmith flag update max_items --value 25
It is worked out from the state read before the write. A new segment override
is undone with flag delete --segment. An explicit --project or --environment
is repeated so the command works from anywhere. No hint is printed when the
previous state can't be restated as a command (an unset value, re-weighted
variants) or when nothing changed.
Part of Flagsmith#65.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
5 issues found across 3 files
Confidence score: 3/5
- Copied undo commands in
undo.gocan target the default host or fail to resolve a project when the original command used explicit context flags. Preserve--api-urland--organisationin the undo command. - The
--identifierupdate path inflag_update.goreturns before printing an undo command, so successful identity changes cannot be reversed from the hint. Add undo generation to that path, including cleanup for newly created identities. flag_update.gocan print an undo hint for a no-op update, and that hint repeats the current value. Suppress it when the requested value matchestarget.Value.- The new test in
cmd_test.gocan pass without confirming the hint is on stdout, and it is missing the repository's Given/When/Then sections. Capture stdout and stderr separately and add those sections.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="internal/cmd/cmd_test.go">
<violation number="1" location="internal/cmd/cmd_test.go:8861">
P3: This assertion accepts the hint on stdout or before the confirmation because `run` combines both streams and `undoLine` searches the combined buffer. Capture stdout and stderr separately, then assert the hint is on stderr after the confirmation.</violation>
<violation number="2" location="internal/cmd/cmd_test.go:8879">
P3: Add the required Given/When/Then sections to this new test so it follows the repository's test structure.</violation>
</file>
<file name="internal/cmd/flag_update.go">
<violation number="1" location="internal/cmd/flag_update.go:298">
P2: Setting a value to its current value still prints an undo hint that repeats the current value, despite nothing changing. Suppress the hint when the requested value matches `target.Value`.</violation>
<violation number="2" location="internal/cmd/flag_update.go:298">
P2: Successful `--identifier` updates return before reaching this hook, so they still print no undo command. Add equivalent undo generation and printing to the identity update path, including deleting newly created identity overrides.</violation>
</file>
<file name="internal/cmd/undo.go">
<violation number="1" location="internal/cmd/undo.go:57">
P2: `scopeArgs` drops explicit `--api-url` and `--organisation`, so a copied undo can hit the default host or fail to resolve a named project across multiple organisations. Repeat those explicit context flags too.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
| } | ||
|
|
||
| // Worked out from the state before the write, printed once it succeeds. | ||
| undo, undoOK := undoFlagMutation(cmd, name, segmentID, target, meta.priority, m) |
There was a problem hiding this comment.
P2: Setting a value to its current value still prints an undo hint that repeats the current value, despite nothing changing. Suppress the hint when the requested value matches target.Value.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At internal/cmd/flag_update.go, line 298:
<comment>Setting a value to its current value still prints an undo hint that repeats the current value, despite nothing changing. Suppress the hint when the requested value matches `target.Value`.</comment>
<file context>
@@ -294,6 +294,9 @@ func applyFlagMutation(cmd *cobra.Command, name string, m flagMutation) error {
}
+ // Worked out from the state before the write, printed once it succeeds.
+ undo, undoOK := undoFlagMutation(cmd, name, segmentID, target, meta.priority, m)
+
resp, err := cred.client().UpdateFlag(cmd.Context(), env.APIKey, feature.ID, req)
</file context>
| } | ||
|
|
||
| // Worked out from the state before the write, printed once it succeeds. | ||
| undo, undoOK := undoFlagMutation(cmd, name, segmentID, target, meta.priority, m) |
There was a problem hiding this comment.
P2: Successful --identifier updates return before reaching this hook, so they still print no undo command. Add equivalent undo generation and printing to the identity update path, including deleting newly created identity overrides.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At internal/cmd/flag_update.go, line 298:
<comment>Successful `--identifier` updates return before reaching this hook, so they still print no undo command. Add equivalent undo generation and printing to the identity update path, including deleting newly created identity overrides.</comment>
<file context>
@@ -294,6 +294,9 @@ func applyFlagMutation(cmd *cobra.Command, name string, m flagMutation) error {
}
+ // Worked out from the state before the write, printed once it succeeds.
+ undo, undoOK := undoFlagMutation(cmd, name, segmentID, target, meta.priority, m)
+
resp, err := cred.client().UpdateFlag(cmd.Context(), env.APIKey, feature.ID, req)
</file context>
| // hits the same project, environment and override from any directory. | ||
| func scopeArgs(cmd *cobra.Command, segmentID int) []string { | ||
| var args []string | ||
| for _, name := range []string{"project", "environment"} { |
There was a problem hiding this comment.
P2: scopeArgs drops explicit --api-url and --organisation, so a copied undo can hit the default host or fail to resolve a named project across multiple organisations. Repeat those explicit context flags too.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At internal/cmd/undo.go, line 57:
<comment>`scopeArgs` drops explicit `--api-url` and `--organisation`, so a copied undo can hit the default host or fail to resolve a named project across multiple organisations. Repeat those explicit context flags too.</comment>
<file context>
@@ -0,0 +1,107 @@
+// hits the same project, environment and override from any directory.
+func scopeArgs(cmd *cobra.Command, segmentID int) []string {
+ var args []string
+ for _, name := range []string{"project", "environment"} {
+ if f := cmd.Flags().Lookup(name); f != nil && f.Changed {
+ args = append(args, "--"+name, shellQuote(f.Value.String()))
</file context>
| for _, name := range []string{"project", "environment"} { | |
| for _, name := range []string{"api-url", "organisation", "project", "environment"} { |
| }) | ||
| } | ||
|
|
||
| func TestUndoValueArgs(t *testing.T) { |
There was a problem hiding this comment.
P3: Add the required Given/When/Then sections to this new test so it follows the repository's test structure.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At internal/cmd/cmd_test.go, line 8879:
<comment>Add the required Given/When/Then sections to this new test so it follows the repository's test structure.</comment>
<file context>
@@ -8770,3 +8770,132 @@ func TestRefreshPersistsToKeychain(t *testing.T) {
+ })
+}
+
+func TestUndoValueArgs(t *testing.T) {
+ cases := []struct {
+ in any
</file context>
| if err != nil { | ||
| t.Fatalf("%v: %v\noutput: %s", tc.args, err, out) | ||
| } | ||
| if got := undoLine(out); got != tc.want { |
There was a problem hiding this comment.
P3: This assertion accepts the hint on stdout or before the confirmation because run combines both streams and undoLine searches the combined buffer. Capture stdout and stderr separately, then assert the hint is on stderr after the confirmation.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At internal/cmd/cmd_test.go, line 8861:
<comment>This assertion accepts the hint on stdout or before the confirmation because `run` combines both streams and `undoLine` searches the combined buffer. Capture stdout and stderr separately, then assert the hint is on stderr after the confirmation.</comment>
<file context>
@@ -8770,3 +8770,132 @@ func TestRefreshPersistsToKeychain(t *testing.T) {
+ if err != nil {
+ t.Fatalf("%v: %v\noutput: %s", tc.args, err, out)
+ }
+ if got := undoLine(out); got != tc.want {
+ t.Errorf("undo = %q, want %q\noutput: %s", got, tc.want, out)
+ }
</file context>
Part of #65: hint an undo command after a successful mutation.
After
flag update,flag enableorflag disablesucceeds, the CLI prints the command that puts the flag back, on stderr under the confirmation:--segment <id>; a newly created override is undone withflagsmith flag delete <feature> --segment <id>.--project/--environmentis repeated, so the command works from any directory. Values are shell-quoted, and a string that would be inferred as another type gets--type string.Not in this PR: the first half of #65 (showing a diff when confirming). That needs a decision on the format, so I left it for a follow-up.
Verified
TestFlagUpdateUndoHint(9 cases, including a failed update and the no-hint cases) andTestUndoValueArgs. The hint cases fail without the change.go vet ./...andgo test -race ./...pass.This contribution was prepared with AI coding assistance.