refactor: use the new utils.ps1 script for operations
This commit is contained in:
@@ -11,35 +11,35 @@
|
|||||||
- Committed both required files (welcome.txt and instructions.txt)
|
- Committed both required files (welcome.txt and instructions.txt)
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
. "$PSScriptRoot\..\..\util.ps1"
|
||||||
|
|
||||||
Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan
|
Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
$allChecksPassed = $true
|
$allChecksPassed = $true
|
||||||
|
$challengeRoot = "$PSScriptRoot\challenge"
|
||||||
|
|
||||||
# Check if challenge directory exists
|
# Check if challenge directory exists
|
||||||
if (-not (Test-Path "challenge")) {
|
if (-not (Test-Path $challengeRoot)) {
|
||||||
Write-Host "[FAIL] Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
Write-Fail "Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location "challenge"
|
|
||||||
|
|
||||||
# Check if git repository exists
|
# Check if git repository exists
|
||||||
if (-not (Test-Path ".git")) {
|
if (-not (Test-Path "$challengeRoot\.git")) {
|
||||||
Write-Host "[FAIL] No git repository found. Did you run 'git init'?" -ForegroundColor Red
|
Write-Fail "No git repository found. Did you run 'git init'?" -ForegroundColor Red
|
||||||
Set-Location ".."
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "[PASS] Git repository initialized" -ForegroundColor Green
|
Write-Pass "Git repository initialized" -ForegroundColor Green
|
||||||
|
|
||||||
# Check if there are any commits
|
# Check if there are any commits
|
||||||
$commitCount = (git rev-list --all --count 2>$null)
|
$commitCount = (git rev-list --all --count 2>$null)
|
||||||
if ($null -eq $commitCount -or $commitCount -eq 0) {
|
if ($null -eq $commitCount -or $commitCount -eq 0) {
|
||||||
Write-Host "[FAIL] No commits found. Have you committed your changes?" -ForegroundColor Red
|
Write-Fail "No commits found. Have you committed your changes?" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[PASS] Found $commitCount commit(s)" -ForegroundColor Green
|
Write-Pass "Found $commitCount commit(s)" -ForegroundColor Green
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if both files are in the git history using git ls-tree
|
# Check if both files are in the git history using git ls-tree
|
||||||
@@ -47,16 +47,16 @@ if ($commitCount -gt 0) {
|
|||||||
$trackedFiles = git ls-tree -r HEAD --name-only 2>$null
|
$trackedFiles = git ls-tree -r HEAD --name-only 2>$null
|
||||||
|
|
||||||
if ($trackedFiles -match "welcome.txt") {
|
if ($trackedFiles -match "welcome.txt") {
|
||||||
Write-Host "[PASS] welcome.txt is committed" -ForegroundColor Green
|
Write-Pass "welcome.txt is committed" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] welcome.txt is not in the commit history" -ForegroundColor Red
|
Write-Fail "welcome.txt is not in the commit history" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($trackedFiles -match "instructions.txt") {
|
if ($trackedFiles -match "instructions.txt") {
|
||||||
Write-Host "[PASS] instructions.txt is committed" -ForegroundColor Green
|
Write-Pass "instructions.txt is committed" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] instructions.txt is not in the commit history" -ForegroundColor Red
|
Write-Fail "instructions.txt is not in the commit history" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,8 +67,6 @@ if ($statusOutput) {
|
|||||||
Write-Host "[INFO] You have uncommitted changes. This is OK, but make sure all required files are committed." -ForegroundColor Yellow
|
Write-Host "[INFO] You have uncommitted changes. This is OK, but make sure all required files are committed." -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location ".."
|
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
if ($allChecksPassed) {
|
if ($allChecksPassed) {
|
||||||
Write-Host "========================================" -ForegroundColor Green
|
Write-Host "========================================" -ForegroundColor Green
|
||||||
|
|||||||
@@ -10,52 +10,53 @@
|
|||||||
- answers.txt exists with correct information about commit history
|
- answers.txt exists with correct information about commit history
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
. "$PSScriptRoot\..\..\util.ps1"
|
||||||
|
|
||||||
Write-Host "`n=== Verifying Module 02 Solution ===" -ForegroundColor Cyan
|
Write-Host "`n=== Verifying Module 02 Solution ===" -ForegroundColor Cyan
|
||||||
|
|
||||||
$allChecksPassed = $true
|
$allChecksPassed = $true
|
||||||
|
$challengeRoot = "$PSScriptRoot\challenge"
|
||||||
|
|
||||||
|
|
||||||
# Check if challenge directory exists
|
# Check if challenge directory exists
|
||||||
if (-not (Test-Path "challenge")) {
|
if (-not (Test-Path $challengeRoot)) {
|
||||||
Write-Host "[FAIL] Challenge directory not found. Did you run setup.ps1?" -ForegroundColor Red
|
Write-Fail "Challenge directory not found. Did you run setup.ps1?" -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location "challenge"
|
|
||||||
|
|
||||||
# Check if git repository exists
|
# Check if git repository exists
|
||||||
if (-not (Test-Path ".git")) {
|
if (-not (Test-Path "$challengeRoot\.git")) {
|
||||||
Write-Host "[FAIL] Not a git repository. Did you run setup.ps1?" -ForegroundColor Red
|
Write-Fail "Not a git repository. Did you run setup.ps1?" -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if answers.md exists
|
# Check if answers.md exists
|
||||||
if (-not (Test-Path "answers.md")) {
|
if (-not (Test-Path "$challengeRoot\answers.md")) {
|
||||||
Write-Host "[FAIL] answers.md not found. Did you run setup.ps1?" -ForegroundColor Red
|
Write-Fail "answers.md not found. Did you run setup.ps1?" -ForegroundColor Red
|
||||||
Write-Host "[HINT] The setup script should have created answers.md for you" -ForegroundColor Yellow
|
Write-Hint "The setup script should have created answers.md for you" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[PASS] answers.md exists" -ForegroundColor Green
|
Write-Pass "answers.md exists" -ForegroundColor Green
|
||||||
|
|
||||||
# Read the answers file
|
# Read the answers file
|
||||||
$answers = Get-Content "answers.md" -Raw
|
$answers = Get-Content "$challengeRoot\answers.md" -Raw
|
||||||
$answersLower = $answers.ToLower()
|
$answersLower = $answers.ToLower()
|
||||||
|
|
||||||
# Check 1: Contains "5" or "five" for commit count
|
# Check 1: Contains "5" or "five" for commit count
|
||||||
if ($answersLower -match "5|five|fem") {
|
if ($answersLower -match "5|five|fem") {
|
||||||
Write-Host "[PASS] Correct commit count found" -ForegroundColor Green
|
Write-Pass "Correct commit count found" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Commit count not found or incorrect" -ForegroundColor Red
|
Write-Fail "Commit count not found or incorrect" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Use 'git log --oneline' to count commits easily" -ForegroundColor Yellow
|
Write-Hint "Use 'git log --oneline' to count commits easily" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check 2: Contains "database" keyword for third commit
|
# Check 2: Contains "database" keyword for third commit
|
||||||
if ($answersLower -match "database") {
|
if ($answersLower -match "database") {
|
||||||
Write-Host "[PASS] Third commit message identified" -ForegroundColor Green
|
Write-Pass "Third commit message identified" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Third commit message not found" -ForegroundColor Red
|
Write-Fail "Third commit message not found" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Use 'git log' to see commit messages in order" -ForegroundColor Yellow
|
Write-Hint "Use 'git log' to see commit messages in order" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,38 +65,37 @@ if (-not (Test-Path "answers.md")) {
|
|||||||
$hasDatabase = $answersLower -match "database"
|
$hasDatabase = $answersLower -match "database"
|
||||||
|
|
||||||
if ($hasAuth -and $hasDatabase) {
|
if ($hasAuth -and $hasDatabase) {
|
||||||
Write-Host "[PASS] Both files identified for bug fix commit" -ForegroundColor Green
|
Write-Pass "Both files identified for bug fix commit" -ForegroundColor Green
|
||||||
} elseif ($hasAuth -or $hasDatabase) {
|
} elseif ($hasAuth -or $hasDatabase) {
|
||||||
Write-Host "[PARTIAL] Only one file found - there are TWO files modified in this commit" -ForegroundColor Yellow
|
Write-Host "[PARTIAL] Only one file found - there are TWO files modified in this commit" -ForegroundColor Yellow
|
||||||
Write-Host "[HINT] Use 'git log --stat' or 'git show <commit-hash> --name-only' to see ALL files changed" -ForegroundColor Yellow
|
Write-Hint "Use 'git log --stat' or 'git show <commit-hash> --name-only' to see ALL files changed" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Files modified in bug fix commit not found" -ForegroundColor Red
|
Write-Fail "Files modified in bug fix commit not found" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Use 'git log --stat' to see which files were changed in each commit" -ForegroundColor Yellow
|
Write-Hint "Use 'git log --stat' to see which files were changed in each commit" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check 4: Contains "config" keyword for staged file
|
# Check 4: Contains "config" keyword for staged file
|
||||||
if ($answersLower -match "config.py") {
|
if ($answersLower -match "config.py") {
|
||||||
Write-Host "[PASS] Staged file identified" -ForegroundColor Green
|
Write-Pass "Staged file identified" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Staged file not identified" -ForegroundColor Red
|
Write-Fail "Staged file not identified" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Use 'git status' or 'git diff --staged' to see staged changes" -ForegroundColor Yellow
|
Write-Hint "Use 'git status' or 'git diff --staged' to see staged changes" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check 5: Contains "unicorn" for the secret code
|
# Check 5: Contains "unicorn" for the secret code
|
||||||
if ($answersLower -match "unicorn") {
|
if ($answersLower -match "unicorn") {
|
||||||
Write-Host "[PASS] Secret code found!" -ForegroundColor Green
|
Write-Pass "Secret code found!" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Secret code not found" -ForegroundColor Red
|
Write-Fail "Secret code not found" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Use 'git diff <commit3> <commit4> database.py' to find the secret code" -ForegroundColor Yellow
|
Write-Hint "Use 'git diff <commit3> <commit4> database.py' to find the secret code" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location ..
|
|
||||||
|
|
||||||
# Final summary
|
# Final summary
|
||||||
if ($allChecksPassed) {
|
if ($allChecksPassed) {
|
||||||
|
|||||||
@@ -12,47 +12,20 @@
|
|||||||
|
|
||||||
$script:allChecksPassed = $true
|
$script:allChecksPassed = $true
|
||||||
|
|
||||||
# ============================================================================
|
$challengeRoot = "$PSScriptRoot\challenge"
|
||||||
# Helper Functions
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
function Write-Pass {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[PASS] $Message" -ForegroundColor Green
|
|
||||||
}
|
|
||||||
|
|
||||||
function Write-Fail {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[FAIL] $Message" -ForegroundColor Red
|
|
||||||
$script:allChecksPassed = $false
|
|
||||||
}
|
|
||||||
|
|
||||||
function Write-Hint {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[HINT] $Message" -ForegroundColor Yellow
|
|
||||||
}
|
|
||||||
|
|
||||||
function Write-Info {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[INFO] $Message" -ForegroundColor Cyan
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Check challenge directory exists
|
# Check challenge directory exists
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
if (-not (Test-Path "challenge")) {
|
if (-not (Test-Path $challengeRoot)) {
|
||||||
Write-Host "[ERROR] Challenge directory not found." -ForegroundColor Red
|
Write-Host "[ERROR] Challenge directory not found." -ForegroundColor Red
|
||||||
Write-Host "Run .\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
Write-Host "Run .\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Push-Location "challenge"
|
if (-not (Test-Path "$challengeRoot\.git")) {
|
||||||
|
|
||||||
if (-not (Test-Path ".git")) {
|
|
||||||
Write-Host "[ERROR] Not a git repository." -ForegroundColor Red
|
Write-Host "[ERROR] Not a git repository." -ForegroundColor Red
|
||||||
Write-Host "Run ..\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
Write-Host "Run ..\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
||||||
Pop-Location
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,24 +35,7 @@ Write-Host "`n=== Verifying Module 03: Branching and Merging ===" -ForegroundCol
|
|||||||
# Detect the main branch name (could be main, master, etc.)
|
# Detect the main branch name (could be main, master, etc.)
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Try to get the default branch from remote origin first
|
# Try to get the default branch from remote origin first
|
||||||
$mainBranch = git symbolic-ref refs/remotes/origin/HEAD 2>$null | Split-Path -Leaf
|
$mainBranch = Get-MainBranch
|
||||||
if (-not $mainBranch) {
|
|
||||||
# Fallback: try to detect from local branches
|
|
||||||
$allBranches = git branch --list 2>$null | ForEach-Object { $_.Trim('* ') }
|
|
||||||
if ($allBranches -contains "main") {
|
|
||||||
$mainBranch = "main"
|
|
||||||
} elseif ($allBranches -contains "master") {
|
|
||||||
$mainBranch = "master"
|
|
||||||
} else {
|
|
||||||
# Get the default branch from git config
|
|
||||||
$mainBranch = git config --get init.defaultBranch
|
|
||||||
if (-not $mainBranch) {
|
|
||||||
# Ultimate fallback: use the first branch
|
|
||||||
$mainBranch = $allBranches | Select-Object -First 1
|
|
||||||
if (-not $mainBranch) { $mainBranch = "main" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
@@ -11,39 +11,18 @@
|
|||||||
- Ensuring valid JSON syntax
|
- Ensuring valid JSON syntax
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
. "$PSScriptRoot\..\..\util.ps1"
|
||||||
|
|
||||||
$script:allChecksPassed = $true
|
$script:allChecksPassed = $true
|
||||||
|
|
||||||
# ============================================================================
|
Write-Host $PSScriptRoot
|
||||||
# Helper Functions
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
function Write-Pass {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[PASS] $Message" -ForegroundColor Green
|
|
||||||
}
|
|
||||||
|
|
||||||
function Write-Fail {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[FAIL] $Message" -ForegroundColor Red
|
|
||||||
$script:allChecksPassed = $false
|
|
||||||
}
|
|
||||||
|
|
||||||
function Write-Hint {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[HINT] $Message" -ForegroundColor Yellow
|
|
||||||
}
|
|
||||||
|
|
||||||
function Write-Info {
|
|
||||||
param([string]$Message)
|
|
||||||
Write-Host "[INFO] $Message" -ForegroundColor Cyan
|
|
||||||
}
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Check challenge directory exists
|
# Check challenge directory exists
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|
||||||
if (-not (Test-Path "challenge")) {
|
if (-not (Test-Path "challenge")) {
|
||||||
Write-Host "[ERROR] Challenge directory not found." -ForegroundColor Red
|
Write-Error "Challenge directory not found." -ForegroundColor Red
|
||||||
Write-Host "Run .\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
Write-Host "Run .\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -51,9 +30,8 @@ if (-not (Test-Path "challenge")) {
|
|||||||
Push-Location "challenge"
|
Push-Location "challenge"
|
||||||
|
|
||||||
if (-not (Test-Path ".git")) {
|
if (-not (Test-Path ".git")) {
|
||||||
Write-Host "[ERROR] Not a git repository." -ForegroundColor Red
|
Write-Error "Not a git repository." -ForegroundColor Red
|
||||||
Write-Host "Run ..\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
Write-Host "Run ..\setup.ps1 first to create the challenge environment." -ForegroundColor Yellow
|
||||||
Pop-Location
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,24 +41,7 @@ Write-Host "`n=== Verifying Module 04: Merge Conflicts ===" -ForegroundColor Cya
|
|||||||
# Detect the main branch name (could be main, master, etc.)
|
# Detect the main branch name (could be main, master, etc.)
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Try to get the default branch from remote origin first
|
# Try to get the default branch from remote origin first
|
||||||
$mainBranch = git symbolic-ref refs/remotes/origin/HEAD 2>$null | Split-Path -Leaf
|
$mainBranch = Get-MainBranch
|
||||||
if (-not $mainBranch) {
|
|
||||||
# Fallback: try to detect from local branches
|
|
||||||
$allBranches = git branch --list 2>$null | ForEach-Object { $_.Trim('* ') }
|
|
||||||
if ($allBranches -contains "main") {
|
|
||||||
$mainBranch = "main"
|
|
||||||
} elseif ($allBranches -contains "master") {
|
|
||||||
$mainBranch = "master"
|
|
||||||
} else {
|
|
||||||
# Get the default branch from git config
|
|
||||||
$mainBranch = git config --get init.defaultBranch
|
|
||||||
if (-not $mainBranch) {
|
|
||||||
# Ultimate fallback: use the first branch
|
|
||||||
$mainBranch = $allBranches | Select-Object -First 1
|
|
||||||
if (-not $mainBranch) { $mainBranch = "main" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
@@ -100,7 +61,6 @@ if ($currentBranch -eq $mainBranch) {
|
|||||||
if (Test-Path ".git/MERGE_HEAD") {
|
if (Test-Path ".git/MERGE_HEAD") {
|
||||||
Write-Fail "Merge is still in progress (conflicts not resolved)"
|
Write-Fail "Merge is still in progress (conflicts not resolved)"
|
||||||
Write-Hint "Resolve conflicts in config.json, then: git add config.json && git commit"
|
Write-Hint "Resolve conflicts in config.json, then: git add config.json && git commit"
|
||||||
Pop-Location
|
|
||||||
exit 1
|
exit 1
|
||||||
} else {
|
} else {
|
||||||
Write-Pass "No merge in progress (conflicts resolved)"
|
Write-Pass "No merge in progress (conflicts resolved)"
|
||||||
@@ -112,7 +72,6 @@ if (Test-Path ".git/MERGE_HEAD") {
|
|||||||
if (-not (Test-Path "config.json")) {
|
if (-not (Test-Path "config.json")) {
|
||||||
Write-Fail "File 'config.json' not found"
|
Write-Fail "File 'config.json' not found"
|
||||||
Write-Hint "The config.json file should exist"
|
Write-Hint "The config.json file should exist"
|
||||||
Pop-Location
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +79,7 @@ if (-not (Test-Path "config.json")) {
|
|||||||
# Verify config.json is valid JSON
|
# Verify config.json is valid JSON
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
try {
|
try {
|
||||||
$configContent = Get-Content "config.json" -Raw
|
$configContent = Get-Content "$challengeRoot\config.json" -Raw
|
||||||
$config = $configContent | ConvertFrom-Json -ErrorAction Stop
|
$config = $configContent | ConvertFrom-Json -ErrorAction Stop
|
||||||
Write-Pass "File 'config.json' is valid JSON"
|
Write-Pass "File 'config.json' is valid JSON"
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
the bug fixes to the main branch.
|
the bug fixes to the main branch.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
. "$PSScriptRoot\..\..\util.ps1"
|
||||||
|
|
||||||
# Remove existing challenge directory if present
|
# Remove existing challenge directory if present
|
||||||
if (Test-Path "challenge") {
|
if (Test-Path "challenge") {
|
||||||
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
||||||
@@ -42,11 +44,7 @@ git add app.py
|
|||||||
git commit -m "Initial app implementation" | Out-Null
|
git commit -m "Initial app implementation" | Out-Null
|
||||||
|
|
||||||
# Detect the main branch name after first commit
|
# Detect the main branch name after first commit
|
||||||
$mainBranch = git branch --show-current
|
$mainBranch = Get-MainBranch
|
||||||
if (-not $mainBranch) {
|
|
||||||
$mainBranch = git config --get init.defaultBranch
|
|
||||||
if (-not $mainBranch) { $mainBranch = "main" }
|
|
||||||
}
|
|
||||||
Write-Host "Default branch detected: $mainBranch" -ForegroundColor Yellow
|
Write-Host "Default branch detected: $mainBranch" -ForegroundColor Yellow
|
||||||
|
|
||||||
$readme = @"
|
$readme = @"
|
||||||
|
|||||||
@@ -9,168 +9,136 @@
|
|||||||
to the main branch without merging the experimental features.
|
to the main branch without merging the experimental features.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
Set-Location "challenge" -ErrorAction SilentlyContinue
|
. "$PSScriptRoot\..\..\util.ps1"
|
||||||
|
|
||||||
# Check if challenge directory exists
|
$challengeRoot = "$PSScriptRoot\challenge"
|
||||||
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 ".")) {
|
if (-not (Test-Path $challengeRoot)) {
|
||||||
Write-Host "Error: Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
Write-Host "Error: Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Verifying your solution..." -ForegroundColor Cyan
|
Write-Host "Verifying your solution..." -ForegroundColor Cyan
|
||||||
|
|
||||||
# Check if git repository exists
|
# Check if git repository exists
|
||||||
if (-not (Test-Path ".git")) {
|
if (-not (Test-Path "$challengeRoot\.git")) {
|
||||||
Write-Host "[FAIL] No git repository found." -ForegroundColor Red
|
Write-Fail "No git repository found." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Detect the main branch name
|
$mainBranch = Get-MainBranch
|
||||||
$allBranches = git branch --list 2>$null | ForEach-Object { $_.Trim('* ') }
|
|
||||||
if ($allBranches -contains "main") {
|
|
||||||
$mainBranch = "main"
|
|
||||||
} elseif ($allBranches -contains "master") {
|
|
||||||
$mainBranch = "master"
|
|
||||||
} else {
|
|
||||||
$mainBranch = git config --get init.defaultBranch
|
|
||||||
if (-not $mainBranch) {
|
|
||||||
$mainBranch = $allBranches | Select-Object -First 1
|
|
||||||
if (-not $mainBranch) { $mainBranch = "main" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
||||||
|
|
||||||
# Check current branch
|
# Check current branch
|
||||||
$currentBranch = git branch --show-current 2>$null
|
$currentBranch = git branch --show-current 2>$null
|
||||||
if ($currentBranch -ne $mainBranch) {
|
if ($currentBranch -ne $mainBranch) {
|
||||||
Write-Host "[FAIL] You should be on the '$mainBranch' branch." -ForegroundColor Red
|
Write-Fail "You should be on the '$mainBranch' branch." -ForegroundColor Red
|
||||||
Write-Host "Current branch: $currentBranch" -ForegroundColor Yellow
|
Write-Host "Current branch: $currentBranch" -ForegroundColor Yellow
|
||||||
Write-Host "Hint: Use 'git checkout $mainBranch' to switch to $mainBranch branch" -ForegroundColor Yellow
|
Write-Hint "Use 'git checkout $mainBranch' to switch to $mainBranch branch" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if there's an ongoing cherry-pick
|
# Check if there's an ongoing cherry-pick
|
||||||
if (Test-Path ".git/CHERRY_PICK_HEAD") {
|
if (Test-Path "$challengeRoot\.git\CHERRY_PICK_HEAD") {
|
||||||
Write-Host "[FAIL] Cherry-pick is not complete. There may be unresolved conflicts." -ForegroundColor Red
|
Write-Fail "Cherry-pick is not complete. There may be unresolved conflicts." -ForegroundColor Red
|
||||||
Write-Host "Hint: Resolve any conflicts, then use:" -ForegroundColor Yellow
|
Write-Hint "Resolve any conflicts, then use:" -ForegroundColor Yellow
|
||||||
Write-Host " git add <file>" -ForegroundColor White
|
Write-Host " git add <file>" -ForegroundColor White
|
||||||
Write-Host " git cherry-pick --continue" -ForegroundColor White
|
Write-Host " git cherry-pick --continue" -ForegroundColor White
|
||||||
Write-Host "Or abort with: git cherry-pick --abort" -ForegroundColor White
|
Write-Host "Or abort with: git cherry-pick --abort" -ForegroundColor White
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check commit count on main (should be 4: 2 initial + 2 cherry-picked)
|
# Check commit count on main (should be 4: 2 initial + 2 cherry-picked)
|
||||||
$mainCommitCount = (git rev-list --count $mainBranch 2>$null)
|
$mainCommitCount = (git rev-list --count $mainBranch 2>$null)
|
||||||
if ($mainCommitCount -ne 4) {
|
if ($mainCommitCount -ne 4) {
|
||||||
Write-Host "[FAIL] Expected 4 commits on $mainBranch branch, found $mainCommitCount" -ForegroundColor Red
|
Write-Fail "Expected 4 commits on $mainBranch branch, found $mainCommitCount" -ForegroundColor Red
|
||||||
if ($mainCommitCount -lt 4) {
|
if ($mainCommitCount -lt 4) {
|
||||||
Write-Host "Hint: You should cherry-pick 2 bug fix commits to $mainBranch" -ForegroundColor Yellow
|
Write-Hint "You should cherry-pick 2 bug fix commits to $mainBranch" -ForegroundColor Yellow
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Hint: You should cherry-pick ONLY the 2 bug fix commits, not all commits" -ForegroundColor Yellow
|
Write-Hint "You should cherry-pick ONLY the 2 bug fix commits, not all commits" -ForegroundColor Yellow
|
||||||
}
|
}
|
||||||
Write-Host "`nExpected commits on ${mainBranch}:" -ForegroundColor Yellow
|
Write-Host "`nExpected commits on ${mainBranch}:" -ForegroundColor Yellow
|
||||||
Write-Host " 1. Initial app implementation" -ForegroundColor White
|
Write-Host " 1. Initial app implementation" -ForegroundColor White
|
||||||
Write-Host " 2. Add README" -ForegroundColor White
|
Write-Host " 2. Add README" -ForegroundColor White
|
||||||
Write-Host " 3. Fix security vulnerability in input validation (cherry-picked)" -ForegroundColor White
|
Write-Host " 3. Fix security vulnerability in input validation (cherry-picked)" -ForegroundColor White
|
||||||
Write-Host " 4. Fix performance issue with data caching (cherry-picked)" -ForegroundColor White
|
Write-Host " 4. Fix performance issue with data caching (cherry-picked)" -ForegroundColor White
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for merge commits (should be none - cherry-pick doesn't create merge commits)
|
# Check for merge commits (should be none - cherry-pick doesn't create merge commits)
|
||||||
$mergeCommits = git log --merges --oneline $mainBranch 2>$null
|
$mergeCommits = git log --merges --oneline $mainBranch 2>$null
|
||||||
if ($mergeCommits) {
|
if ($mergeCommits) {
|
||||||
Write-Host "[FAIL] Found merge commits on $mainBranch. You should use cherry-pick, not merge." -ForegroundColor Red
|
Write-Fail "Found merge commits on $mainBranch. You should use cherry-pick, not merge." -ForegroundColor Red
|
||||||
Write-Host "Hint: Use 'git cherry-pick <commit-hash>' instead of 'git merge'" -ForegroundColor Yellow
|
Write-Hint "Use 'git cherry-pick <commit-hash>' instead of 'git merge'" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that security.py exists (from the security fix commit)
|
# Check that security.py exists (from the security fix commit)
|
||||||
if (-not (Test-Path "security.py")) {
|
if (-not (Test-Path "$challengeRoot\security.py")) {
|
||||||
Write-Host "[FAIL] security.py not found on $mainBranch branch." -ForegroundColor Red
|
Write-Fail "security.py not found on $mainBranch branch." -ForegroundColor Red
|
||||||
Write-Host "Hint: You need to cherry-pick the 'Fix security vulnerability' commit" -ForegroundColor Yellow
|
Write-Hint "You need to cherry-pick the 'Fix security vulnerability' commit" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that security.py has the security fix
|
# Check that security.py has the security fix
|
||||||
$securityContent = Get-Content "security.py" -Raw
|
$securityContent = Get-Content "$challengeRoot\security.py" -Raw
|
||||||
|
|
||||||
if ($securityContent -notmatch "sanitize_input") {
|
if ($securityContent -notmatch "sanitize_input") {
|
||||||
Write-Host "[FAIL] security.py is missing the sanitize_input function." -ForegroundColor Red
|
Write-Fail "security.py is missing the sanitize_input function." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($securityContent -notmatch "validate_token") {
|
if ($securityContent -notmatch "validate_token") {
|
||||||
Write-Host "[FAIL] security.py is missing the validate_token function." -ForegroundColor Red
|
Write-Fail "security.py is missing the validate_token function." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that app.py exists
|
# Check that app.py exists
|
||||||
if (-not (Test-Path "app.py")) {
|
if (-not (Test-Path "$challengeRoot\app.py")) {
|
||||||
Write-Host "[FAIL] app.py not found." -ForegroundColor Red
|
Write-Fail "app.py not found." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that cache.py exists (from performance fix)
|
# Check that cache.py exists (from performance fix)
|
||||||
if (-not (Test-Path "cache.py")) {
|
if (-not (Test-Path "$challengeRoot\cache.py")) {
|
||||||
Write-Host "[FAIL] cache.py not found on $mainBranch branch." -ForegroundColor Red
|
Write-Fail "cache.py not found on $mainBranch branch." -ForegroundColor Red
|
||||||
Write-Host "Hint: You need to cherry-pick the 'Fix performance issue' commit" -ForegroundColor Yellow
|
Write-Hint "You need to cherry-pick the 'Fix performance issue' commit" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that cache.py has the DataCache class
|
# Check that cache.py has the DataCache class
|
||||||
$cacheContent = Get-Content "cache.py" -Raw
|
$cacheContent = Get-Content "$challengeRoot\cache.py" -Raw
|
||||||
|
|
||||||
if ($cacheContent -notmatch "DataCache") {
|
if ($cacheContent -notmatch "DataCache") {
|
||||||
Write-Host "[FAIL] cache.py is missing the DataCache class." -ForegroundColor Red
|
Write-Fail "cache.py is missing the DataCache class." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cacheContent -notmatch "def get\(") {
|
if ($cacheContent -notmatch "def get\(") {
|
||||||
Write-Host "[FAIL] cache.py is missing the get method." -ForegroundColor Red
|
Write-Fail "cache.py is missing the get method." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that app.py does NOT have experimental features
|
# Check that app.py does NOT have experimental features
|
||||||
$appContent = Get-Content "app.py" -Raw
|
$appContent = Get-Content "$challengeRoot\app.py" -Raw
|
||||||
|
|
||||||
# Should NOT have experimental features
|
# Should NOT have experimental features
|
||||||
if ($appContent -match "experimental_mode") {
|
if ($appContent -match "experimental_mode") {
|
||||||
Write-Host "[FAIL] app.py contains experimental features (experimental_mode)." -ForegroundColor Red
|
Write-Fail "app.py contains experimental features (experimental_mode)." -ForegroundColor Red
|
||||||
Write-Host "Hint: You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
|
Write-Hint "You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
|
||||||
Write-Host " The experimental feature commits should stay on development branch only" -ForegroundColor Yellow
|
Write-Host " The experimental feature commits should stay on development branch only" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($appContent -match "beta_features") {
|
if ($appContent -match "beta_features") {
|
||||||
Write-Host "[FAIL] app.py contains experimental features (beta_features)." -ForegroundColor Red
|
Write-Fail "app.py contains experimental features (beta_features)." -ForegroundColor Red
|
||||||
Write-Host "Hint: You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
|
Write-Hint "You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($appContent -match "enable_experimental_features") {
|
if ($appContent -match "enable_experimental_features") {
|
||||||
Write-Host "[FAIL] app.py contains experimental features (enable_experimental_features)." -ForegroundColor Red
|
Write-Fail "app.py contains experimental features (enable_experimental_features)." -ForegroundColor Red
|
||||||
Write-Host "Hint: You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
|
Write-Hint "You should cherry-pick ONLY the bug fixes, not experimental features" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,25 +159,22 @@ foreach ($commit in $commitArray) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (-not $hasSecurityFix) {
|
if (-not $hasSecurityFix) {
|
||||||
Write-Host "[FAIL] Security fix commit not found on $mainBranch branch." -ForegroundColor Red
|
Write-Fail "Security fix commit not found on $mainBranch branch." -ForegroundColor Red
|
||||||
Write-Host "Hint: Cherry-pick the 'Fix security vulnerability' commit from development" -ForegroundColor Yellow
|
Write-Hint "Cherry-pick the 'Fix security vulnerability' commit from development" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not $hasPerformanceFix) {
|
if (-not $hasPerformanceFix) {
|
||||||
Write-Host "[FAIL] Performance fix commit not found on $mainBranch branch." -ForegroundColor Red
|
Write-Fail "Performance fix commit not found on $mainBranch branch." -ForegroundColor Red
|
||||||
Write-Host "Hint: Cherry-pick the 'Fix performance issue' commit from development" -ForegroundColor Yellow
|
Write-Hint "Cherry-pick the 'Fix performance issue' commit from development" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Verify development branch still has all commits
|
# Verify development branch still has all commits
|
||||||
$devCommitCount = (git rev-list --count development 2>$null)
|
$devCommitCount = (git rev-list --count development 2>$null)
|
||||||
if ($devCommitCount -ne 6) {
|
if ($devCommitCount -ne 6) {
|
||||||
Write-Host "[FAIL] Development branch should still have 6 commits." -ForegroundColor Red
|
Write-Fail "Development branch should still have 6 commits." -ForegroundColor Red
|
||||||
Write-Host "Found: $devCommitCount commits" -ForegroundColor Yellow
|
Write-Host "Found: $devCommitCount commits" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,5 +191,4 @@ Write-Host "`nPerfect use of cherry-pick!" -ForegroundColor Green
|
|||||||
Write-Host "You selectively applied critical fixes without merging unfinished features.`n" -ForegroundColor Green
|
Write-Host "You selectively applied critical fixes without merging unfinished features.`n" -ForegroundColor Green
|
||||||
Write-Host "Try 'git log --oneline --graph --all' to see both branches." -ForegroundColor Cyan
|
Write-Host "Try 'git log --oneline --graph --all' to see both branches." -ForegroundColor Cyan
|
||||||
|
|
||||||
Set-Location ..
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -9,23 +9,23 @@
|
|||||||
- multi-revert: Multiple commits reverted
|
- multi-revert: Multiple commits reverted
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
. "$PSScriptRoot\..\..\util.ps1"
|
||||||
|
|
||||||
Write-Host "`n=== Verifying Module 06: Git Revert Solutions ===" -ForegroundColor Cyan
|
Write-Host "`n=== Verifying Module 06: Git Revert Solutions ===" -ForegroundColor Cyan
|
||||||
|
|
||||||
$allChecksPassed = $true
|
$allChecksPassed = $true
|
||||||
$originalDir = Get-Location
|
|
||||||
|
$challengeRoot = "$PSScriptRoot\challenge"
|
||||||
|
|
||||||
# Check if challenge directory exists
|
# Check if challenge directory exists
|
||||||
if (-not (Test-Path "challenge")) {
|
if (-not (Test-Path "$challengeRoot")) {
|
||||||
Write-Host "[FAIL] Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
Write-Fail "Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location "challenge"
|
|
||||||
|
|
||||||
# Check if git repository exists
|
# Check if git repository exists
|
||||||
if (-not (Test-Path ".git")) {
|
if (-not (Test-Path "$challengeRoot\.git")) {
|
||||||
Write-Host "[FAIL] Not a git repository. Run setup.ps1 first." -ForegroundColor Red
|
Write-Fail "Not a git repository. Run setup.ps1 first." -ForegroundColor Red
|
||||||
Set-Location $originalDir
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,50 +37,50 @@ Write-Host "`n=== Scenario 1: Regular Revert ===" -ForegroundColor Cyan
|
|||||||
git switch regular-revert 2>&1 | Out-Null
|
git switch regular-revert 2>&1 | Out-Null
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "[FAIL] regular-revert branch not found" -ForegroundColor Red
|
Write-Fail "regular-revert branch not found" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
} else {
|
} else {
|
||||||
# Check that a revert commit exists
|
# Check that a revert commit exists
|
||||||
$revertCommit = git log --oneline --grep="Revert" 2>$null
|
$revertCommit = git log --oneline --grep="Revert" 2>$null
|
||||||
if ($revertCommit) {
|
if ($revertCommit) {
|
||||||
Write-Host "[PASS] Revert commit found" -ForegroundColor Green
|
Write-Pass "Revert commit found" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] No revert commit found" -ForegroundColor Red
|
Write-Fail "No revert commit found" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Use: git revert <commit-hash>" -ForegroundColor Yellow
|
Write-Hint "Use: git revert <commit-hash>" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that divide.py is removed (was reverted)
|
# Check that divide.py is removed (was reverted)
|
||||||
if (-not (Test-Path "divide.py")) {
|
if (-not (Test-Path "$challengeRoot\divide.py")) {
|
||||||
Write-Host "[PASS] Broken divide.py successfully reverted (file removed)" -ForegroundColor Green
|
Write-Pass "Broken divide.py successfully reverted (file removed)" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] divide.py still exists (should be reverted)" -ForegroundColor Red
|
Write-Fail "divide.py still exists (should be reverted)" -ForegroundColor Red
|
||||||
Write-Host "[HINT] The bad commit should be reverted, removing divide.py" -ForegroundColor Yellow
|
Write-Hint "The bad commit should be reverted, removing divide.py" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that calculator.py exists and has correct content
|
# Check that calculator.py exists and has correct content
|
||||||
if (Test-Path "calculator.py") {
|
if (Test-Path "$challengeRoot\calculator.py") {
|
||||||
$calcContent = Get-Content "calculator.py" -Raw
|
$calcContent = Get-Content "$challengeRoot\calculator.py" -Raw
|
||||||
|
|
||||||
# Check that modulo function still exists (should be preserved)
|
# Check that modulo function still exists (should be preserved)
|
||||||
if ($calcContent -match "def modulo") {
|
if ($calcContent -match "def modulo") {
|
||||||
Write-Host "[PASS] modulo function preserved (good commit after bad one)" -ForegroundColor Green
|
Write-Pass "modulo function preserved (good commit after bad one)" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] modulo function missing (should still exist)" -ForegroundColor Red
|
Write-Fail "modulo function missing (should still exist)" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Only revert the bad commit, not the good ones after it" -ForegroundColor Yellow
|
Write-Hint "Only revert the bad commit, not the good ones after it" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that multiply function exists (should be preserved)
|
# Check that multiply function exists (should be preserved)
|
||||||
if ($calcContent -match "def multiply") {
|
if ($calcContent -match "def multiply") {
|
||||||
Write-Host "[PASS] multiply function preserved (good commit before bad one)" -ForegroundColor Green
|
Write-Pass "multiply function preserved (good commit before bad one)" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] multiply function missing" -ForegroundColor Red
|
Write-Fail "multiply function missing" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] calculator.py not found" -ForegroundColor Red
|
Write-Fail "calculator.py not found" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ Write-Host "`n=== Scenario 2: Multi Revert ===" -ForegroundColor Cyan
|
|||||||
git switch multi-revert 2>&1 | Out-Null
|
git switch multi-revert 2>&1 | Out-Null
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "[FAIL] multi-revert branch not found" -ForegroundColor Red
|
Write-Fail "multi-revert branch not found" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
} else {
|
} else {
|
||||||
# Count revert commits
|
# Count revert commits
|
||||||
@@ -101,56 +101,54 @@ if ($LASTEXITCODE -ne 0) {
|
|||||||
$revertCount = ($revertCommits | Measure-Object).Count
|
$revertCount = ($revertCommits | Measure-Object).Count
|
||||||
|
|
||||||
if ($revertCount -ge 2) {
|
if ($revertCount -ge 2) {
|
||||||
Write-Host "[PASS] Found $revertCount revert commits (expected at least 2)" -ForegroundColor Green
|
Write-Pass "Found $revertCount revert commits (expected at least 2)" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] Found only $revertCount revert commit(s), need at least 2" -ForegroundColor Red
|
Write-Fail "Found only $revertCount revert commit(s), need at least 2" -ForegroundColor Red
|
||||||
Write-Host "[HINT] Revert both bad commits: git revert <commit1> <commit2>" -ForegroundColor Yellow
|
Write-Hint "Revert both bad commits: git revert <commit1> <commit2>" -ForegroundColor Yellow
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that sqrt.py is removed (reverted)
|
# Check that sqrt.py is removed (reverted)
|
||||||
if (-not (Test-Path "sqrt.py")) {
|
if (-not (Test-Path "$challengeRoot\sqrt.py")) {
|
||||||
Write-Host "[PASS] Broken sqrt.py successfully reverted (file removed)" -ForegroundColor Green
|
Write-Pass "Broken sqrt.py successfully reverted (file removed)" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] sqrt.py still exists (should be reverted)" -ForegroundColor Red
|
Write-Fail "sqrt.py still exists (should be reverted)" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that logarithm.py is removed (reverted)
|
# Check that logarithm.py is removed (reverted)
|
||||||
if (-not (Test-Path "logarithm.py")) {
|
if (-not (Test-Path "$challengeRoot\logarithm.py")) {
|
||||||
Write-Host "[PASS] Broken logarithm.py successfully reverted (file removed)" -ForegroundColor Green
|
Write-Pass "Broken logarithm.py successfully reverted (file removed)" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] logarithm.py still exists (should be reverted)" -ForegroundColor Red
|
Write-Fail "logarithm.py still exists (should be reverted)" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check calculator.py content
|
# Check calculator.py content
|
||||||
if (Test-Path "calculator.py") {
|
if (Test-Path "$challengeRoot\calculator.py") {
|
||||||
$calcContent = Get-Content "calculator.py" -Raw
|
$calcContent = Get-Content "$challengeRoot\calculator.py" -Raw
|
||||||
|
|
||||||
# Check that power function still exists (good commit before bad ones)
|
# Check that power function still exists (good commit before bad ones)
|
||||||
if ($calcContent -match "def power") {
|
if ($calcContent -match "def power") {
|
||||||
Write-Host "[PASS] power function preserved" -ForegroundColor Green
|
Write-Pass "power function preserved" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] power function missing (should still exist)" -ForegroundColor Red
|
Write-Fail "power function missing (should still exist)" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that absolute function still exists (good commit after bad ones)
|
# Check that absolute function still exists (good commit after bad ones)
|
||||||
if ($calcContent -match "def absolute") {
|
if ($calcContent -match "def absolute") {
|
||||||
Write-Host "[PASS] absolute function preserved" -ForegroundColor Green
|
Write-Pass "absolute function preserved" -ForegroundColor Green
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] absolute function missing (should still exist)" -ForegroundColor Red
|
Write-Fail "absolute function missing (should still exist)" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Write-Host "[FAIL] calculator.py not found" -ForegroundColor Red
|
Write-Fail "calculator.py not found" -ForegroundColor Red
|
||||||
$allChecksPassed = $false
|
$allChecksPassed = $false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-Location $originalDir
|
|
||||||
|
|
||||||
# Final summary
|
# Final summary
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
if ($allChecksPassed) {
|
if ($allChecksPassed) {
|
||||||
|
|||||||
@@ -9,48 +9,28 @@
|
|||||||
and completed the feature on the feature branch.
|
and completed the feature on the feature branch.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
Set-Location "challenge" -ErrorAction SilentlyContinue
|
$root = $PSScriptRoot
|
||||||
|
|
||||||
# Check if challenge directory exists
|
if (-not (Test-Path "$root/challenge")) {
|
||||||
if (-not (Test-Path "../verify.ps1")) {
|
Write-Error "Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red
|
||||||
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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Verifying your solution..." -ForegroundColor Cyan
|
Write-Host "Verifying your solution..." -ForegroundColor Cyan
|
||||||
|
|
||||||
# Check if git repository exists
|
# Check if git repository exists
|
||||||
if (-not (Test-Path ".git")) {
|
if (-not (Test-Path "$root/challenge/.git")) {
|
||||||
Write-Host "[FAIL] No git repository found." -ForegroundColor Red
|
Write-Fail "No git repository found." -ForegroundColor Red
|
||||||
Set-Location ..
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Detect the main branch name
|
$mainBranch = Get-MainBranch
|
||||||
$allBranches = git branch --list 2>$null | ForEach-Object { $_.Trim('* ') }
|
|
||||||
if ($allBranches -contains "main") {
|
|
||||||
$mainBranch = "main"
|
|
||||||
} elseif ($allBranches -contains "master") {
|
|
||||||
$mainBranch = "master"
|
|
||||||
} else {
|
|
||||||
$mainBranch = git config --get init.defaultBranch
|
|
||||||
if (-not $mainBranch) {
|
|
||||||
$mainBranch = $allBranches | Select-Object -First 1
|
|
||||||
if (-not $mainBranch) { $mainBranch = "main" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
Write-Host "Detected main branch: $mainBranch" -ForegroundColor Cyan
|
||||||
|
|
||||||
# Check current branch
|
# Check current branch
|
||||||
$currentBranch = git branch --show-current 2>$null
|
$currentBranch = git branch --show-current 2>$null
|
||||||
if ($currentBranch -ne "feature-login") {
|
if ($currentBranch -ne "feature-login") {
|
||||||
Write-Host "[FAIL] You should be on the 'feature-login' branch." -ForegroundColor Red
|
Write-Fail "You should be on the 'feature-login' branch." -ForegroundColor Red
|
||||||
Write-Host "Current branch: $currentBranch" -ForegroundColor Yellow
|
Write-Host "Current branch: $currentBranch" -ForegroundColor Yellow
|
||||||
Write-Host "Hint: Switch back to feature-login after completing the challenge" -ForegroundColor Yellow
|
Write-Host "Hint: Switch back to feature-login after completing the challenge" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
@@ -60,8 +40,8 @@ if ($currentBranch -ne "feature-login") {
|
|||||||
# Check for uncommitted changes on feature-login
|
# Check for uncommitted changes on feature-login
|
||||||
$status = git status --porcelain 2>$null
|
$status = git status --porcelain 2>$null
|
||||||
if ($status) {
|
if ($status) {
|
||||||
Write-Host "[FAIL] You have uncommitted changes on feature-login." -ForegroundColor Red
|
Write-Fail "You have uncommitted changes on feature-login." -ForegroundColor Red
|
||||||
Write-Host "Hint: After restoring from stash, you should complete and commit the feature" -ForegroundColor Yellow
|
Write-Hint "After restoring from stash, you should complete and commit the feature" -ForegroundColor Yellow
|
||||||
git status --short
|
git status --short
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
@@ -69,7 +49,7 @@ if ($status) {
|
|||||||
|
|
||||||
# Verify main branch has the security fix
|
# Verify main branch has the security fix
|
||||||
Write-Host "`nChecking $mainBranch branch for bug fix..." -ForegroundColor Cyan
|
Write-Host "`nChecking $mainBranch branch for bug fix..." -ForegroundColor Cyan
|
||||||
git checkout $mainBranch 2>$null | Out-Null
|
git switch $mainBranch 2>$null | Out-Null
|
||||||
|
|
||||||
# Check for bug fix commit
|
# Check for bug fix commit
|
||||||
$mainCommits = git log --pretty=format:"%s" $mainBranch 2>$null
|
$mainCommits = git log --pretty=format:"%s" $mainBranch 2>$null
|
||||||
@@ -82,17 +62,17 @@ foreach ($commit in $mainCommits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (-not $hasSecurityFix) {
|
if (-not $hasSecurityFix) {
|
||||||
Write-Host "[FAIL] No security bug fix commit found on $mainBranch branch." -ForegroundColor Red
|
Write-Fail "No security bug fix commit found on $mainBranch branch." -ForegroundColor Red
|
||||||
Write-Host "Hint: After stashing, switch to $mainBranch and commit a bug fix" -ForegroundColor Yellow
|
Write-Host "Hint: After stashing, switch to $mainBranch and commit a bug fix" -ForegroundColor Yellow
|
||||||
git checkout feature-login 2>$null | Out-Null
|
git switch feature-login 2>$null | Out-Null
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that app.py has been fixed
|
# Check that app.py has been fixed
|
||||||
if (-not (Test-Path "app.py")) {
|
if (-not (Test-Path "app.py")) {
|
||||||
Write-Host "[FAIL] app.py not found on $mainBranch branch." -ForegroundColor Red
|
Write-Fail "app.py not found on $mainBranch branch." -ForegroundColor Red
|
||||||
git checkout feature-login 2>$null | Out-Null
|
git switch feature-login 2>$null | Out-Null
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -102,9 +82,9 @@ $appContent = Get-Content "app.py" -Raw
|
|||||||
# The bug was "return true" in authenticate - it should be fixed now
|
# The bug was "return true" in authenticate - it should be fixed now
|
||||||
# We'll check that the buggy comment is gone or the implementation is improved
|
# We'll check that the buggy comment is gone or the implementation is improved
|
||||||
if ($appContent -match "allows unauthenticated access") {
|
if ($appContent -match "allows unauthenticated access") {
|
||||||
Write-Host "[FAIL] The security bug comment still exists in app.py." -ForegroundColor Red
|
Write-Fail "The security bug comment still exists in app.py." -ForegroundColor Red
|
||||||
Write-Host "Hint: Remove the bug from app.py and commit the fix" -ForegroundColor Yellow
|
Write-Host "Hint: Remove the bug from app.py and commit the fix" -ForegroundColor Yellow
|
||||||
git checkout feature-login 2>$null | Out-Null
|
git switch feature-login 2>$null | Out-Null
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -113,14 +93,14 @@ Write-Host "[PASS] Security bug fixed on main!" -ForegroundColor Green
|
|||||||
|
|
||||||
# Switch back to feature-login
|
# Switch back to feature-login
|
||||||
Write-Host "`nChecking feature-login branch..." -ForegroundColor Cyan
|
Write-Host "`nChecking feature-login branch..." -ForegroundColor Cyan
|
||||||
git checkout feature-login 2>$null | Out-Null
|
git switch feature-login 2>$null | Out-Null
|
||||||
|
|
||||||
# Check for completed feature commit
|
# Check for completed feature commit
|
||||||
$featureCommits = git log --pretty=format:"%s" feature-login 2>$null
|
$featureCommits = git log --pretty=format:"%s" feature-login 2>$null
|
||||||
$commitCount = ($featureCommits -split "`n").Count
|
$commitCount = ($featureCommits -split "`n").Count
|
||||||
|
|
||||||
if ($commitCount -lt 3) {
|
if ($commitCount -lt 3) {
|
||||||
Write-Host "[FAIL] Expected at least 3 commits on feature-login." -ForegroundColor Red
|
Write-Fail "Expected at least 3 commits on feature-login." -ForegroundColor Red
|
||||||
Write-Host "Hint: You should have the initial commits plus your completed feature commit" -ForegroundColor Yellow
|
Write-Host "Hint: You should have the initial commits plus your completed feature commit" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
@@ -128,7 +108,7 @@ if ($commitCount -lt 3) {
|
|||||||
|
|
||||||
# Check that login.py exists
|
# Check that login.py exists
|
||||||
if (-not (Test-Path "login.py")) {
|
if (-not (Test-Path "login.py")) {
|
||||||
Write-Host "[FAIL] login.py not found on feature-login branch." -ForegroundColor Red
|
Write-Fail "login.py not found on feature-login branch." -ForegroundColor Red
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -137,22 +117,22 @@ $loginContent = Get-Content "login.py" -Raw
|
|||||||
|
|
||||||
# Check that login method exists and is implemented
|
# Check that login method exists and is implemented
|
||||||
if ($loginContent -notmatch "def login") {
|
if ($loginContent -notmatch "def login") {
|
||||||
Write-Host "[FAIL] login.py should have a login method." -ForegroundColor Red
|
Write-Fail "login.py should have a login method." -ForegroundColor Red
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that TODOs are completed (no TODO comments should remain)
|
# Check that TODOs are completed (no TODO comments should remain)
|
||||||
if ($loginContent -match "TODO") {
|
if ($loginContent -match "TODO") {
|
||||||
Write-Host "[FAIL] login.py still contains TODO comments." -ForegroundColor Red
|
Write-Fail "login.py still contains TODO comments." -ForegroundColor Red
|
||||||
Write-Host "Hint: Complete all the TODOs in login.py before committing" -ForegroundColor Yellow
|
Write-Hint "Complete all the TODOs in login.py before committing" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check that password verification is implemented
|
# Check that password verification is implemented
|
||||||
if ($loginContent -notmatch "password") {
|
if ($loginContent -notmatch "password") {
|
||||||
Write-Host "[FAIL] login method should verify the password." -ForegroundColor Red
|
Write-Fail "login method should verify the password." -ForegroundColor Red
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@@ -160,7 +140,7 @@ if ($loginContent -notmatch "password") {
|
|||||||
# Check that the feature has been committed (not just in working directory)
|
# Check that the feature has been committed (not just in working directory)
|
||||||
$lastCommit = git log -1 --pretty=format:"%s" 2>$null
|
$lastCommit = git log -1 --pretty=format:"%s" 2>$null
|
||||||
if ($lastCommit -notmatch "login|feature|complete|implement") {
|
if ($lastCommit -notmatch "login|feature|complete|implement") {
|
||||||
Write-Host "[FAIL] Your completed feature should be committed." -ForegroundColor Red
|
Write-Fail "Your completed feature should be committed." -ForegroundColor Red
|
||||||
Write-Host "Last commit: $lastCommit" -ForegroundColor Yellow
|
Write-Host "Last commit: $lastCommit" -ForegroundColor Yellow
|
||||||
Write-Host "Hint: After popping the stash and completing the TODOs, commit the feature" -ForegroundColor Yellow
|
Write-Host "Hint: After popping the stash and completing the TODOs, commit the feature" -ForegroundColor Yellow
|
||||||
Set-Location ..
|
Set-Location ..
|
||||||
|
|||||||
Reference in New Issue
Block a user