Skip to content

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

Draft
ferrandiaz wants to merge 14 commits intomainfrom
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 14 commits intomainfrom
ferran/red-375-cli-ctrlc-during-checkly-pw-test-cancel-test-session

Conversation

@ferrandiaz
Copy link
Copy Markdown
Contributor

Affected Components

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

Notes for the Reviewer

Adds a --detach (-d) flag to the test, pw-test, and trigger commands. When active, Ctrl+C no longer exits immediately — instead it shows a confirmation prompt and cancels the remote test session via POST /v1/cancel, allowing the server to return results marked as cancelled rather than dropping the connection mid-run.

SIGINT flow (with --detach)

  • First Ctrl+C: pauses the check queue, shows "Stop running checks?" prompt
  • Confirm: emits a CANCEL event, resumes the queue, server returns results with cancelled status
  • Decline: resumes the queue; the next Ctrl+C will ask again
  • Second Ctrl+C while the prompt is active: force-quits with exit code 130
  • Without --detach: Ctrl+C exits immediately (behavior unchanged)

Key files changed

  • rest/cancel.ts — new file, thin client for POST /v1/cancel
  • abstract-check-runner.ts — SIGINT handler added as private methods; cleanup in finally
  • Reporter files — CANCELLED status handling, isCancelled priority
  • test, pw-test, trigger command files — flag declaration and cancel handler wiring

@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
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🎉 Experimental release successfully published on npm

npm install checkly@0.0.0-pr.1292.53a75cb

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