feat: Add per-test timeout support to prevent hung tests#356
feat: Add per-test timeout support to prevent hung tests#356OleksandrKucherenko wants to merge 8 commits intoshellspec:masterfrom
Conversation
- Update README.md with --timeout and --no-timeout options - Add comprehensive timeout documentation to docs/cli.md - Add verification test spec/verify_timeout_spec.sh 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
115ffc3 to
d2ccd84
Compare
e9b2d59 to
0c87cc3
Compare
- Restore SHELLSPEC_PATH in watchdog script to access system utilities (sleep, rm) which are not available in shellspec's modified PATH - Use shellspec_rm instead of plain rm in dsl.sh for timeout file cleanup These fixes ensure the timeout feature works correctly in shellspec's modified PATH environment during test execution.
Bug Fix: Timeout Feature PATH IssuesDuring verification testing, two critical bugs were discovered and fixed: Issue 1: Watchdog Script PATHThe watchdog script couldn't find Fix: Added PATH restoration at the beginning of if [ "${SHELLSPEC_PATH:-}" ]; then
PATH="$SHELLSPEC_PATH"
export PATH
fiIssue 2: rm Command in dsl.shThe cleanup code in Fix: Changed lines 234 and 243 from Verification ResultsAll timeout functionality tests now pass:
|
- Added section for critical rejections (dsl.sh, outputs.sh) - Documented the PATH restoration fix for watchdog - Added instructions to use shellspec_rm instead of rm - Added troubleshooting section for common issues - Expanded manual fixes section with code examples
Documentation Update: Patch Installation GuideUpdated New Sections Added:
Key Points for Users:
Commit: |
- Added shellspec-0.28.1-to-0.29.0-timeout.patch generated by comparing actual release archives (no context line mismatches) - Updated PATCH_INSTALLATION.md with two installation options: 1. Release-based patch (recommended, applies cleanly) 2. PR-based patch (may have rejections) - Added patch generation instructions for users - Includes all bug fixes (PATH restoration, shellspec_rm)
Release-Based Patch Added 🎉A new approach for patch installation is now available that applies cleanly to 0.28.1 without any rejections! New Files Added:
How It Works:Instead of using git commit diffs (which have context line mismatches), we now provide a patch created by:
Installation:cd ~/.local/lib/shellspec
curl -L https://raw.githubusercontent.com/OleksandrKucherenko/shellspec/timeout-implementation/docs/features/timeout/shellspec-0.28.1-to-0.29.0-timeout.patch -o timeout.patch
patch -p1 < timeout.patchVerification Results:
Commit: |
- Clear 5-step installation process - Explanation of why bin/shellspec.rej is harmless (it's a symlink) - Usage examples for timeout feature - Simplified troubleshooting section
Documentation Simplified ✅Updated Installation is Now Just 5 Steps:
Clarification on
|
#357 - Merge as 0.29.0 version
Resolves:
Summary
This PR implements timeout support for ShellSpec to prevent hung tests and infinite loops. The feature provides both global and per-test timeout configuration with a background watchdog process that enforces timeout limits.
Key Features
--timeout 60(default: 60 seconds)It 'test' % timeout:3030,30s,1m,1m30s--no-timeoutto disable timeoutsImplementation Details
The implementation uses a background watchdog process pattern (similar to the existing profiler) for cross-shell portability:
--timeoutand--no-timeoutCLI options%timeoutdirective for per-test overridesFiles Changed
New files:
lib/libexec/timeout-parser.sh- Parse timeout formatslibexec/shellspec-timeout-watchdog.sh- Watchdog process implementationModified files:
lib/libexec/optparser/parser_definition.sh- CLI optionslib/libexec/optparser/optparser.sh- Validationlib/libexec/optparser/parser_definition_generated.sh- Generated parserlib/libexec/grammar/directives- Grammar directivelib/libexec/translator.sh- Metadata extractionlibexec/shellspec-translate.sh- Code generationlib/core/dsl.sh- Watchdog integrationlib/core/outputs.sh- TIMEOUT output handlerlib/bootstrap.sh- Parser loadingDocumentation:
README.md- CLI options documentationdocs/cli.md- Comprehensive timeout documentationspec/timeout_spec.sh- Unit tests verifying integrationspec/verify_timeout_spec.sh- Manual verification testTesting
Usage Examples
Design Decisions
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com
How to Manually Apply the Timeout Feature
If you need to use the timeout feature before the official release (v0.29.0) is merged, you can apply it as a patch to your existing ShellSpec installation.
Prerequisites
curlorwgetpatchutility (standard on most Unix-like systems)~/.local/lib/shellspecor wherever it was cloned/extracted)Instructions
Navigate to your ShellSpec installation directory:
Download the Patch:
We recommend using the pull request patch.
# Download patch for PR #357 (Release 0.29.0) curl -L https://github.com/shellspec/shellspec/pull/357.patch -o shellspec-timeout.patchApply the Patch:
patch -p1 < shellspec-timeout.patchVerify the Installation:
Check if the version or help output reflects the change.
./shellspec --help | grep timeoutYou should see:
Rolling Back
To revert the changes:
patch -R -p1 < shellspec-timeout.patch rm shellspec-timeout.patch