feat(samoid): implement hook execution runtime (#3)#15
Merged
Conversation
## Summary Implement the hook runner that executes actual hook scripts with proper environment setup, error handling, and debugging support. ## Implementation Details - **Hook Runner Binary**: New `samoid-hook` binary for executing Git hooks - **Environment Control**: Support for SAMOID=0/1/2 (skip/normal/debug modes) - **Init Script Loading**: Automatic loading of `~/.config/samoid/init.sh` - **Error Handling**: Proper exit code propagation and clear error messages - **Debug Mode**: Detailed script tracing with SAMOID=2 - **Cross-Platform**: Windows home directory fallback support ## Architecture The hook runner follows dependency injection pattern for testability: - Environment, CommandRunner, and FileSystem traits - Mock implementations for comprehensive unit testing - Thread-safe mocks using Arc<Mutex<T>> ## Key Features ✅ Execute hook scripts from project root directory ✅ Load initialization script from `~/.config/samoid/init.sh` ✅ Handle `SAMOID=0` environment variable to skip execution ✅ Support `SAMOID=2` for debug mode with script tracing ✅ Exit with hook script's exit code ✅ Display informative error messages for failed hooks ✅ Show "command not found" message when PATH is incorrect ✅ Skip execution if hook script file doesn't exist ## Testing - 30+ unit tests with dependency injection pattern - Mock implementations for complete test isolation - Integration tests with real hook script execution - Error scenario coverage (exit codes, command not found) ## Acceptance Criteria Met All acceptance criteria from issue #3 have been implemented and tested. Closes #3
Auto-formatting and linting fixes applied to samoid source files: - src/config.rs: Code formatting improvements - src/hook_runner.rs: Formatting and style consistency - src/main.rs: Code style improvements - src/project.rs: Formatting consistency No functional changes - maintaining code quality standards.
behrangsa
added a commit
that referenced
this pull request
Jul 31, 2025
* feat(samoid): implement hook execution runtime (#3) ## Summary Implement the hook runner that executes actual hook scripts with proper environment setup, error handling, and debugging support. ## Implementation Details - **Hook Runner Binary**: New `samoid-hook` binary for executing Git hooks - **Environment Control**: Support for SAMOID=0/1/2 (skip/normal/debug modes) - **Init Script Loading**: Automatic loading of `~/.config/samoid/init.sh` - **Error Handling**: Proper exit code propagation and clear error messages - **Debug Mode**: Detailed script tracing with SAMOID=2 - **Cross-Platform**: Windows home directory fallback support ## Architecture The hook runner follows dependency injection pattern for testability: - Environment, CommandRunner, and FileSystem traits - Mock implementations for comprehensive unit testing - Thread-safe mocks using Arc<Mutex<T>> ## Key Features ✅ Execute hook scripts from project root directory ✅ Load initialization script from `~/.config/samoid/init.sh` ✅ Handle `SAMOID=0` environment variable to skip execution ✅ Support `SAMOID=2` for debug mode with script tracing ✅ Exit with hook script's exit code ✅ Display informative error messages for failed hooks ✅ Show "command not found" message when PATH is incorrect ✅ Skip execution if hook script file doesn't exist ## Testing - 30+ unit tests with dependency injection pattern - Mock implementations for complete test isolation - Integration tests with real hook script execution - Error scenario coverage (exit codes, command not found) ## Acceptance Criteria Met All acceptance criteria from issue #3 have been implemented and tested. Closes #3 * chore: apply formatting and linting improvements Auto-formatting and linting fixes applied to samoid source files: - src/config.rs: Code formatting improvements - src/hook_runner.rs: Formatting and style consistency - src/main.rs: Code style improvements - src/project.rs: Formatting consistency No functional changes - maintaining code quality standards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implement the hook runner that executes actual hook scripts with proper environment setup, error handling, and debugging support as specified in issue #3.
🎯 Acceptance Criteria Complete
All acceptance criteria from issue #3 have been successfully implemented:
~/.config/samoid/init.shSAMOID=0environment variable to skip executionSAMOID=2for debug mode with script tracing🏗️ Architecture & Design
Hook Runner Binary
samoid-hookbinary that serves as the actual Git hook executorEnvironment Variable Controls
Dependency Injection Pattern
Follows established codebase patterns for complete test isolation:
Environment,CommandRunner,FileSystemtrait abstractionsSystemEnvironment,SystemCommandRunner,SystemFileSystemArc<Mutex<T>>for thread-safe testingCross-Platform Support
~/.config/samoid/init.sh(using XDG_CONFIG_HOME)%USERPROFILE%\.config\samoid\init.sh🧪 Testing Strategy
Comprehensive Unit Testing
Integration Testing
Quality Metrics
Following the codebase's high-quality testing standards established in the existing implementation.
📦 Implementation Details
Hook Execution Flow
~/.config/samoid/init.sh(if exists).samoid/_/{hook_name}Error Handling
Files Modified
Cargo.toml: Addedsamoid-hookbinary configurationsrc/hook_runner.rs: Complete hook runner implementation with tests🔗 Dependencies
📋 Test Plan
🚀 Ready for Review
This implementation provides a robust, well-tested hook execution runtime that forms the core of the samoid Git hooks system. The dependency injection pattern ensures maintainability and testability while supporting all specified requirements.
Closes #3