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

@@ -28,21 +28,16 @@ git config user.email "user@workshop.local" | Out-Null
# Create initial commits on main branch
$app = @"
class App {
constructor() {
this.version = '1.0.0';
}
class App:
def __init__(self):
self.version = '1.0.0'
start() {
console.log('App started');
}
}
module.exports = App;
def start(self):
print('App started')
"@
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 app implementation" | Out-Null
$readme = @"
@@ -60,132 +55,104 @@ git checkout -b development | Out-Null
# Commit 1: Experimental feature (should NOT be cherry-picked)
$appWithExperimental = @"
class App {
constructor() {
this.version = '1.0.0';
this.experimentalMode = false;
}
class App:
def __init__(self):
self.version = '1.0.0'
self.experimental_mode = False
start() {
console.log('App started');
if (this.experimentalMode) {
this.enableExperimentalFeatures();
}
}
def start(self):
print('App started')
if self.experimental_mode:
self.enable_experimental_features()
enableExperimentalFeatures() {
console.log('Experimental features enabled');
}
}
module.exports = App;
def enable_experimental_features(self):
print('Experimental features enabled')
"@
Set-Content -Path "app.js" -Value $appWithExperimental
git add app.js
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 = @"
class Security {
static sanitizeInput(input) {
// Remove potential XSS attacks
return input.replace(/[<>]/g, '');
}
import re
static validateToken(token) {
if (!token || token.length < 32) {
throw new Error('Invalid security token');
}
return true;
}
}
class Security:
@staticmethod
def sanitize_input(input_str):
# Remove potential XSS attacks
return re.sub(r'[<>]', '', input_str)
module.exports = Security;
@staticmethod
def validate_token(token):
if not token or len(token) < 32:
raise ValueError('Invalid security token')
return True
"@
Set-Content -Path "security.js" -Value $security
git add security.js
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 {
constructor() {
this.version = '1.0.0';
this.experimentalMode = false;
this.betaFeatures = [];
}
class App:
def __init__(self):
self.version = '1.0.0'
self.experimental_mode = False
self.beta_features = []
start() {
console.log('App started');
if (this.experimentalMode) {
this.enableExperimentalFeatures();
}
}
def start(self):
print('App started')
if self.experimental_mode:
self.enable_experimental_features()
enableExperimentalFeatures() {
console.log('Experimental features enabled');
}
def enable_experimental_features(self):
print('Experimental features enabled')
addBetaFeature(feature) {
this.betaFeatures.push(feature);
}
}
module.exports = App;
def add_beta_feature(self, feature):
self.beta_features.append(feature)
"@
Set-Content -Path "app.js" -Value $appWithMoreExperimental
git add app.js
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 {
constructor() {
this.version = '1.0.0';
this.experimentalMode = false;
this.betaFeatures = [];
this.cache = new Map();
}
class App:
def __init__(self):
self.version = '1.0.0'
self.experimental_mode = False
self.beta_features = []
self.cache = {}
start() {
console.log('App started');
if (this.experimentalMode) {
this.enableExperimentalFeatures();
}
}
def start(self):
print('App started')
if self.experimental_mode:
self.enable_experimental_features()
enableExperimentalFeatures() {
console.log('Experimental features enabled');
}
def enable_experimental_features(self):
print('Experimental features enabled')
addBetaFeature(feature) {
this.betaFeatures.push(feature);
}
def add_beta_feature(self, feature):
self.beta_features.append(feature)
getData(key) {
// Use cache to improve performance
if (this.cache.has(key)) {
return this.cache.get(key);
}
const data = this.fetchData(key);
this.cache.set(key, data);
return data;
}
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
fetchData(key) {
// Simulate data fetching
return { key: key, value: 'data' };
}
}
module.exports = App;
def fetch_data(self, key):
# Simulate data fetching
return {'key': key, 'value': 'data'}
"@
Set-Content -Path "app.js" -Value $appWithPerformance
git add app.js
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

View File

@@ -80,71 +80,71 @@ if ($mergeCommits) {
exit 1
}
# Check that security.js exists (from the security fix commit)
if (-not (Test-Path "security.js")) {
Write-Host "[FAIL] security.js not found on main branch." -ForegroundColor Red
# Check that security.py exists (from the security fix commit)
if (-not (Test-Path "security.py")) {
Write-Host "[FAIL] security.py not found on main branch." -ForegroundColor Red
Write-Host "Hint: You need to cherry-pick the 'Fix security vulnerability' commit" -ForegroundColor Yellow
Set-Location ..
exit 1
}
# Check that security.js has the security fix
$securityContent = Get-Content "security.js" -Raw
# Check that security.py has the security fix
$securityContent = Get-Content "security.py" -Raw
if ($securityContent -notmatch "sanitizeInput") {
Write-Host "[FAIL] security.js is missing the sanitizeInput function." -ForegroundColor Red
if ($securityContent -notmatch "sanitize_input") {
Write-Host "[FAIL] security.py is missing the sanitize_input function." -ForegroundColor Red
Set-Location ..
exit 1
}
if ($securityContent -notmatch "validateToken") {
Write-Host "[FAIL] security.js is missing the validateToken function." -ForegroundColor Red
if ($securityContent -notmatch "validate_token") {
Write-Host "[FAIL] security.py is missing the validate_token function." -ForegroundColor Red
Set-Location ..
exit 1
}
# Check that app.js exists
if (-not (Test-Path "app.js")) {
Write-Host "[FAIL] app.js not found." -ForegroundColor Red
# Check that app.py exists
if (-not (Test-Path "app.py")) {
Write-Host "[FAIL] app.py not found." -ForegroundColor Red
Set-Location ..
exit 1
}
# Check that app.js has the performance fix (cache) but NOT experimental features
$appContent = Get-Content "app.js" -Raw
# Check that app.py has the performance fix (cache) but NOT experimental features
$appContent = Get-Content "app.py" -Raw
# Should have cache (from performance fix)
if ($appContent -notmatch "cache") {
Write-Host "[FAIL] app.js is missing the performance fix (cache)." -ForegroundColor Red
Write-Host "[FAIL] app.py is missing the performance fix (cache)." -ForegroundColor Red
Write-Host "Hint: You need to cherry-pick the 'Fix performance issue' commit" -ForegroundColor Yellow
Set-Location ..
exit 1
}
if ($appContent -notmatch "getData") {
Write-Host "[FAIL] app.js is missing the getData method from performance fix." -ForegroundColor Red
if ($appContent -notmatch "get_data") {
Write-Host "[FAIL] app.py is missing the get_data method from performance fix." -ForegroundColor Red
Set-Location ..
exit 1
}
# Should NOT have experimental features
if ($appContent -match "experimentalMode") {
Write-Host "[FAIL] app.js contains experimental features (experimentalMode)." -ForegroundColor Red
if ($appContent -match "experimental_mode") {
Write-Host "[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-Host " The experimental feature commits should stay on development branch only" -ForegroundColor Yellow
Set-Location ..
exit 1
}
if ($appContent -match "betaFeatures") {
Write-Host "[FAIL] app.js contains experimental features (betaFeatures)." -ForegroundColor Red
if ($appContent -match "beta_features") {
Write-Host "[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
Set-Location ..
exit 1
}
if ($appContent -match "enableExperimentalFeatures") {
Write-Host "[FAIL] app.js contains experimental features (enableExperimentalFeatures)." -ForegroundColor Red
if ($appContent -match "enable_experimental_features") {
Write-Host "[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
Set-Location ..
exit 1