#!/usr/bin/env pwsh <# .SYNOPSIS Verifies the Module 04 challenge solution. .DESCRIPTION This script checks that you've successfully resolved the merge conflict by: - Merging both branches into main - Resolving the conflict in config.json - Keeping both timeout and debug settings - Ensuring valid JSON syntax #> . "$PSScriptRoot\..\..\util.ps1" $script:allChecksPassed = $true $challengeRoot = "$PSScriptRoot\challenge" Write-Host $PSScriptRoot # ============================================================================ # Check challenge directory exists # ============================================================================ if (-not (Test-Path $challengeRoot)) { Write-Error "Challenge directory not found." -ForegroundColor Red Write-Host "Run .\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow exit 1 } if (-not (Test-Path "$challengeRoot\.git")) { Write-Error "Not a git repository." -ForegroundColor Red Write-Host "Run ..\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow exit 1 } Write-Host "`n=== Verifying Module 04: Merge Conflicts ===" -ForegroundColor Cyan # ============================================================================ # Detect the main branch name (could be main, master, etc.) # ============================================================================ # Try to get the default branch from remote origin first $mainBranch = Get-MainBranch Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan # ============================================================================ # Check current branch # ============================================================================ $currentBranch = git branch --show-current 2>$null if ($currentBranch -eq $mainBranch) { Write-Pass "Currently on $mainBranch branch" } else { Write-Fail "Should be on $mainBranch branch (currently on: $currentBranch)" Write-Hint "Switch to $mainBranch with: git switch $mainBranch" } # ============================================================================ # Check that merge is not in progress # ============================================================================ if (Test-Path "$challengeRoot/.git/MERGE_HEAD") { Write-Fail "Merge is still in progress (conflicts not resolved)" Write-Hint "Resolve conflicts in config.json, then: git add config.json && git commit" exit 1 } else { Write-Pass "No merge in progress (conflicts resolved)" } # ============================================================================ # Check if config.json exists # ============================================================================ if (-not (Test-Path "$challengeRoot\config.json")) { Write-Fail "File 'config.json' not found" Write-Hint "The config.json file should exist" exit 1 } # ============================================================================ # Verify config.json is valid JSON # ============================================================================ try { $configContent = Get-Content "$challengeRoot\config.json" -Raw $config = $configContent | ConvertFrom-Json -ErrorAction Stop Write-Pass "File 'config.json' is valid JSON" } catch { Write-Fail "File 'config.json' is not valid JSON" Write-Hint "Make sure you removed all conflict markers (<<<<<<<, =======, >>>>>>>)" Write-Hint "Check for missing commas or brackets" Pop-Location exit 1 } # ============================================================================ # Check for conflict markers # ============================================================================ if ($configContent -match '<<<<<<<|=======|>>>>>>>') { Write-Fail "Conflict markers still present in config.json" Write-Hint "Remove all conflict markers (<<<<<<<, =======, >>>>>>>)" Pop-Location exit 1 } else { Write-Pass "No conflict markers in config.json" } # ============================================================================ # Verify both settings are present (timeout and debug) # ============================================================================ if ($config.app.timeout -eq 5000) { Write-Pass "Timeout setting preserved (5000)" } else { Write-Fail "Timeout setting missing or incorrect" Write-Hint "Keep the timeout: 5000 setting from add-timeout branch" } if ($config.app.debug -eq $true) { Write-Pass "Debug setting preserved (true)" } else { Write-Fail "Debug setting missing or incorrect" Write-Hint "Keep the debug: true setting from add-debug branch" } # ============================================================================ # Verify both branches were merged # ============================================================================ git merge-base --is-ancestor add-timeout main $addTimeoutMerged = $LASTEXITCODE -eq 0 git merge-base --is-ancestor add-debug main $addDebugMerged = $LASTEXITCODE -eq 0 if ($addTimeoutMerged) { Write-Pass "add-timeout branch has been merged" } else { # Check if it was a fast-forward merge (commits exist but no merge commit) $timeoutCommit = git log --oneline --grep="Add timeout configuration" 2>$null if ($timeoutCommit) { Write-Pass "add-timeout branch changes are in main" } else { Write-Fail "add-timeout branch not merged" Write-Hint "Merge with: git merge add-timeout" } } if ($addDebugMerged) { Write-Pass "add-debug branch has been merged" } else { Write-Fail "add-debug branch not merged" Write-Hint "Merge with: git merge add-debug" } # ============================================================================ # Check commit count (should have both merges) # ============================================================================ $totalCommits = [int](git rev-list --count HEAD 2>$null) if ($totalCommits -ge 5) { Write-Pass "Repository has $totalCommits commits (all merges complete)" } else { Write-Info "Repository has $totalCommits commits" Write-Hint "Make sure both branches are merged" } Pop-Location # ============================================================================ # Final summary # ============================================================================ Write-Host "" if ($script:allChecksPassed) { Write-Host "=========================================" -ForegroundColor Green Write-Host " CONGRATULATIONS! CHALLENGE PASSED!" -ForegroundColor Green Write-Host "=========================================" -ForegroundColor Green Write-Host "`nYou've successfully:" -ForegroundColor Cyan Write-Host " ✓ Discovered changes using git diff" -ForegroundColor White Write-Host " ✓ Merged the first branch" -ForegroundColor White Write-Host " ✓ Encountered a merge conflict" -ForegroundColor White Write-Host " ✓ Resolved the conflict by keeping both changes" -ForegroundColor White Write-Host " ✓ Completed the merge" -ForegroundColor White Write-Host "`nYou're now ready to handle merge conflicts in real projects!" -ForegroundColor Green Write-Host "" exit 0 } else { Write-Host "[SUMMARY] Some checks failed. Review the hints above." -ForegroundColor Red Write-Host "" Write-Host "Quick guide:" -ForegroundColor Cyan Write-Host " 1. Make sure you're on $mainBranch : git switch $mainBranch" -ForegroundColor White Write-Host " 2. Merge first branch: git merge add-timeout" -ForegroundColor White Write-Host " 3. Merge second branch: git merge add-debug" -ForegroundColor White Write-Host " 4. Resolve conflict: edit config.json, remove markers, keep both settings" -ForegroundColor White Write-Host " 5. Stage resolved file: git add config.json" -ForegroundColor White Write-Host " 6. Complete merge: git commit" -ForegroundColor White Write-Host " 7. Run this verify script again" -ForegroundColor White Write-Host "" exit 1 }