Skip to content

Commit d5ee641

Browse files
fix(cli): fail closed on destructive confirmations [EXT-69] (#292)
* fix: fail closed on destructive confirmations * test: cover explicit bulk move confirmation --------- Co-authored-by: bougyman's bot <ruby-automation@users.noreply.github.com>
1 parent d29348f commit d5ee641

9 files changed

Lines changed: 281 additions & 7 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Do not apply both to the same text.
2525
- Phase 10 Plan: documents/phase-10-plan.adoc
2626
- Phase 11 Plan: documents/phase-11-plan.adoc
2727
- Phase 12 Plan: documents/phase-12-plan.adoc
28+
- Phase 12 confirmation decision: documents/phase-12-confirmation-decision.adoc
2829
- Phase 13 Plan: documents/phase-13-plan.adoc
2930
- Phase 14 Plan: documents/phase-14-plan.adoc
3031
- Phase 15 Plan: documents/phase-15-plan.adoc

‎Readme.adoc‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ issues assigned to other users, or `--assignee` to select a named user. Already
313313
unassigned issues are skipped. Exact
314314
project and assignee matches are used without a prompt. Partial matches prompt
315315
you to choose a project or assignee. Before any filtered mutation, the command
316-
asks for confirmation; `--yes` skips that prompt and `--dry-run` prints the
317-
matching issues without changing them.
316+
asks for confirmation. An explicit `y` or `yes`, or `--yes`, is required.
317+
EOF, blank input, and exhausted invalid input cancel without
318+
changing issues. `--dry-run` prints the matching issues without changing them.
318319
The command processes at most 100 matches at a time. If more than 100 issues
319320
match, it prints a warning and processes only the first 100. Updates remain
320321
independent API calls, so a failed request can leave earlier matches already
@@ -437,7 +438,7 @@ $ lc issue move --project Manhattan --dry-run CRY-1 <3>
437438
$ lc issue move --project Manhattan --yes CRY-1 <4>
438439
$ lc issue move --project Manhattan --team ENG CRY-1 <5>
439440
----
440-
<1> Move a single issue; prompts for confirmation before executing
441+
<1> Move a single issue; an explicit `y` or `yes` is required before execution
441442
<2> Move multiple issues at once — updates run concurrently
442443
<3> Preview the planned moves without executing any mutations
443444
<4> Skip the confirmation prompt
@@ -454,7 +455,7 @@ $ lc issue move --from Retired --to Active --all <2>
454455
$ lc issue move --from p-uuid-1 --to p-uuid-2 <3>
455456
$ lc issue move --from Retired --to Active --dry-run <4>
456457
----
457-
<1> Moves all open issues from "Retired" to "Active", prompts for confirmation
458+
<1> Moves all open issues from "Retired" to "Active". An explicit `y` or `yes` is required
458459
<2> Includes completed and cancelled issues too
459460
<3> Move by project UUID — the way to target a project in another team
460461
<4> Preview without mutating

‎app/lib/linear_cli/cli/commands/issues/move.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ defmodule LinearCli.CLI.Commands.Issues.Move do
7373
do: apply_moves(issues, project, output)
7474

7575
defp execute_moves_if_confirmed(issues, project, _flags, output) do
76-
if Prompt.yes?("Proceed with move?"),
76+
if Prompt.confirm_destructive?("Proceed with move?"),
7777
do: apply_moves(issues, project, output),
7878
else: Prompt.warn("Move cancelled")
7979
end
@@ -145,7 +145,7 @@ defmodule LinearCli.CLI.Commands.Issues.Move do
145145
:ok
146146

147147
not flags.yes and
148-
not Prompt.yes?(
148+
not Prompt.confirm_destructive?(
149149
"Move #{length(issues)} issue(s) from #{source.name} to #{target.name}?"
150150
) ->
151151
Prompt.warn("Move cancelled")

‎app/lib/linear_cli/cli/commands/issues/mutations.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ defmodule LinearCli.CLI.Commands.Issues.Mutations do
212212
end
213213

214214
defp unassign_filtered_issues(issues, _flags, options) do
215-
if Prompt.yes?("Unassign #{length(issues)} issue(s)?") do
215+
if Prompt.confirm_destructive?("Unassign #{length(issues)} issue(s)?") do
216216
unassign_and_show(issues, options)
217217
else
218218
cancel_unassign(options)

‎app/lib/linear_cli/cli/prompt.ex‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ defmodule LinearCli.CLI.Prompt do
126126
@spec yes?(Owl.Data.t()) :: boolean()
127127
def yes?(message), do: Owl.IO.confirm(message: message, default: true)
128128

129+
@doc """
130+
Asks a yes/no question for a destructive operation, defaulting to `false`.
131+
132+
A blank answer or end of input cancels the operation. Use this helper for
133+
destructive confirmations. Keep `yes?/1` for prompts where the affirmative
134+
default is part of the existing behavior.
135+
"""
136+
@spec confirm_destructive?(Owl.Data.t()) :: boolean()
137+
def confirm_destructive?(message), do: Owl.IO.confirm(message: message, default: false)
138+
129139
@doc """
130140
Prompts for a single choice from an ordered `[{label, value}]` list,
131141
returning the chosen `value`.

‎app/test/linear_cli/cli/commands/issues/move_test.exs‎

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,46 @@ defmodule LinearCli.CLI.Commands.Issues.MoveTest do
150150
assert output =~ "Move cancelled"
151151
end
152152

153+
test "closed stdin cancels explicit-ID move without mutation" do
154+
test_pid = self()
155+
156+
Req.Test.stub(LinearCli.Api, fn conn ->
157+
{:ok, body, conn} = Plug.Conn.read_body(conn)
158+
decoded = Jason.decode!(body)
159+
query = decoded["query"]
160+
161+
cond do
162+
String.contains?(query, "issue(id: $id)") ->
163+
Req.Test.json(conn, %{"data" => %{"issue" => issue_map()}})
164+
165+
String.contains?(query, "projects(first: 100") ->
166+
Req.Test.json(conn, move_team_projects())
167+
168+
String.contains?(query, "issueUpdate") ->
169+
send(test_pid, :mutation_called)
170+
raise "closed stdin must not send issueUpdate"
171+
172+
true ->
173+
raise "no stub matched query: #{query}"
174+
end
175+
end)
176+
177+
output =
178+
capture_io([input: ""], fn ->
179+
assert :ok =
180+
LinearCli.CLI.main([
181+
"issue",
182+
"move",
183+
"--project",
184+
"Manhattan",
185+
"CRY-1"
186+
])
187+
end)
188+
189+
refute_received :mutation_called
190+
assert output =~ "Move cancelled"
191+
end
192+
153193
test "user confirms, mutation is called" do
154194
test_pid = self()
155195

@@ -473,6 +513,43 @@ defmodule LinearCli.CLI.Commands.Issues.MoveTest do
473513
assert vars3["input"]["projectId"] == "p-tgt"
474514
end
475515

516+
test "--from/--to proceeds with an explicit yes answer" do
517+
test_pid = self()
518+
519+
Req.Test.stub(LinearCli.Api, fn conn ->
520+
{:ok, body, conn} = Plug.Conn.read_body(conn)
521+
decoded = Jason.decode!(body)
522+
%{"query" => query} = decoded
523+
524+
if String.contains?(query, "issueUpdate") do
525+
send(test_pid, :update)
526+
end
527+
528+
case Enum.find(bulk_stub_pairs(), fn {match, _} -> String.contains?(query, match) end) do
529+
{_match, response} -> Req.Test.json(conn, response)
530+
nil -> raise "no stub matched query: #{query}"
531+
end
532+
end)
533+
534+
capture_io([input: "y\n"], fn ->
535+
assert :ok =
536+
LinearCli.CLI.main([
537+
"issue",
538+
"move",
539+
"--from",
540+
"Source Project",
541+
"--to",
542+
"Target Project",
543+
"--team",
544+
"ENG"
545+
])
546+
end)
547+
548+
assert_received :update
549+
assert_received :update
550+
assert_received :update
551+
end
552+
476553
test "--from/--to --all sends list query without completedAt/canceledAt guards" do
477554
test_pid = self()
478555

@@ -726,6 +803,43 @@ defmodule LinearCli.CLI.Commands.Issues.MoveTest do
726803
assert output =~ "Move cancelled"
727804
end
728805

806+
test "--from/--to closed stdin cancels without mutation" do
807+
test_pid = self()
808+
809+
Req.Test.stub(LinearCli.Api, fn conn ->
810+
{:ok, body, conn} = Plug.Conn.read_body(conn)
811+
%{"query" => query} = Jason.decode!(body)
812+
813+
if String.contains?(query, "issueUpdate") do
814+
send(test_pid, :mutation_called)
815+
raise "closed stdin must not send issueUpdate"
816+
end
817+
818+
case Enum.find(bulk_stub_pairs(), fn {match, _} -> String.contains?(query, match) end) do
819+
{_match, response} -> Req.Test.json(conn, response)
820+
nil -> raise "no stub matched query: #{query}"
821+
end
822+
end)
823+
824+
output =
825+
capture_io([input: ""], fn ->
826+
assert :ok =
827+
LinearCli.CLI.main([
828+
"issue",
829+
"move",
830+
"--from",
831+
"Source Project",
832+
"--to",
833+
"Target Project",
834+
"--team",
835+
"ENG"
836+
])
837+
end)
838+
839+
refute_received :mutation_called
840+
assert output =~ "Move cancelled"
841+
end
842+
729843
test "--from without --to exits 22 with a clear error" do
730844
test_pid = self()
731845
halt = fn code -> send(test_pid, {:halted, code}) end

‎app/test/linear_cli/cli/commands/issues/mutations_test.exs‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,80 @@ defmodule LinearCli.CLI.Commands.Issues.MutationsTest do
315315
assert output =~ "Unassign cancelled"
316316
end
317317

318+
test "confirms the filtered batch with an explicit yes answer" do
319+
test_pid = self()
320+
321+
Req.Test.stub(LinearCli.Api, fn conn ->
322+
{:ok, body, conn} = Plug.Conn.read_body(conn)
323+
%{"query" => query} = Jason.decode!(body)
324+
325+
cond do
326+
String.contains?(query, "issues(filter:") ->
327+
Req.Test.json(conn, issues_response([issue_map()]))
328+
329+
String.contains?(query, "issueUpdate") ->
330+
send(test_pid, :mutated)
331+
Req.Test.json(conn, issue_updated(%{"assignee" => nil}))
332+
333+
true ->
334+
raise "no stub matched query: #{query}"
335+
end
336+
end)
337+
338+
capture_io([input: "yes\n"], fn ->
339+
assert :ok =
340+
LinearCli.CLI.main([
341+
"issue",
342+
"unassign",
343+
"--no-profile",
344+
"--team",
345+
"ENG",
346+
"--state",
347+
"started"
348+
])
349+
end)
350+
351+
assert_received :mutated
352+
end
353+
354+
test "closed stdin cancels the filtered batch without mutating" do
355+
test_pid = self()
356+
357+
Req.Test.stub(LinearCli.Api, fn conn ->
358+
{:ok, body, conn} = Plug.Conn.read_body(conn)
359+
%{"query" => query} = Jason.decode!(body)
360+
361+
cond do
362+
String.contains?(query, "issues(filter:") ->
363+
Req.Test.json(conn, issues_response([issue_map()]))
364+
365+
String.contains?(query, "issueUpdate") ->
366+
send(test_pid, :mutated)
367+
raise "closed stdin must not send issueUpdate"
368+
369+
true ->
370+
raise "no stub matched query: #{query}"
371+
end
372+
end)
373+
374+
output =
375+
capture_io([input: ""], fn ->
376+
assert :ok =
377+
LinearCli.CLI.main([
378+
"issue",
379+
"unassign",
380+
"--no-profile",
381+
"--team",
382+
"ENG",
383+
"--state",
384+
"started"
385+
])
386+
end)
387+
388+
refute_received :mutated
389+
assert output =~ "Unassign cancelled"
390+
end
391+
318392
test "--dry-run lists filtered matches without mutation" do
319393
test_pid = self()
320394

‎app/test/linear_cli/cli/prompt_test.exs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,42 @@ defmodule LinearCli.CLI.PromptTest do
7474
end
7575
end
7676

77+
describe "confirm_destructive?/1" do
78+
test "defaults to false on EOF" do
79+
assert capture_io([input: ""], fn ->
80+
refute Prompt.confirm_destructive?("Proceed?")
81+
end) =~ "[yN]"
82+
end
83+
84+
test "defaults to false on a blank answer" do
85+
assert capture_io([input: "\n"], fn ->
86+
refute Prompt.confirm_destructive?("Proceed?")
87+
end) =~ "[yN]"
88+
end
89+
90+
test "returns false when invalid input is followed by EOF" do
91+
output =
92+
capture_io([input: "invalid\n"], fn ->
93+
refute Prompt.confirm_destructive?("Proceed?")
94+
end)
95+
96+
assert output =~ "unknown answer"
97+
assert output =~ "[yN]"
98+
end
99+
100+
test "an explicit yes answer returns true" do
101+
assert capture_io([input: "yes\n"], fn ->
102+
assert Prompt.confirm_destructive?("Proceed?")
103+
end) =~ "[yN]"
104+
end
105+
106+
test "an explicit no answer returns false" do
107+
assert capture_io([input: "n\n"], fn ->
108+
refute Prompt.confirm_destructive?("Proceed?")
109+
end) =~ "[yN]"
110+
end
111+
end
112+
77113
describe "select/2" do
78114
test "returns the value paired with the chosen label" do
79115
choices = [{"Bug fixes", :fix}, {"New feature work", :feat}]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
= Phase 12 confirmation behavior: fail closed for destructive commands
2+
:revdate: Sep 27, 2026
3+
:icons: font
4+
:toc:
5+
6+
== Status
7+
8+
This note supersedes the confirmation rule in Phase 12, decision 7, only.
9+
The accepted Phase 12 plan remains unchanged.
10+
11+
== Decision
12+
13+
Destructive bulk commands require an explicit affirmative answer unless the
14+
caller passes `--yes`.
15+
16+
* Filter-only `issue unassign` uses `Prompt.confirm_destructive?/1`.
17+
* Both `issue move` confirmation paths use `Prompt.confirm_destructive?/1`.
18+
* The helper calls `Owl.IO.confirm/1` with `default: false`.
19+
* EOF, blank input, and an exhausted stream after invalid input return `false` and send no mutation.
20+
* `y` and `yes` return `true` from a terminal or a usable pipe.
21+
* `--yes` bypasses the prompt.
22+
23+
`Prompt.yes?/1` keeps its affirmative default. Non-destructive prompts, such as
24+
the issue-create self-assignment prompt, keep their existing behavior.
25+
26+
== Reason
27+
28+
Owl maps EOF and blank input to its configured default. A destructive prompt
29+
with `default: true` can therefore authorize a mutation without an explicit
30+
affirmative answer. A separate helper limits the fail-closed behavior to the
31+
three destructive confirmation paths.
32+
33+
== Verification
34+
35+
Prompt tests cover EOF, blank input, `y`, `yes`, and `n`. Command tests prove
36+
that closed stdin sends no `issueUpdate` request for filter-only unassign,
37+
explicit-ID move, and project-to-project move. Existing `--yes` and explicit
38+
answer tests remain in place.

0 commit comments

Comments
 (0)