Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Fix plugin loader ordering + add live test report

Juan Denis191c6fde94b0
diff --git a/backend/app/__init__.py b/backend/app/__init__.py
index ee3b1bb2..f987bc85 100644
--- a/backend/app/__init__.py
+++ b/backend/app/__init__.py
@@ -61,16 +61,16 @@ def create_app(config_name=None):
from app.middleware.api_key_auth import register_api_key_auth
register_api_key_auth(app)
- # Register API analytics middleware
- from app.middleware.api_analytics import register_api_analytics
- register_api_analytics(app)
-
- # Register fallback audit logging for authenticated mutating API requests
- from app.middleware.audit import register_audit_fallback
- register_audit_fallback(app)
-
- # Update rate limiter with custom key function
- from app.middleware.rate_limit import get_rate_limit_key, register_rate_limit_headers
+ # Register API analytics middleware
+ from app.middleware.api_analytics import register_api_analytics
+ register_api_analytics(app)
+
+ # Register fallback audit logging for authenticated mutating API requests
+ from app.middleware.audit import register_audit_fallback
+ register_audit_fallback(app)
+
+ # Update rate limiter with custom key function
+ from app.middleware.rate_limit import get_rate_limit_key, register_rate_limit_headers
limiter._key_func = get_rate_limit_key
register_rate_limit_headers(app)
@@ -201,15 +201,15 @@ def create_app(config_name=None):
from app.api.two_factor import two_factor_bp
app.register_blueprint(two_factor_bp, url_prefix='/api/v1/auth/2fa')
- # Register blueprints - SSO / OAuth
- from app.api.sso import sso_bp
- app.register_blueprint(sso_bp, url_prefix='/api/v1/sso')
-
- # Register blueprints - Source provider connections
- from app.api.source_connections import source_connections_bp
- app.register_blueprint(source_connections_bp, url_prefix='/api/v1/source-connections')
-
- # Register blueprints - Database Migrations
+ # Register blueprints - SSO / OAuth
+ from app.api.sso import sso_bp
+ app.register_blueprint(sso_bp, url_prefix='/api/v1/sso')
+
+ # Register blueprints - Source provider connections
+ from app.api.source_connections import source_connections_bp
+ app.register_blueprint(source_connections_bp, url_prefix='/api/v1/source-connections')
+
+ # Register blueprints - Database Migrations
from app.api.migrations import migrations_bp
app.register_blueprint(migrations_bp, url_prefix='/api/v1/migrations')
@@ -303,15 +303,8 @@ def create_app(config_name=None):
from app.api.pairing import pairing_bp
app.register_blueprint(pairing_bp, url_prefix='/api/v1/pairing')
- # Load installed plugins (dynamic blueprints)
- try:
- from app.services.plugin_service import load_all_plugins
- load_all_plugins(app)
- except Exception as e:
- import logging
- logging.getLogger(__name__).warning(f'Plugin loader: {e}')
-
- # Handle database migrations (Alembic)
+ # Handle database migrations (Alembic) — must run before plugin loader
+ # since the loader queries the installed_plugins table.
with app.app_context():
from app.services.migration_service import MigrationService
MigrationService.check_and_prepare(app)
@@ -321,6 +314,15 @@ def create_app(config_name=None):
SettingsService.initialize_defaults()
SettingsService.migrate_legacy_roles()
+ # Load installed plugins (dynamic blueprints) AFTER migrations,
+ # so the installed_plugins table exists.
+ try:
+ from app.services.plugin_service import load_all_plugins
+ load_all_plugins(app)
+ except Exception as e:
+ import logging
+ logging.getLogger(__name__).warning(f'Plugin loader: {e}')
+
# Start metrics history collection in background
from app.services.metrics_history_service import MetricsHistoryService
if not MetricsHistoryService.is_running():
diff --git a/scripts/test/full-stack-test.ps1 b/scripts/test/full-stack-test.ps1
index 18cd6e91..d7be8920 100644
--- a/scripts/test/full-stack-test.ps1
+++ b/scripts/test/full-stack-test.ps1
@@ -83,12 +83,29 @@ Write-Host "========================================" -ForegroundColor Cyan
# NB: 'mp' is a built-in PS alias for Move-ItemProperty, so we must NOT
# define a helper function named Mp. Use $MpExe directly everywhere.
+# --- live state + report regen ------------------------------------------
+$script:State = @{ running = $true; vms = @{} }
+function Save-State {
+ $json = $script:State | ConvertTo-Json -Depth 5 -Compress
+ Set-Content -Path (Join-Path $OutDir 'state.json') -Value $json -Encoding utf8
+ if (Get-Command python -ErrorAction SilentlyContinue) {
+ & python (Join-Path $PSScriptRoot 'report.py') $OutDir 2>&1 | Out-Null
+ }
+}
+function Set-VmStage {
+ param([string]$Vm, [string]$Stage)
+ if (-not $script:State.vms.ContainsKey($Vm)) { $script:State.vms[$Vm] = @{} }
+ $script:State.vms[$Vm].stage = $Stage
+ Save-State
+}
+
function Test-VmInstall {
param([string]$Vm, [string]$VmOut, [string]$Tarball, [string]$VmInstallScript, [string]$HarnessDir)
New-Item -ItemType Directory -Force -Path $VmOut | Out-Null
$statusFile = Join-Path $VmOut 'install-status'
+ Set-VmStage -Vm $Vm -Stage 'transferring source'
Write-Host " [$Vm] transferring source ($([math]::Round((Get-Item $Tarball).Length/1MB,1)) MB)..." -ForegroundColor DarkCyan
& $MpExe transfer $Tarball "${Vm}:/tmp/serverkit-src.tar.gz" 2>&1 | Out-Null
& $MpExe transfer $VmInstallScript "${Vm}:/tmp/vm-install.sh" 2>&1 | Out-Null
@@ -96,14 +113,12 @@ function Test-VmInstall {
& $MpExe exec $Vm -- sudo tar -xzf /tmp/serverkit-src.tar.gz -C /opt/serverkit-src 2>&1 | Out-Null
& $MpExe exec $Vm -- sudo chmod +x /tmp/vm-install.sh 2>&1 | Out-Null
+ Set-VmStage -Vm $Vm -Stage 'installing (npm ci + build, ~10 min)'
Write-Host " [$Vm] running install (this is the long part)..." -ForegroundColor DarkCyan
- # NB: multipass exec's stdout pipe can hang on Windows when piped through
- # PS. Redirect everything to a file on the VM and only check exit code.
& $MpExe exec $Vm -- sh -c "sudo bash /tmp/vm-install.sh > /tmp/vm-install-stdout.log 2>&1; rc=`$?; echo EXIT_RC=`$rc; exit `$rc" `
| Out-File (Join-Path $VmOut 'install.log') -Encoding utf8
$installRC = $LASTEXITCODE
- # Capture canonical logs + status
& $MpExe transfer "${Vm}:/var/log/serverkit-test-install.log" "$VmOut\vm-install.log" 2>&1 | Out-Null
& $MpExe transfer "${Vm}:/tmp/serverkit-install-status" $statusFile 2>&1 | Out-Null
if (-not (Test-Path $statusFile) -or (Get-Content $statusFile -Raw -ErrorAction SilentlyContinue).Trim() -eq '') {
@@ -115,9 +130,14 @@ function Test-VmInstall {
$status = (Get-Content $statusFile -Raw).Trim()
Write-Host " [$Vm] install status: $status" -ForegroundColor $(if ($status -eq 'OK') { 'Green' } else { 'Red' })
+ Save-State # regenerate so install log + journalctl show up
- if ($status -ne 'OK') { return $status }
+ if ($status -ne 'OK') {
+ Set-VmStage -Vm $Vm -Stage 'install failed'
+ return $status
+ }
+ Set-VmStage -Vm $Vm -Stage 'running pytest'
Write-Host " [$Vm] running pytest harness..." -ForegroundColor DarkCyan
& $MpExe exec $Vm -- sudo mkdir -p /opt/serverkit-test 2>&1 | Out-Null
& $MpExe exec $Vm -- sudo chown ubuntu:ubuntu /opt/serverkit-test 2>&1 | Out-Null
@@ -131,6 +151,7 @@ function Test-VmInstall {
& $MpExe transfer "${Vm}:/tmp/pytest-stdout.log" (Join-Path $VmOut 'pytest-stdout.log') 2>&1 | Out-Null
& $MpExe transfer "${Vm}:/opt/serverkit-test/pytest-report.json" (Join-Path $VmOut 'pytest-report.json') 2>&1 | Out-Null
+ Set-VmStage -Vm $Vm -Stage 'done'
return $status
}
@@ -166,6 +187,19 @@ $vmInstallScript = Join-Path $PSScriptRoot 'vm-install.sh'
$cloudInit = Join-Path $PSScriptRoot 'cloud-init\base.yaml'
$harnessDir = Join-Path $PSScriptRoot 'harness'
+# Pre-populate stages and seed the live report, then open it in the browser.
+foreach ($d in $Distros) {
+ $vmName = if ($ReuseVm) { $ReuseVm } else { "sk-test-$d-$RunId" }
+ $script:State.vms[$vmName] = @{ stage = 'pending' }
+ if ($ReuseVm) { break }
+}
+Save-State
+$reportPath = Join-Path $OutDir 'report.html'
+if (Test-Path $reportPath) {
+ Write-Host "`nLive report: $reportPath (opening in browser)" -ForegroundColor Cyan
+ Start-Process $reportPath
+}
+
if ($ReuseVm) {
Write-Host "`n[2-3/4] Reusing VM: $ReuseVm" -ForegroundColor Yellow
$vmOut = Join-Path $OutDir $ReuseVm
@@ -199,14 +233,15 @@ if ($ReuseVm) {
}
# --- report -------------------------------------------------------------
-Write-Host "`n[4/4] Generating HTML report..." -ForegroundColor Yellow
-$reportHtml = $null
-$reportPy = Join-Path $PSScriptRoot 'report.py'
-if (Get-Command python -ErrorAction SilentlyContinue) {
- $reportHtml = & python $reportPy $OutDir
+Write-Host "`n[4/4] Finalizing HTML report..." -ForegroundColor Yellow
+$script:State.running = $false
+Save-State
+$reportHtml = Join-Path $OutDir 'report.html'
+if (Test-Path $reportHtml) {
Write-Host " Report: $reportHtml" -ForegroundColor Green
} else {
Write-Host " python not on PATH. Raw output: $OutDir" -ForegroundColor Yellow
+ $reportHtml = $null
}
# --- teardown -----------------------------------------------------------
@@ -224,11 +259,9 @@ $failed = @($results | Where-Object { $_.Status -ne 'OK' })
Write-Host ""
if ($failed.Count -eq 0 -and $results.Count -gt 0) {
Write-Host "ALL GREEN - $($results.Count) VM(s) passed." -ForegroundColor Green
- if ($reportHtml) { Start-Process $reportHtml }
exit 0
} else {
Write-Host "FAILURES on $($failed.Count) VM(s):" -ForegroundColor Red
$failed | ForEach-Object { Write-Host " - $($_.Name): $($_.Status)" -ForegroundColor Red }
- if ($reportHtml) { Start-Process $reportHtml }
exit 1
}
diff --git a/scripts/test/report.py b/scripts/test/report.py
index fc5dc65e..d91ce884 100644
--- a/scripts/test/report.py
+++ b/scripts/test/report.py
@@ -76,24 +76,33 @@ def vm_summary(vm_dir: Path):
HTML_TEMPLATE = """<!doctype html>
<html><head><meta charset="utf-8"><title>ServerKit E2E Report — {ts}</title>
+{refresh_meta}
<style>
body{{font-family:-apple-system,Segoe UI,sans-serif;margin:24px;background:#0f1115;color:#e6e6e6}}
h1{{margin-top:0}}
+ .live-banner{{background:#1f3a5f;color:#cfe2ff;padding:8px 14px;border-radius:6px;margin:0 0 16px;display:inline-block}}
+ .live-banner .dot{{display:inline-block;width:8px;height:8px;border-radius:50%;background:#3fb950;margin-right:8px;animation:pulse 1.2s ease-in-out infinite}}
+ @keyframes pulse{{0%,100%{{opacity:1}}50%{{opacity:.3}}}}
.vm{{background:#1a1d24;border-radius:8px;padding:16px;margin:16px 0;border-left:6px solid #555}}
.vm.pass{{border-left-color:#3fb950}}
.vm.fail{{border-left-color:#f85149}}
+ .vm.running{{border-left-color:#3a72d6}}
.badge{{display:inline-block;padding:2px 10px;border-radius:12px;font-size:12px;font-weight:600}}
- .badge.pass{{background:#1f6f33;color:#d2f5d8}}
- .badge.fail{{background:#7a2a26;color:#fdd}}
- .badge.skip{{background:#3a3a3a;color:#bbb}}
+ .badge.pass,.badge.passed{{background:#1f6f33;color:#d2f5d8}}
+ .badge.fail,.badge.failed{{background:#7a2a26;color:#fdd}}
+ .badge.skip,.badge.skipped{{background:#3a3a3a;color:#bbb}}
+ .badge.running{{background:#1f4b8e;color:#cfe2ff}}
details{{margin-top:8px;background:#0c0e13;border-radius:6px;padding:8px}}
summary{{cursor:pointer;font-weight:600}}
pre{{white-space:pre-wrap;word-break:break-word;font-size:12px;background:#000;padding:8px;border-radius:4px;max-height:400px;overflow:auto}}
+ td.empty{{color:#666;text-align:center}}
table{{border-collapse:collapse;width:100%;margin-top:8px;font-size:13px}}
- td,th{{padding:4px 8px;border-bottom:1px solid #2a2d34;text-align:left}}
- .counts span{{margin-right:12px}}
+ td,th{{padding:6px 10px;border-bottom:1px solid #2a2d34;text-align:left;vertical-align:top}}
+ .counts span{{margin-right:14px}}
+ .stage{{color:#9aa4b2;font-size:13px;margin-top:6px}}
</style></head><body>
<h1>ServerKit E2E Test Report</h1>
+{live_banner}
<p>Run: <code>{run_id}</code> · {ts}</p>
<p>Overall: <span class="badge {overall_cls}">{overall}</span>
&nbsp; VMs: {n_vms} &nbsp; Passed: {n_pass} &nbsp; Failed: {n_fail}</p>
@@ -103,6 +112,7 @@ HTML_TEMPLATE = """<!doctype html>
VM_TEMPLATE = """<div class="vm {cls}">
<h2>{name} <span class="badge {cls}">{overall}</span></h2>
<div class="counts">
+ <span>Stage: <b>{stage}</b></span>
<span>Install: <b>{install}</b></span>
<span>Passed: <b>{p}</b></span>
<span>Failed: <b>{f}</b></span>
@@ -114,24 +124,66 @@ VM_TEMPLATE = """<div class="vm {cls}">
</div>"""
+def _read_state(run_dir: Path):
+ """state.json (written by the orchestrator) tells us which phase
+ each VM is in while the run is still going."""
+ f = run_dir / "state.json"
+ if not f.exists():
+ return {}
+ try:
+ return json.loads(f.read_text(encoding="utf-8"))
+ except Exception:
+ return {}
+
+
def render(run_dir: Path) -> Path:
+ state = _read_state(run_dir)
+ running = bool(state.get("running"))
+ vm_states = state.get("vms", {})
+
vm_dirs = sorted([p for p in run_dir.iterdir() if p.is_dir()])
summaries = [vm_summary(d) for d in vm_dirs]
+ # Add stage from state.json (if available) and merge in VMs that haven't
+ # produced output yet (so the UI shows them as "running").
+ seen = {s["name"] for s in summaries}
+ for name, st in vm_states.items():
+ if name not in seen:
+ summaries.append({
+ "name": name, "install_ok": False, "overall": "RUNNING",
+ "tests": [], "pass": 0, "fail": 0, "skip": 0,
+ "install_log": "", "journal": "",
+ })
+ for s in summaries:
+ s["stage"] = vm_states.get(s["name"], {}).get("stage", "done")
+
n_pass = sum(1 for s in summaries if s["overall"] == "PASS")
- n_fail = sum(1 for s in summaries if s["overall"] != "PASS")
- overall = "PASS" if n_fail == 0 and n_pass > 0 else "FAIL"
+ n_fail = sum(1 for s in summaries if s["overall"] == "FAIL")
+ overall = "PASS" if (n_fail == 0 and n_pass > 0 and not running) else ("RUNNING" if running else ("PASS" if n_fail == 0 and n_pass > 0 else "FAIL"))
+
+ refresh_meta = '<meta http-equiv="refresh" content="8">' if running else ''
+ live_banner = '<div class="live-banner"><span class="dot"></span>Run in progress — page auto-refreshes every 8s</div>' if running else ''
vm_sections = []
for s in summaries:
- cls = "pass" if s["overall"] == "PASS" else "fail"
+ cls = {"PASS": "pass", "FAIL": "fail", "RUNNING": "running"}.get(s["overall"], "fail")
if s["tests"]:
- rows = "".join(
- f"<tr><td>{esc(nid)}</td><td><span class='badge {oc}'>{esc(oc)}</span></td>"
- f"<td><pre style='max-height:120px'>{esc(repr_)}</pre></td></tr>"
- for nid, oc, repr_ in s["tests"]
- )
- tests_table = f"<table><tr><th>Test</th><th>Result</th><th>Details</th></tr>{rows}</table>"
+ rows = []
+ for nid, oc, repr_ in s["tests"]:
+ details_html = (
+ f"<pre style='max-height:120px'>{esc(repr_)}</pre>"
+ if (repr_ and str(repr_).strip()) else
+ "<span class='empty'>—</span>"
+ )
+ rows.append(
+ f"<tr><td>{esc(nid)}</td>"
+ f"<td><span class='badge {oc}'>{esc(oc)}</span></td>"
+ f"<td>{details_html}</td></tr>"
+ )
+ tests_table = ("<table><tr><th>Test</th><th>Result</th><th>Details</th></tr>"
+ + "".join(rows) + "</table>")
+ elif s["overall"] == "RUNNING":
+ tests_table = f"<p class='stage'><i>Currently: {esc(s['stage'])}…</i></p>"
else:
tests_table = "<p><i>No pytest results (install likely failed before harness ran).</i></p>"
@@ -139,7 +191,8 @@ def render(run_dir: Path) -> Path:
cls=cls,
name=esc(s["name"]),
overall=esc(s["overall"]),
- install="OK" if s["install_ok"] else "FAIL",
+ stage=esc(s.get("stage", "?")),
+ install="OK" if s["install_ok"] else ("-" if s["overall"] == "RUNNING" else "FAIL"),
p=s["pass"], f=s["fail"], s=s["skip"],
tests_table=tests_table,
install_log=esc(s["install_log"]),
@@ -151,9 +204,11 @@ def render(run_dir: Path) -> Path:
ts=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
run_id=esc(run_dir.name),
overall=overall,
- overall_cls="pass" if overall == "PASS" else "fail",
+ overall_cls={"PASS":"pass","FAIL":"fail","RUNNING":"running"}.get(overall,"fail"),
n_vms=len(summaries),
n_pass=n_pass,
+ refresh_meta=refresh_meta,
+ live_banner=live_banner,
n_fail=n_fail,
vm_sections="\n".join(vm_sections),
), encoding="utf-8")