176 lines
5.4 KiB
PowerShell
176 lines
5.4 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
|
|
<#
|
|
.SYNOPSIS
|
|
Sets up the cherry-pick challenge environment.
|
|
|
|
.DESCRIPTION
|
|
Creates a Git repository with a development branch containing both
|
|
bug fixes and experimental features. Students must cherry-pick only
|
|
the bug fixes to the main branch.
|
|
#>
|
|
|
|
# Remove existing challenge directory if present
|
|
if (Test-Path "challenge") {
|
|
Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow
|
|
Remove-Item -Path "challenge" -Recurse -Force
|
|
}
|
|
|
|
# Create challenge directory
|
|
Write-Host "Creating challenge environment..." -ForegroundColor Cyan
|
|
New-Item -ItemType Directory -Path "challenge" | Out-Null
|
|
Set-Location "challenge"
|
|
|
|
# Initialize git repository
|
|
git init | Out-Null
|
|
git config user.name "Workshop User" | Out-Null
|
|
git config user.email "user@workshop.local" | Out-Null
|
|
|
|
# Create initial commits on main branch
|
|
$app = @"
|
|
class App:
|
|
def __init__(self):
|
|
self.version = '1.0.0'
|
|
|
|
def start(self):
|
|
print('App started')
|
|
"@
|
|
|
|
Set-Content -Path "app.py" -Value $app
|
|
git add app.py
|
|
git commit -m "Initial app implementation" | Out-Null
|
|
|
|
$readme = @"
|
|
# Application
|
|
|
|
Version 1.0.0
|
|
"@
|
|
|
|
Set-Content -Path "README.md" -Value $readme
|
|
git add README.md
|
|
git commit -m "Add README" | Out-Null
|
|
|
|
# Create development branch
|
|
git checkout -b development | Out-Null
|
|
|
|
# Commit 1: Experimental feature (should NOT be cherry-picked)
|
|
$appWithExperimental = @"
|
|
class App:
|
|
def __init__(self):
|
|
self.version = '1.0.0'
|
|
self.experimental_mode = False
|
|
|
|
def start(self):
|
|
print('App started')
|
|
if self.experimental_mode:
|
|
self.enable_experimental_features()
|
|
|
|
def enable_experimental_features(self):
|
|
print('Experimental features enabled')
|
|
"@
|
|
|
|
Set-Content -Path "app.py" -Value $appWithExperimental
|
|
git add app.py
|
|
git commit -m "Add experimental AI features" | Out-Null
|
|
|
|
# Commit 2: Security bug fix (SHOULD be cherry-picked)
|
|
$security = @"
|
|
import re
|
|
|
|
class Security:
|
|
@staticmethod
|
|
def sanitize_input(input_str):
|
|
# Remove potential XSS attacks
|
|
return re.sub(r'[<>]', '', input_str)
|
|
|
|
@staticmethod
|
|
def validate_token(token):
|
|
if not token or len(token) < 32:
|
|
raise ValueError('Invalid security token')
|
|
return True
|
|
"@
|
|
|
|
Set-Content -Path "security.py" -Value $security
|
|
git add security.py
|
|
git commit -m "Fix security vulnerability in input validation" | Out-Null
|
|
|
|
# Commit 3: Another experimental feature (should NOT be cherry-picked)
|
|
$appWithMoreExperimental = @"
|
|
class App:
|
|
def __init__(self):
|
|
self.version = '1.0.0'
|
|
self.experimental_mode = False
|
|
self.beta_features = []
|
|
|
|
def start(self):
|
|
print('App started')
|
|
if self.experimental_mode:
|
|
self.enable_experimental_features()
|
|
|
|
def enable_experimental_features(self):
|
|
print('Experimental features enabled')
|
|
|
|
def add_beta_feature(self, feature):
|
|
self.beta_features.append(feature)
|
|
"@
|
|
|
|
Set-Content -Path "app.py" -Value $appWithMoreExperimental
|
|
git add app.py
|
|
git commit -m "Add beta features framework" | Out-Null
|
|
|
|
# Commit 4: Performance bug fix (SHOULD be cherry-picked)
|
|
$appWithPerformance = @"
|
|
class App:
|
|
def __init__(self):
|
|
self.version = '1.0.0'
|
|
self.experimental_mode = False
|
|
self.beta_features = []
|
|
self.cache = {}
|
|
|
|
def start(self):
|
|
print('App started')
|
|
if self.experimental_mode:
|
|
self.enable_experimental_features()
|
|
|
|
def enable_experimental_features(self):
|
|
print('Experimental features enabled')
|
|
|
|
def add_beta_feature(self, feature):
|
|
self.beta_features.append(feature)
|
|
|
|
def get_data(self, key):
|
|
# Use cache to improve performance
|
|
if key in self.cache:
|
|
return self.cache[key]
|
|
data = self.fetch_data(key)
|
|
self.cache[key] = data
|
|
return data
|
|
|
|
def fetch_data(self, key):
|
|
# Simulate data fetching
|
|
return {'key': key, 'value': 'data'}
|
|
"@
|
|
|
|
Set-Content -Path "app.py" -Value $appWithPerformance
|
|
git add app.py
|
|
git commit -m "Fix performance issue with data caching" | Out-Null
|
|
|
|
# Return to module directory
|
|
Set-Location ..
|
|
|
|
Write-Host "`n========================================" -ForegroundColor Green
|
|
Write-Host "Challenge environment created!" -ForegroundColor Green
|
|
Write-Host "========================================" -ForegroundColor Green
|
|
Write-Host "`nYou are on the 'development' branch with multiple commits:" -ForegroundColor Cyan
|
|
Write-Host "- Experimental features (not ready for production)" -ForegroundColor Yellow
|
|
Write-Host "- Critical bug fixes (needed in production NOW)" -ForegroundColor Green
|
|
Write-Host "`nYour task:" -ForegroundColor Yellow
|
|
Write-Host "1. Navigate to the challenge directory: cd challenge" -ForegroundColor White
|
|
Write-Host "2. View the development branch commits: git log --oneline" -ForegroundColor White
|
|
Write-Host "3. Identify which commits are bug fixes (look for 'Fix' in messages)" -ForegroundColor White
|
|
Write-Host "4. Switch to main branch: git checkout main" -ForegroundColor White
|
|
Write-Host "5. Cherry-pick ONLY the bug fix commits to main" -ForegroundColor White
|
|
Write-Host "6. Do NOT bring the experimental features to main" -ForegroundColor White
|
|
Write-Host "`nHint: Look for commits mentioning 'security' and 'performance' fixes" -ForegroundColor Cyan
|
|
Write-Host "Run '../verify.ps1' from the challenge directory to check your solution.`n" -ForegroundColor Cyan
|