Repository navigation
feat(cli): add noninteractive controls and interrupt-safe progress - #5
Conversation
51e2179 to
0e6078b
Compare
tee8z
left a comment
There was a problem hiding this comment.
Follow-up from a broader pass over the PR: two issues with the new Ctrl-C handling, each with a suggested fix. The first one can leave the user's terminal in a bad state, so I think it should be fixed before merge.
ff3e105 to
1d73676
Compare
|
Follow-up to the review: beyond the interrupt-message fix @tee8z suggested for token refresh,
A sent write still outranks a session change. Unit tests cover each message, and integration tests interrupt a slow refresh, a login before it is saved, and a logout revoke. The same push also makes Ctrl-C exit 130 reliably: it installs the interrupt handler before the command runs ( |
1d73676 to
353fc3e
Compare
There was a problem hiding this comment.
The SIGINT payment recovery behavior looks correct against local mocks. Before merging, please address:
src/startup.rs:32: synchronous explicit stdin reads prevent both first and second Ctrl-C from being handled; move them behind cancellable orchestration.tests/cli_integration.rs:1330: make the PTY descriptors close-on-exec so concurrent children cannot keep the drain open.
tee8z
left a comment
There was a problem hiding this comment.
I'm good once @LightningK0ala comments are addressed
Add global --no-input and -q/--quiet, route stderr diagnostics through a Terminal helper that separates optional progress and notices from confirmation and recovery information, and show cancellable status on interactive stderr only. Terminal::during ties a status line to the one future it describes, so it clears on completion, error, or cancellation and cannot leak into a result. Ctrl-C exits 130 and wins at prompts. The interrupt handler is installed before the command runs, and terminal prompts, stdin, and --data or credential file reads run on a detached thread so a blocked read cannot hold the process. A hidden prompt saves the terminal attributes and restores them when cancelled, and a Ctrl-C typed at it, which rpassword raises as SIGINT itself, is reported as an interruption rather than an I/O failure. Every write is recorded immediately before it is sent, and an in-flight login change (token refresh, device login, or logout revoke) is recorded until its local side is saved. An interruption reports that no resource change was submitted, how to recover a login change, or an unknown outcome with the original ID; it never claims a write was cancelled. A fresh saved login is used without the credential lock, which is now taken only to refresh, so parallel commands no longer run one at a time. A const assertion keeps LOCK_TIMEOUT at least twice AUTH_TIMEOUT. Logout keeps the lock across revoke so a concurrent refresh cannot leave the new session live. TerminalModes' unsafe calls are an approved exception in the style guide.
353fc3e to
9bb9590
Compare
done |
Summary
--no-inputand--quietwhile preserving mandatory confirmations, errors, results and recovery IDs.--yesapproves consequential actions but never supplies a secret.voltage loginagain, or logout with--local).Terminalbuilt from the global flags instead of threadingquiet/no_inputbooleans through auth, config and startup.Terminal::duringties a status line to the one future it describes.Targets
masterdirectly (not stacked) and merges cleanly with it, including #9 and #10. Localdocs/plans/files are gitignored and intentionally not included.Feature-by-feature, before and after
Real output from master and
feat/cli-interaction-progress, both run against a slow local mock API. Long JSON is trimmed, and the temp directory is shown as<tmp>.1. Progress status on a terminal (new)
Before: the terminal sits silent for 2 seconds, then:
After: raw bytes written to stderr:
You see
Waiting for API response...while the request is in flight. Then\r\x1b[2K(carriage return, then "erase line") removes it, so the final screen looks the same as before. Other status labels are "Submitting request...", "Waiting for auth service...", "Waiting for device approval...", "Waiting for credential lock...", "Waiting for price service..." and "Waiting for checkout event...".When redirected (
2>fileor a pipe), both versions write 0 bytes to stderr. The status appears only when stderr is a real terminal, so log files never get control codes.2.
-q / --quiet(new)voltage -q wallets list --org $ORGNo status line. With
--quiet, the necessary output still appears:Hidden: status lines, "Invoice copied to the clipboard.", "Invoice is ready; continuing to poll...", and repeated "Payment X status: pending; waiting..." updates.
Before:
error: unexpected argument '-q' found, exit 2.3.
--no-input(new)On a terminal, without
--yes:Without the flag, it would show
Proceed? [y/N]and wait. With it, nothing is sent and no recovery record is written.Secrets are never taken from
--yes:The fix is
... auth import-key --stdin <<< "$KEY".Before:
error: unexpected argument '--no-input' found, exit 2.Refusing earlier: when a confirmation can't be answered, the branch now refuses before resolving credentials or making a wallet preflight request, so nothing touches the network. In my run the timing was the same (0.01s) because an API key from the environment needs no refresh. With a login session it saves a token refresh.
4. Ctrl-C at the
Proceed? [y/N]prompt (fix)Before:
The blocking
read_linestalled the async task, so the CLI's own Ctrl-C handler never ran. The operating system killed the process outright: no error report, no--jsonerror, and the cursor left on the prompt line.After:
The read runs on a detached thread (
read_detached), so the handler runs. It reports an error that says what happened and exits with the standard code 130.5. Ctrl-C messages that say what actually happened (fix)
During a read (
wallets list):error: Interrupted; any submitted payment continues independently. Use its original ID to check status.error: Interrupted before any resource change was submittedThe old message mentioned a payment during a read-only list, which was misleading.
While a payment POST is in flight (
--yes payments create):Before:
After:
The new message names the ID and machine-readable
detailssay"outcome":"unknown", so a script can reconcile. Awallets deleteinterrupted the same way gets a generic "request may have been submitted" message that doesn't mention a payment.SubmissionStateinsrc/api.rsmakes this work. It records the write just before the request leaves the process, and the Ctrl-C handler checks it to pick the right message. A second Ctrl-C now callsexit(130)immediately, even if cleanup is still running.6. Unchanged except for wording
Piped stdin without
--yesbehaves the same on both versions (exit 2, summary printed first). Only the message changed, from "requires --yes in noninteractive use" to "requires --yes when input is disabled or noninteractive".Review exceptions
std::threadfor terminal reads: a blocked read cannot be cancelled, and the runtime waits forspawn_blockingwork at shutdown. Aoneshotchannel reports completion, and process exit ends an unfinished read.syncfeature: providesoneshotfor those reads andNotifyin tests; no new crate.unsafelibc::tcgetattr/tcsetattrinTerminalModes(production): std cannot save or restore terminal attributes, and rpassword restores echo only when its read returns, which Ctrl-C no longer waits for. One call per block with aSAFETY:comment; recorded in the style guide's approved exceptions.unsafelibc::openpty,setsid/ioctl(TIOCSCTTY)inpre_exec, andtcgetattr: std cannot open a PTY, make it a child's controlling terminal, or read its modes, and terminal-only progress and echo restoration need a real terminal to test. Each block has aSAFETY:comment.pub(crate) LOCK_TIMEOUT: read by a const assertion inauththat keeps it at least twiceAUTH_TIMEOUT.Verification
cargo fmt --checkcargo clippy --locked --all-targets -- -D warnings, plus the test file linted with itscfg(unix)items disabled to simulate the Windows jobcargo test --lockedpython3 scripts/check-coverage.pycargo machete --with-metadata