Skip to content

feat(runner): add signal handling support (SIGINT/SIGTERM)#52

Merged
usernane merged 1 commit into
devfrom
feat/signal-handling
Jun 13, 2026
Merged

feat(runner): add signal handling support (SIGINT/SIGTERM)#52
usernane merged 1 commit into
devfrom
feat/signal-handling

Conversation

@usernane

Copy link
Copy Markdown
Member

Summary

Adds signal handling support (SIGINT/SIGTERM) to the CLI library, enabling graceful shutdown and per-command cleanup registration.

Motivation

When a CLI application receives OS signals, PHP terminates immediately with no cleanup opportunity. This is problematic for commands holding locks, temp files, or DB transactions, and for interactive mode running in containers. Closes #45.

Changes

  • Added SignalHandler class with register(), remove(), enable(), disable(), isSupported() API
  • Added enableSignalHandling(), setSignalHandler(), getSignalHandler(), isShutdownRequested() to Runner
  • Added onSignal(), getSignalHandlers(), clearSignalHandlers() to Command
  • Default SIGINT handler: exits with code 130 (in interactive mode: interrupts command but keeps app alive)
  • Default SIGTERM handler: sets shutdown flag, exits with code 143
  • Interactive mode loop checks shutdown flag for clean exit
  • Per-command signal handlers auto-removed after command finishes
  • Graceful degradation on Windows (no-op when pcntl unavailable)

How to Test / Verify

Unit and integration tests with 100% line coverage on all new code:

  • tests/WebFiori/Tests/Cli/SignalHandlerTest.php (13 tests)
  • tests/WebFiori/Tests/Cli/SignalIntegrationTest.php (22 tests)

Run: composer test

Breaking Changes and Migration Steps

None. All new functionality is opt-in via enableSignalHandling().

Checklist

  • I reviewed my own diff before requesting review
  • My commits follow Conventional Commits
  • I added/updated tests (or explained why not)
  • I updated docs (if needed) Docs Repo
  • I ran lint/cs-fixer (if applicable) (composer fix-cs)
  • I considered backward compatibility
  • I considered security

Related issues

Closes #45

- Add SignalHandler class with register/remove/enable/disable API
- Add enableSignalHandling() and setSignalHandler() to Runner
- Add onSignal() per-command cleanup registration to Command
- Default SIGINT: exits with code 130 (interactive: interrupts command only)
- Default SIGTERM: sets shutdown flag, exits with code 143
- Graceful degradation on Windows (no-op when pcntl unavailable)
- Interactive mode loop respects shutdown flag for clean exit
- Per-command handlers auto-removed after command finishes

Closes #45
@usernane usernane force-pushed the feat/signal-handling branch from 52e04bc to 5b68bfe Compare June 13, 2026 00:45
@usernane usernane merged commit f256870 into dev Jun 13, 2026
1 check passed
@usernane usernane deleted the feat/signal-handling branch June 13, 2026 00:48
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.86223% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.97%. Comparing base (54c6bd6) to head (5b68bfe).
⚠️ Report is 2 commits behind head on dev.

Files with missing lines Patch % Lines
WebFiori/Cli/Runner.php 97.67% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                dev      #52      +/-   ##
============================================
+ Coverage     87.72%   87.97%   +0.24%     
+ Complexity     1322     1284      -38     
============================================
  Files            33       34       +1     
  Lines          3610     3693      +83     
============================================
+ Hits           3167     3249      +82     
- Misses          443      444       +1     
Flag Coverage Δ
php-8.1 ?
php-8.2 ?
php-8.3 87.97% <97.86%> (+0.24%) ⬆️
php-8.4 ?
php-8.5 ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant