Skip to content

Add Core Utility Libraries Migration with Comprehensive Bash Testing#18

Merged
ooloth merged 2 commits intomainfrom
feature/core-utils-bash
Jul 11, 2025
Merged

Add Core Utility Libraries Migration with Comprehensive Bash Testing#18
ooloth merged 2 commits intomainfrom
feature/core-utils-bash

Conversation

@ooloth
Copy link
Owner

@ooloth ooloth commented Jul 10, 2025

💪 What

Core Utility Libraries Migration: Complete migration of machine detection and prerequisite validation from zsh to bash, establishing the foundation for all setup processes.

Files Changed

  • bin/lib/machine-detection.bash - Machine type detection with hostname patterns (13 tests, all passing)
  • bin/lib/prerequisite-validation.bash - System prerequisites validation (19 tests, all passing)
  • test/setup/test-machine-detection-bash.bats - Comprehensive unit tests for machine detection
  • test/setup/test-prerequisite-validation-bash.bats - Comprehensive unit tests for prerequisite validation

Core Functionality Migrated

Machine Detection:

  • detect_machine_type() - Hostname pattern matching (Air/Mini/Work)
  • set_machine_variables() - Environment variable setup (IS_AIR, IS_MINI, IS_WORK)
  • init_machine_detection() - Complete initialization with optional debug output

Prerequisite Validation:

  • validate_command_line_tools() - Xcode Command Line Tools verification
  • validate_network_connectivity() - Essential service reachability (GitHub, raw.githubusercontent.com)
  • validate_macos_version() - Minimum version compatibility (macOS 12.0+)
  • validate_directory_permissions() - Directory existence and access validation
  • validate_write_permissions() - Write access verification with temp file testing
  • run_prerequisite_validation() - Comprehensive validation workflow with detailed reporting

🤔 Why

Foundation for bash migration project: These utilities are used by all setup processes and needed to be migrated first to establish the core infrastructure for the bash migration.

Quality improvements:

  • Industry-standard tooling - Zero shellcheck warnings for both utilities
  • Comprehensive test coverage - 32 total tests covering all functions and edge cases
  • Better error handling - Improved error messages and graceful fallbacks
  • Architecture awareness - Environment variable overrides and debug modes

👀 Usage

Machine Detection:

source "$DOTFILES_ROOT/bin/lib/machine-detection.bash"

# Initialize machine detection
init_machine_detection

# Check machine type
if [[ "$IS_AIR" == "true" ]]; then
    echo "Running on personal MacBook Air"
elif [[ "$IS_MINI" == "true" ]]; then
    echo "Running on Mac Mini server"  
else
    echo "Running on work machine"
fi

Prerequisite Validation:

source "$DOTFILES_ROOT/bin/lib/prerequisite-validation.bash"

# Run all validation checks
if run_prerequisite_validation; then
    echo "System ready for installation"
else
    echo "Prerequisites not met, please fix issues above"
    exit 1
fi

# Individual validations
validate_command_line_tools
validate_network_connectivity
validate_macos_version

👩‍🔬 How to validate

Run all tests:

# Machine detection tests (13 tests)
./test/run-tests.zsh test-machine-detection-bash
# OR
bats test/setup/test-machine-detection-bash.bats

# Prerequisite validation tests (19 tests)  
./test/run-tests.zsh test-prerequisite-validation-bash
# OR
bats test/setup/test-prerequisite-validation-bash.bats

Test machine detection:

# Test hostname detection
MACHINE=air bin/lib/machine-detection.bash detect_machine_type
# Should output: air

# Test with debug mode
DEBUG_MACHINE_DETECTION=true bin/lib/machine-detection.bash init_machine_detection

Test prerequisite validation:

# Run validation on current system
bin/lib/prerequisite-validation.bash run_prerequisite_validation

# Test individual components
bin/lib/prerequisite-validation.bash validate_macos_version

Verify shellcheck compliance:

shellcheck bin/lib/machine-detection.bash
shellcheck bin/lib/prerequisite-validation.bash
# Both should show no warnings

All 32 tests pass, zero shellcheck warnings, maintains complete feature parity with original zsh implementations.

🔗 Related links

- Create bin/lib/machine-detection.bash with hostname-based detection
- Add detect_machine_type() for air/mini/work machine identification
- Add set_machine_variables() for IS_AIR/IS_MINI/IS_WORK environment setup
- Add init_machine_detection() for complete initialization workflow
- Add 13 comprehensive unit tests covering all edge cases

- Create bin/lib/prerequisite-validation.bash with system validation
- Add validate_command_line_tools() for Xcode Command Line Tools checking
- Add validate_network_connectivity() for essential service reachability
- Add validate_macos_version() for minimum version compatibility
- Add validate_directory_permissions() and validate_write_permissions()
- Add run_prerequisite_validation() for complete validation workflow
- Add 19 comprehensive unit tests covering all validation scenarios

- Follow established bash migration pattern with zero shellcheck warnings
- All 32 tests pass, demonstrates complete functionality parity
- Maintains original zsh behavior while improving code quality
@ooloth ooloth merged commit 7986d2d into main Jul 11, 2025
1 check passed
@ooloth ooloth deleted the feature/core-utils-bash branch July 11, 2025 03:33
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