Skip to content

Commit ab8a035

Browse files
Restore non-human format rejection for confirmation-gated workflow commands
The JSON confirmation envelope replaced the old Format() != Human guard, which let --format csv fall through to interactive confirmation on a TTY for cancel, cutover, and switch-traffic. Reinstate the format error after the JSON branch so non-JSON machine formats fail fast without --force. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2cac4d5 commit ab8a035

6 files changed

Lines changed: 103 additions & 0 deletions

File tree

internal/cmd/workflow/cancel.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ marks it as cancelled, allowing you to start a new workflow if needed.`,
4646
cmdutil.AgentWorkflowActionCmd(wfCtx.Org, db, num, "cancel", "--force"))
4747
}
4848

49+
if ch.Printer.Format() != printer.Human {
50+
return fmt.Errorf(`cannot cancel workflow with the output format "%s" (run with --force to override)`, ch.Printer.Format())
51+
}
52+
4953
if !printer.IsTTY {
5054
return fmt.Errorf("cannot confirm cancellation (run with --force to override)")
5155
}

internal/cmd/workflow/cancel_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,36 @@ func TestWorkflow_CancelCmd(t *testing.T) {
8989
c.Assert(buf.String(), qt.JSONEquals, expectedWorkflow)
9090
}
9191

92+
func TestWorkflow_CancelCmd_CSVWithoutForce(t *testing.T) {
93+
c := qt.New(t)
94+
95+
var buf bytes.Buffer
96+
format := printer.CSV
97+
p := printer.NewPrinter(&format)
98+
p.SetResourceOutput(&buf)
99+
100+
svc := &mock.WorkflowsService{}
101+
102+
ch := &cmdutil.Helper{
103+
Printer: p,
104+
Config: &config.Config{
105+
Organization: "planetscale",
106+
},
107+
Client: func() (*ps.Client, error) {
108+
return &ps.Client{
109+
Workflows: svc,
110+
}, nil
111+
},
112+
}
113+
114+
cmd := CancelCmd(ch)
115+
cmd.SetArgs([]string{"planetscale", "123"})
116+
err := cmd.Execute()
117+
118+
c.Assert(err, qt.ErrorMatches, `cannot cancel workflow with the output format "csv".*`)
119+
c.Assert(svc.CancelFnInvoked, qt.IsFalse)
120+
}
121+
92122
func TestWorkflow_CancelCmd_Error(t *testing.T) {
93123
c := qt.New(t)
94124

internal/cmd/workflow/cutover.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func CutoverCmd(ch *cmdutil.Helper) *cobra.Command {
4545
cmdutil.AgentWorkflowActionCmd(wfCtx.Org, db, num, "cutover", "--force"))
4646
}
4747

48+
if ch.Printer.Format() != printer.Human {
49+
return fmt.Errorf(`cannot cutover with the output format "%s" (run with --force to override)`, ch.Printer.Format())
50+
}
51+
4852
if !printer.IsTTY {
4953
return fmt.Errorf("cannot confirm cutover (run with --force to override)")
5054
}

internal/cmd/workflow/cutover_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ func TestWorkflow_CutoverCmd(t *testing.T) {
9191
c.Assert(buf.String(), qt.JSONEquals, expectedWorkflow)
9292
}
9393

94+
func TestWorkflow_CutoverCmd_CSVWithoutForce(t *testing.T) {
95+
c := qt.New(t)
96+
97+
var buf bytes.Buffer
98+
format := printer.CSV
99+
p := printer.NewPrinter(&format)
100+
p.SetResourceOutput(&buf)
101+
102+
svc := &mock.WorkflowsService{}
103+
104+
ch := &cmdutil.Helper{
105+
Printer: p,
106+
Config: &config.Config{
107+
Organization: "planetscale",
108+
},
109+
Client: func() (*ps.Client, error) {
110+
return &ps.Client{
111+
Workflows: svc,
112+
}, nil
113+
},
114+
}
115+
116+
cmd := CutoverCmd(ch)
117+
cmd.SetArgs([]string{"planetscale", "123"})
118+
err := cmd.Execute()
119+
120+
c.Assert(err, qt.ErrorMatches, `cannot cutover with the output format "csv".*`)
121+
c.Assert(svc.CutoverFnInvoked, qt.IsFalse)
122+
}
123+
94124
func TestWorkflow_CutoverCmd_Error(t *testing.T) {
95125
c := qt.New(t)
96126

internal/cmd/workflow/switch_traffic.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ By default, this command will route all queries for primary, replica, and read-o
5454
cmdutil.AgentWorkflowActionCmd(wfCtx.Org, db, num, "switch-traffic", retryFlags...))
5555
}
5656

57+
if ch.Printer.Format() != printer.Human {
58+
return fmt.Errorf(`cannot switch query traffic with the output format "%s" (run with --force to override)`, ch.Printer.Format())
59+
}
60+
5761
if !printer.IsTTY {
5862
return fmt.Errorf("cannot confirm switching query traffic (run with --force to override)")
5963
}

internal/cmd/workflow/switch_traffic_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,37 @@ func TestWorkflow_SwitchTrafficCmd_Replicas(t *testing.T) {
163163
c.Assert(buf.String(), qt.JSONEquals, expectedWorkflow)
164164
}
165165

166+
func TestWorkflow_SwitchTrafficCmd_CSVWithoutForce(t *testing.T) {
167+
c := qt.New(t)
168+
169+
var buf bytes.Buffer
170+
format := printer.CSV
171+
p := printer.NewPrinter(&format)
172+
p.SetResourceOutput(&buf)
173+
174+
svc := &mock.WorkflowsService{}
175+
176+
ch := &cmdutil.Helper{
177+
Printer: p,
178+
Config: &config.Config{
179+
Organization: "planetscale",
180+
},
181+
Client: func() (*ps.Client, error) {
182+
return &ps.Client{
183+
Workflows: svc,
184+
}, nil
185+
},
186+
}
187+
188+
cmd := SwitchTrafficCmd(ch)
189+
cmd.SetArgs([]string{"planetscale", "123"})
190+
err := cmd.Execute()
191+
192+
c.Assert(err, qt.ErrorMatches, `cannot switch query traffic with the output format "csv".*`)
193+
c.Assert(svc.SwitchPrimariesFnInvoked, qt.IsFalse)
194+
c.Assert(svc.SwitchReplicasFnInvoked, qt.IsFalse)
195+
}
196+
166197
func TestWorkflow_SwitchTrafficCmd_Error(t *testing.T) {
167198
c := qt.New(t)
168199

0 commit comments

Comments
 (0)