refactor: use python instead of javascript

This commit is contained in:
Bjarke Sporring
2026-01-05 12:21:48 +01:00
parent e1b8d8418a
commit f11f5a4646
14 changed files with 550 additions and 735 deletions

View File

@@ -27,28 +27,22 @@ git config user.email "user@workshop.local" | Out-Null
# Create initial application on main
$app = @"
class Application {
constructor() {
this.name = 'MyApp';
this.version = '1.0.0';
}
class Application:
def __init__(self):
self.name = 'MyApp'
self.version = '1.0.0'
start() {
console.log('Application started');
this.authenticate();
}
def start(self):
print('Application started')
self.authenticate()
authenticate() {
console.log('Authentication check');
return true;
}
}
module.exports = Application;
def authenticate(self):
print('Authentication check')
return True
"@
Set-Content -Path "app.js" -Value $app
git add app.js
Set-Content -Path "app.py" -Value $app
git add app.py
git commit -m "Initial application" | Out-Null
$readme = @"
@@ -66,54 +60,44 @@ git checkout -b feature-login | Out-Null
# Start working on login feature
$loginInitial = @"
class LoginService {
constructor() {
this.users = new Map();
}
from datetime import datetime
register(username, password) {
if (this.users.has(username)) {
throw new Error('User already exists');
}
this.users.set(username, { password, createdAt: new Date() });
return true;
}
}
class LoginService:
def __init__(self):
self.users = {}
module.exports = LoginService;
def register(self, username, password):
if username in self.users:
raise ValueError('User already exists')
self.users[username] = {'password': password, 'created_at': datetime.now()}
return True
"@
Set-Content -Path "login.js" -Value $loginInitial
git add login.js
Set-Content -Path "login.py" -Value $loginInitial
git add login.py
git commit -m "Start login service implementation" | Out-Null
# Add a critical bug to main branch (simulating a bug that was introduced)
git checkout main | Out-Null
$appWithBug = @"
class Application {
constructor() {
this.name = 'MyApp';
this.version = '1.0.0';
}
class Application:
def __init__(self):
self.name = 'MyApp'
self.version = '1.0.0'
start() {
console.log('Application started');
this.authenticate();
}
def start(self):
print('Application started')
self.authenticate()
authenticate() {
console.log('Authentication check');
// BUG: This allows unauthenticated access!
return true; // Should check actual credentials
}
}
module.exports = Application;
def authenticate(self):
print('Authentication check')
# BUG: This allows unauthenticated access!
return True # Should check actual credentials
"@
Set-Content -Path "app.js" -Value $appWithBug
git add app.js
Set-Content -Path "app.py" -Value $appWithBug
git add app.py
git commit -m "Update authentication (contains bug)" | Out-Null
# Go back to feature branch
@@ -121,35 +105,29 @@ git checkout feature-login | Out-Null
# Create work in progress (uncommitted changes)
$loginWIP = @"
class LoginService {
constructor() {
this.users = new Map();
}
from datetime import datetime
register(username, password) {
if (this.users.has(username)) {
throw new Error('User already exists');
}
this.users.set(username, { password, createdAt: new Date() });
return true;
}
class LoginService:
def __init__(self):
self.users = {}
// TODO: Complete this method
login(username, password) {
if (!this.users.has(username)) {
throw new Error('User not found');
}
// TODO: Verify password
// TODO: Return user session
}
def register(self, username, password):
if username in self.users:
raise ValueError('User already exists')
self.users[username] = {'password': password, 'created_at': datetime.now()}
return True
// TODO: Add logout method
}
# TODO: Complete this method
def login(self, username, password):
if username not in self.users:
raise ValueError('User not found')
# TODO: Verify password
# TODO: Return user session
module.exports = LoginService;
# TODO: Add logout method
"@
Set-Content -Path "login.js" -Value $loginWIP
Set-Content -Path "login.py" -Value $loginWIP
# Don't commit - leave as uncommitted changes
@@ -169,10 +147,10 @@ Write-Host "1. Navigate to the challenge directory: cd challenge" -ForegroundCol
Write-Host "2. Check your status: git status (see uncommitted changes)" -ForegroundColor White
Write-Host "3. Stash your work: git stash save 'WIP: login feature'" -ForegroundColor White
Write-Host "4. Switch to main: git checkout main" -ForegroundColor White
Write-Host "5. Fix the security bug in app.js (remove the comment and fix the auth)" -ForegroundColor White
Write-Host "6. Commit the fix: git add app.js && git commit -m 'Fix critical security bug'" -ForegroundColor White
Write-Host "5. Fix the security bug in app.py (remove the comment and fix the auth)" -ForegroundColor White
Write-Host "6. Commit the fix: git add app.py && git commit -m 'Fix critical security bug'" -ForegroundColor White
Write-Host "7. Switch back: git checkout feature-login" -ForegroundColor White
Write-Host "8. Restore your work: git stash pop" -ForegroundColor White
Write-Host "9. Complete the TODOs in login.js" -ForegroundColor White
Write-Host "9. Complete the TODOs in login.py" -ForegroundColor White
Write-Host "10. Commit your completed feature" -ForegroundColor White
Write-Host "`nRun '../verify.ps1' from the challenge directory to check your solution.`n" -ForegroundColor Cyan