Skip to content

feat: add ctrl+c cancellation on running pw-checks/tests#1292

Draft
ferrandiaz wants to merge 20 commits into
mainfrom
ferran/red-375-cli-ctrlc-during-checkly-pw-test-cancel-test-session
Draft

feat: add ctrl+c cancellation on running pw-checks/tests#1292
ferrandiaz wants to merge 20 commits into
mainfrom
ferran/red-375-cli-ctrlc-during-checkly-pw-test-cancel-test-session

Conversation

@ferrandiaz
Copy link
Copy Markdown
Contributor

@ferrandiaz ferrandiaz commented Apr 28, 2026

Affected Components

  • CLI
  • Create CLI
  • Test
  • Docs
  • Examples
  • Other

Notes for the Reviewer

Pressing Ctrl-C during checkly pw-test, checkly test, or checkly trigger now shows an interactive confirmation prompt ("Stop running checks?") instead of immediately killing the CLI process and leaving the remote test session running. If the user confirms, the CLI calls a new /v1/cancel REST endpoint to abort the in-flight session server-side.

Motivation

Before this change, Ctrl-C terminated the CLI without signalling the backend — the remote session kept consuming cloud resources with no way to stop it.

What changed

  • New Cancel REST client (rest/cancel.ts) — POST /v1/cancel via cancelTestSession and cancelCheckSession; registered as api.cancel in api.ts
  • SIGINT handler in AbstractCheckRunner — pauses the PQueue while the prompt is open (buffering in-flight results), resumes on answer, 100 ms debounce against duplicate signals, second Ctrl-C force-quits immediately
  • Three CLI commands (pw-test, test, trigger) wire Events.CANCEL / CANCEL_PROMPT_SHOWN / CANCEL_PROMPT_HIDDEN to reporters and the cancel API; --detach skips handler registration entirely
  • Reporters — new onCancelPromptShown / onCancelPromptHidden lifecycle on the Reporter interface; CheckStatus.CANCELLED with symbol; cancelled-count in summary line; live status bar and log output suppressed while prompt is open
  • TTY gateisInteractiveTerminal() in reporters/util.ts skips the prompt and cancels immediately in CI, piped stdio, or dumb terminals:

Tests

Unit tests across cancel client (4), runner SIGINT lifecycle (12), reporter cancel UI (15), util including TTY gate (31). E2E (2) verifies pre-buffered Ctrl-C and confirm-with-y.

Notes

  • cancelCheckSession is wired but not called from any command in this PR — reserved for a future integration
  • Any custom Reporter implementations outside this repo need stubs for onCancelPromptShown() and onCancelPromptHidden()
  • --detach skips SIGINT registration; Ctrl-C kills the CLI but leaves cloud checks running (documented intent)

@ferrandiaz ferrandiaz added the build Issue regarding building and packaging label Apr 28, 2026
@github-actions

This comment has been minimized.

ferrandiaz added 4 commits May 7, 2026 15:43
Adds an isCancelling flag to AbstractListReporter so the live status panel
stops re-rendering while the cancel confirmation prompt is on screen, and
resumes when the prompt closes.

- onCancelPromptShown clears the panel and raises the flag.
- onCancelPromptHidden lowers the flag and repaints; runs on both confirm
  and decline so live updates resume during the cancellation drain.
- _printSummary and onStreamLogs short-circuit while the flag is up.
- _clearSummary becomes a no-op when there is nothing to erase, preserving
  the clear/print invariant if a guard skips the paired _printSummary.
PQueue.pause() does not interrupt an in-flight handler. A CHECK_INPROGRESS
handler that started before SIGINT could still emit and trigger a panel
re-render right under the cancel prompt, producing spurious project-tree
output.

- Emit CANCEL_PROMPT_SHOWN before queue.pause(); EventEmitter.emit is
  synchronous so reporters set their flag before any pending handler can
  render.
- Emit CANCEL_PROMPT_HIDDEN after the prompt resolves on both confirm and
  decline, restoring live updates.
- On confirm, print 'Cancelling test session...' so the user sees feedback
  while the backend cancellation completes.
- Always queue.start() after the prompt: drains MQTT results so
  allChecksFinished can resolve on confirm, resumes normal flow on decline.
- Use printLn instead of raw process.stdout.write to match the rest of the
  CLI.
Wires the runner's CANCEL_PROMPT_SHOWN and CANCEL_PROMPT_HIDDEN events to
each reporter for the test, pw-test, and trigger commands.
Covers happy paths (clear-then-repaint, normal render before/after the
prompt) and edge cases (empty _clearString no-op, double prompt-shown
idempotency, prompt-hidden without prior prompt-shown, suppression of
_printSummary and onStreamLogs while cancelling).
@ferrandiaz ferrandiaz added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels May 7, 2026
@github-actions

This comment has been minimized.

@ferrandiaz ferrandiaz added canary:cancel build Issue regarding building and packaging and removed build Issue regarding building and packaging labels May 8, 2026
@github-actions

This comment has been minimized.

@ferrandiaz ferrandiaz added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels May 13, 2026
@github-actions

This comment has been minimized.

@ferrandiaz ferrandiaz added build Issue regarding building and packaging and removed build Issue regarding building and packaging labels May 14, 2026
@github-actions
Copy link
Copy Markdown

🎉 Experimental release successfully published on npm

npm install checkly@0.0.0-pr.1292.fff12f3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Issue regarding building and packaging canary:cancel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant