implement admin db testing

This commit is contained in:
southseact-3d
2026-02-20 13:54:51 +00:00
parent cb95a916ae
commit d3580b091a
15 changed files with 452 additions and 6 deletions

View File

@@ -33,6 +33,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -94,4 +95,4 @@
<script src="/admin.js"></script>
</body>
</html>
</html>

View File

@@ -33,6 +33,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -94,3 +95,4 @@
</body>
</html>

View File

@@ -245,6 +245,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -427,3 +428,4 @@
<script src="/js/blog-admin.js"></script>
</body>
</html>

View File

@@ -138,6 +138,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost active" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -307,3 +308,4 @@
</script>
</body>
</html>

View File

@@ -31,6 +31,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -80,3 +81,4 @@
<script src="/admin.js"></script>
</body>
</html>

View File

@@ -226,6 +226,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost active" href="/admin/feature-requests">Feature Requests</a>
@@ -535,3 +536,4 @@
</script>
</body>
</html>

View File

@@ -31,6 +31,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -145,3 +146,4 @@
<script src="/admin.js"></script>
</body>
</html>

View File

@@ -31,6 +31,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -97,4 +98,4 @@
</div>
<script src="/admin.js"></script>
</body>
</html>
</html>

View File

@@ -224,9 +224,10 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost active" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
<a class="ghost" href="/admin/login">Login</a>
</div>
</aside>
@@ -962,3 +963,4 @@
</script>
</body>
</html>

View File

@@ -0,0 +1,79 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Admin Panel - System Tests</title>
<link rel="stylesheet" href="/styles.css" />
<!-- PostHog Analytics -->
<script src="/posthog.js"></script>
</head>
<body data-page="system-tests">
<div class="sidebar-overlay"></div>
<div class="app-shell">
<aside class="sidebar">
<div class="brand">
<div class="brand-mark">A</div>
<div>
<div class="brand-title">Admin</div>
<div class="brand-sub">Site management</div>
</div>
<button id="close-sidebar" class="ghost" style="margin-left: auto; display: none;">&times;</button>
</div>
<div class="sidebar-section">
<div class="section-heading">Navigation</div>
<a class="ghost" href="/admin/build">Build models</a>
<a class="ghost" href="/admin/plan">Plan models</a>
<a class="ghost" href="/admin/plans">Plans</a>
<a class="ghost" href="/admin/accounts">Accounts</a>
<a class="ghost" href="/admin/affiliates">Affiliates</a>
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
<a class="ghost" href="/admin/blogs">Blog Management</a>
<a class="ghost" href="/admin/login">Login</a>
</div>
</aside>
<main class="main">
<div class="admin-shell">
<div class="topbar" style="margin-bottom: 12px;">
<button id="menu-toggle">
<span></span><span></span><span></span>
</button>
<div>
<div class="pill">Admin</div>
<div class="title" style="margin-top: 6px;">System Tests</div>
<div class="crumb">Run end-to-end checks for database, accounts, and payments.</div>
</div>
<div class="admin-actions">
<button id="admin-refresh" class="ghost">Refresh</button>
<button id="admin-logout" class="primary">Logout</button>
</div>
</div>
<div class="admin-card">
<header>
<h3>Full system self-test</h3>
<div class="pill">Diagnostics</div>
</header>
<p class="muted" style="margin-top:0;">
Runs database/encryption checks, creates a temporary test account, and verifies payment configuration.
If Dodo is configured, it will create a test checkout session (no charge is completed).
</p>
<div class="admin-actions">
<button id="system-tests-run" class="primary">Run full self-test</button>
<div class="status-line" id="system-tests-status"></div>
</div>
<div id="system-tests-output" class="admin-list" style="margin-top: 12px;"></div>
</div>
</div>
</main>
</div>
<script src="/admin.js"></script>
</body>
</html>

View File

@@ -184,6 +184,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -990,3 +991,4 @@
</script>
</body>
</html>

View File

@@ -33,6 +33,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -93,3 +94,4 @@
</body>
</html>

View File

@@ -43,6 +43,7 @@
<a class="ghost" href="/admin/withdrawals">Withdrawals</a>
<a class="ghost" href="/admin/tracking">Tracking</a>
<a class="ghost" href="/admin/resources">Resources</a>
<a class="ghost" href="/admin/system-tests">System Tests</a>
<a class="ghost" href="/admin/external-testing">External Testing</a>
<a class="ghost" href="/admin/contact-messages">Contact Messages</a>
<a class="ghost" href="/admin/feature-requests">Feature Requests</a>
@@ -322,3 +323,4 @@
<script src="/admin.js"></script>
</body>
</html>

View File

@@ -125,6 +125,9 @@
ollamaTestRun: document.getElementById('ollama-test-run'),
ollamaTestStatus: document.getElementById('ollama-test-status'),
ollamaTestOutput: document.getElementById('ollama-test-output'),
systemTestsRun: document.getElementById('system-tests-run'),
systemTestsStatus: document.getElementById('system-tests-status'),
systemTestsOutput: document.getElementById('system-tests-output'),
};
function ensureAvailableDatalist() {
@@ -221,6 +224,12 @@
el.externalTestingStatus.style.color = isError ? 'var(--danger)' : 'inherit';
}
function setSystemTestsStatus(msg, isError = false) {
if (!el.systemTestsStatus) return;
el.systemTestsStatus.textContent = msg || '';
el.systemTestsStatus.style.color = isError ? 'var(--danger)' : 'inherit';
}
function renderExternalTestingConfig(config) {
if (!el.externalTestingConfig) return;
el.externalTestingConfig.innerHTML = '';
@@ -337,6 +346,66 @@
renderExternalTestingConfig(data.config || {});
}
function renderSystemTestsOutput(data) {
if (!el.systemTestsOutput) return;
el.systemTestsOutput.innerHTML = '';
if (!data) return;
const summary = data.summary || { total: 0, passed: 0, failed: 0, skipped: 0 };
const summaryRow = document.createElement('div');
summaryRow.className = 'admin-row';
const summaryLabel = document.createElement('div');
summaryLabel.style.minWidth = '180px';
summaryLabel.style.color = 'var(--muted)';
summaryLabel.textContent = 'Summary';
const summaryValue = document.createElement('div');
summaryValue.textContent = `${summary.passed} passed, ${summary.failed} failed, ${summary.skipped} skipped (${data.durationMs || 0}ms)`;
summaryRow.appendChild(summaryLabel);
summaryRow.appendChild(summaryValue);
el.systemTestsOutput.appendChild(summaryRow);
const results = Array.isArray(data.results) ? data.results : [];
results.forEach((result) => {
const row = document.createElement('div');
row.className = 'admin-row';
const labelWrap = document.createElement('div');
labelWrap.style.minWidth = '180px';
const strong = document.createElement('strong');
strong.textContent = result.name || 'Check';
labelWrap.appendChild(strong);
const valueWrap = document.createElement('div');
const status = document.createElement('span');
const statusText = (result.status || 'unknown').toUpperCase();
status.textContent = statusText;
if (result.status === 'passed') status.style.color = 'var(--shopify-green)';
else if (result.status === 'failed') status.style.color = 'var(--danger)';
else status.style.color = 'var(--muted)';
valueWrap.appendChild(status);
if (result.details) {
const sep = document.createElement('span');
sep.textContent = ' - ';
valueWrap.appendChild(sep);
const details = document.createElement('span');
details.textContent = result.details;
valueWrap.appendChild(details);
}
if (typeof result.durationMs === 'number') {
const timing = document.createElement('span');
timing.textContent = ` (${result.durationMs}ms)`;
timing.style.color = 'var(--muted)';
timing.style.marginLeft = '4px';
valueWrap.appendChild(timing);
}
row.appendChild(labelWrap);
row.appendChild(valueWrap);
el.systemTestsOutput.appendChild(row);
});
}
// --- Ollama Test UI ---
function setOllamaTestStatus(msg, isError = false) {
if (!el.ollamaTestStatus) return;
@@ -2822,6 +2891,23 @@
});
}
if (el.systemTestsRun) {
el.systemTestsRun.addEventListener('click', async () => {
el.systemTestsRun.disabled = true;
setSystemTestsStatus('Running system tests...');
if (el.systemTestsOutput) el.systemTestsOutput.innerHTML = '';
try {
const data = await api('/api/admin/system-tests', { method: 'POST' });
renderSystemTestsOutput(data || null);
setSystemTestsStatus(data && data.ok ? 'System tests passed.' : 'System tests completed with failures.', !data || !data.ok);
} catch (err) {
setSystemTestsStatus(err.message || 'System tests failed.', true);
} finally {
el.systemTestsRun.disabled = false;
}
});
}
// Ollama Test button handler
if (el.ollamaTestRun) {
el.ollamaTestRun.addEventListener('click', async () => {