Repository navigation
feat!: use cli-core's confirmation flow for destructive commands - #141
Conversation
Bump @todoist/cli-core to 2.1.0 and move tdc's --yes / --dry-run
flow onto its shared helpers, so it behaves like the other Todoist
CLIs:
- channel delete, comment delete, msg delete, groups delete, thread
delete, thread done/undone and conversation done/undone call
requireConfirmation before any request and previewUnlessConfirmed
once the target is resolved. Without --yes they print the same
"Would ..." line and "Use --yes to confirm."; channel delete now
names the resolved channel rather than echoing the ref.
- bulk thread mark-read / mark-unread use requireConfirmation for
their guard and keep their per-thread preview rows.
- every printDryRun caller imports it from cli-core, and the local
copy and its tests are gone (cli-core tests the same cases).
BREAKING CHANGE: a destructive command run with --json but without
--yes or --dry-run now fails with CONFIRMATION_REQUIRED ("Pass --yes
to execute <command>, or --dry-run to preview it.") instead of
MISSING_YES_FLAG, and fails before any API call. --dry-run --json now
prints a { "status": "preview", "command", "messages" } object
instead of the plain-text dry-run preview.
doistbot
left a comment
There was a problem hiding this comment.
This migrates the destructive commands (channel/comment/msg/thread delete, thread and conversation done/undone, bulk mark-read/mark-unread) onto cli-core 2.1.0's shared confirmation helpers, replacing the local printDryRun and retiring MISSING_YES_FLAG in favor of CONFIRMATION_REQUIRED that fires before any API call, with a new JSON preview envelope. It's a clean, internally consistent migration: handler wiring, tests, skill content, and docs all line up, and the security-sensitive ordering (private-channel and ownership checks still precede previews) is preserved.
Few things worth tightening:
- The channel delete tests pass
Engineeringas the ref while the resolved channel is also namedEngineering, so the assertions can't tell whether the preview uses the resolved channel or echoes the ref — the exact behavior this PR changes. Use a ref that differs from the name (e.g.CH500oreng) soWould delete: Engineering (id:CH500)only passes when the resolved name is used.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (2)
src/commands/thread/helpers.ts:141:
needsConfirmationon line 140 already encodes this bulk guard, soif (rawRefs.length > 1)reads as ifrequireConfirmationfires even with--yes/--dry-run. Reuse the variable (if (needsConfirmation)) — cli-core's helper no-ops on--yes/--dry-run, so the behaviour is unchanged — and there's a single expression of the condition to keep in sync.src/commands/thread/thread.test.ts:2102: This preview test only checks the output envelope. The fixture thread isn't archived, so a regression that ignored
--dry-runand archived anyway would be caught only by the extra result log, not by a direct side-effect assertion. Addexpect(client.inbox.archiveThread).not.toHaveBeenCalled(), matching the new preview tests forthread delete/channel delete/etc. Same gap in theconversation donepreview test (conversation.test.ts:1228), whereconversations.archiveConversationshould be asserted not called.
The channel delete preview tests passed the channel's own name as the ref, so they could not tell the resolved name from an echo of the ref. Use a different ref. The thread and conversation done --dry-run --json tests now also assert nothing was archived, and the bulk read-state guard reuses needsConfirmation instead of restating the condition.
|
🎉 This PR is included in version 6.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Bumps
@todoist/cli-coreto 2.1.0 and moves tdc's--yes/--dry-runflow onto the shared helpers from todoist/cli-core#198, so destructive commands behave the same way in tdc as in td (todoist/todoist-cli#734).channel delete,comment delete,msg delete,groups delete,thread delete,thread done/undoneandconversation done/undonecallrequireConfirmationbefore any request andpreviewUnlessConfirmedonce the target is resolved. Without--yesthey print the sameWould …line andUse --yes to confirm.as before.channel deletenow names the resolved channel (Would delete: Engineering (id:CH500)) rather than echoing the ref, andchannel/comment/msg deletenow look the target up before showing that preview.thread mark-read/mark-unreaduserequireConfirmationfor their guard but keep their own per-thread preview rows (dryRun: trueunder--json), since a multi-thread plan doesn't fit the single-message envelope.printDryRuncaller imports it from cli-core. The local copy and its tests are gone; cli-core tests the same cases and its version is identical.CODEBASE.mdpoints atchannel/delete.tsas the example.This is breaking for scripts, hence
feat!: under--jsonwithout--yesor--dry-run, these commands now fail withCONFIRMATION_REQUIRED("Pass --yes to execute , or --dry-run to preview it.") instead ofMISSING_YES_FLAG, and they fail before any API call.--dry-run --jsonnow prints a{ "status": "preview", "command", "messages" }object instead of the plain-text preview.MISSING_YES_FLAGis no longer used anywhere and has been removed from the error codes.Checked with
npm run verify, and with the built CLI:tdc thread done <ref> --jsonfails withCONFIRMATION_REQUIRED, andtdc thread done <ref> --dry-run --jsonon a real inbox thread prints the preview envelope without changing anything.