#!/usr/bin/env pwsh <# .SYNOPSIS Verifies the interactive rebase challenge solution. .DESCRIPTION Checks that the user successfully cleaned up the commit history by combining multiple messy commits into a single clean commit. #> Set-Location "challenge" -ErrorAction SilentlyContinue # Check if challenge directory exists if (-not (Test-Path "../verify.ps1")) { Write-Host "Error: Please run this script from the module directory" -ForegroundColor Red exit 1 } if (-not (Test-Path ".")) { Write-Host "Error: Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red Set-Location .. exit 1 } Write-Host "Verifying your solution..." -ForegroundColor Cyan # Check if git repository exists if (-not (Test-Path ".git")) { Write-Host "[FAIL] No git repository found." -ForegroundColor Red Set-Location .. exit 1 } # Check commit count (should be exactly 2: initial + combined feature commit) $commitCount = (git rev-list --count HEAD 2>$null) if ($commitCount -ne 2) { Write-Host "[FAIL] Expected exactly 2 commits, found $commitCount" -ForegroundColor Red if ($commitCount -gt 2) { Write-Host "Hint: You have too many commits. Use 'git reset --soft HEAD~N' to combine them." -ForegroundColor Yellow Write-Host " Where N is the number of commits to undo (should be 4 in this case)." -ForegroundColor Yellow } else { Write-Host "Hint: You may have reset too far back. Run ../reset.ps1 to start over." -ForegroundColor Yellow } Set-Location .. exit 1 } # Get commit messages $commits = git log --pretty=format:"%s" 2>$null $commitArray = $commits -split "`n" # Check that first commit is still the initial commit if ($commitArray[1] -ne "Initial commit") { Write-Host "[FAIL] The initial commit should remain unchanged." -ForegroundColor Red Write-Host "Expected first commit: 'Initial commit'" -ForegroundColor Yellow Write-Host "Found: '$($commitArray[1])'" -ForegroundColor Yellow Set-Location .. exit 1 } # Check that the second commit message is clean (not WIP, not with typos) $featureCommit = $commitArray[0] if ($featureCommit -match "WIP|wip") { Write-Host "[FAIL] Commit message still contains 'WIP'." -ForegroundColor Red Write-Host "Current message: '$featureCommit'" -ForegroundColor Yellow Write-Host "Hint: Create a clean, descriptive commit message." -ForegroundColor Yellow Set-Location .. exit 1 } if ($featureCommit -match "validaton") { Write-Host "[FAIL] Commit message contains a typo ('validaton')." -ForegroundColor Red Write-Host "Current message: '$featureCommit'" -ForegroundColor Yellow Write-Host "Hint: Use a properly spelled commit message." -ForegroundColor Yellow Set-Location .. exit 1 } # Check that commit message is not empty and has reasonable length if ($featureCommit.Length -lt 10) { Write-Host "[FAIL] Commit message is too short. Be more descriptive." -ForegroundColor Red Write-Host "Current message: '$featureCommit'" -ForegroundColor Yellow Set-Location .. exit 1 } # Check that required files exist if (-not (Test-Path "user_profile.py")) { Write-Host "[FAIL] user_profile.py not found." -ForegroundColor Red Set-Location .. exit 1 } if (-not (Test-Path "test_user_profile.py")) { Write-Host "[FAIL] test_user_profile.py not found." -ForegroundColor Red Set-Location .. exit 1 } # Check that user_profile.py contains all expected features $userProfileContent = Get-Content "user_profile.py" -Raw # Should have the class if ($userProfileContent -notmatch "class UserProfile") { Write-Host "[FAIL] user_profile.py should contain UserProfile class." -ForegroundColor Red Set-Location .. exit 1 } # Should have validation method if ($userProfileContent -notmatch "def validate\(") { Write-Host "[FAIL] user_profile.py should contain validate() method." -ForegroundColor Red Set-Location .. exit 1 } # Should have email format validation (the final fix from commit 3) if ($userProfileContent -notmatch "'@'.*in.*email|email.*in.*'@'") { Write-Host "[FAIL] user_profile.py should contain email format validation." -ForegroundColor Red Write-Host "Hint: Make sure all changes from all 4 commits are included." -ForegroundColor Yellow Set-Location .. exit 1 } # Check that test file has content $testContent = Get-Content "test_user_profile.py" -Raw if ($testContent -notmatch "class.*TestUserProfile") { Write-Host "[FAIL] test_user_profile.py should contain TestUserProfile tests." -ForegroundColor Red Set-Location .. exit 1 } # Check that we have at least 3 test cases $testMatches = ([regex]::Matches($testContent, "def test_")).Count if ($testMatches -lt 3) { Write-Host "[FAIL] test_user_profile.py should contain at least 3 test cases." -ForegroundColor Red Set-Location .. exit 1 } # Verify that the latest commit contains changes to both files $filesInLastCommit = git diff-tree --no-commit-id --name-only -r HEAD 2>$null if ($filesInLastCommit -notcontains "user_profile.py") { Write-Host "[FAIL] The feature commit should include user_profile.py" -ForegroundColor Red Set-Location .. exit 1 } if ($filesInLastCommit -notcontains "test_user_profile.py") { Write-Host "[FAIL] The feature commit should include test_user_profile.py" -ForegroundColor Red Set-Location .. exit 1 } # Success! Write-Host "`n========================================" -ForegroundColor Green Write-Host "SUCCESS! Challenge completed!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "`nYou have successfully:" -ForegroundColor Cyan Write-Host "- Combined 4 messy commits into 1 clean commit" -ForegroundColor White Write-Host "- Created a descriptive commit message" -ForegroundColor White Write-Host "- Preserved all code changes" -ForegroundColor White Write-Host "- Cleaned up the commit history" -ForegroundColor White Write-Host "`nYour commit history is now clean and professional!" -ForegroundColor Green Write-Host "Run 'git log --oneline' to see the result.`n" -ForegroundColor Cyan Write-Host "Key takeaway: Clean commit history makes code review easier" -ForegroundColor Yellow Write-Host "and your project more maintainable.`n" -ForegroundColor Yellow Set-Location .. exit 0