feat: Add Web UI for account and quota management
## Summary Add an optional Web UI for managing accounts and monitoring quotas. WebUI is implemented as a modular plugin with minimal changes to server.js (only 5 lines added). ## New Features - Dashboard: Real-time model quota visualization with Chart.js - Accounts: OAuth-based account management (add/enable/disable/refresh/remove) - Logs: Live server log streaming via SSE with search and level filtering - Settings: System configuration with 4 tabs - Interface: Language (EN/zh_CN), polling interval, log buffer size, display options - Claude CLI: Proxy connection config, model selection, alias overrides (~/.claude.json) - Models: Model visibility and ordering management - Server Info: Runtime info and account config reload ## Technical Changes - Add src/webui/index.js as modular plugin (all WebUI routes encapsulated) - Add src/config.js for centralized configuration (~/.config/antigravity-proxy/config.json) - Add authMiddleware for optional password protection (WEBUI_PASSWORD env var) - Enhance logger with EventEmitter for SSE log streaming - Make constants configurable via config.json - Merge with main v1.2.6 (model fallback, cross-model thinking) - server.js changes: only 5 lines added to import and mount WebUI module ## Bug Fixes - Fix Alpine.js $watch error in settings-store.js (not supported in store init) - Fix "OK" label to "SUCCESS" in logs filter - Add saveSettings() calls to settings toggles for proper persistence - Improve Claude CLI config robustness (handle empty/invalid JSON files) - Add safety check for empty config.env in claude-config component - Improve config.example.json instructions with clear Windows/macOS/Linux paths ## New Files - src/webui/index.js - WebUI module with all API routes - public/ - Complete Web UI frontend (Alpine.js + TailwindCSS + DaisyUI) - src/config.js - Configuration management - src/utils/claude-config.js - Claude CLI settings helper - tests/frontend/ - Frontend test suite ## API Endpoints Added - GET/POST /api/config - Server configuration - GET/POST /api/claude/config - Claude CLI configuration - POST /api/models/config - Model alias/hidden settings - GET /api/accounts - Account list with status - POST /api/accounts/:email/toggle - Enable/disable account - POST /api/accounts/:email/refresh - Refresh account token - DELETE /api/accounts/:email - Remove account - GET /api/logs - Log history - GET /api/logs/stream - Live log streaming (SSE) - GET /api/auth/url - OAuth URL generation - GET /oauth/callback - OAuth callback handler ## Backward Compatibility - Default port remains 8080 - All existing CLI/API functionality unchanged - WebUI is entirely optional - Can be disabled by removing mountWebUI() call
This commit is contained in:
160
tests/frontend/test-frontend-dashboard.cjs
Normal file
160
tests/frontend/test-frontend-dashboard.cjs
Normal file
@@ -0,0 +1,160 @@
|
||||
/**
|
||||
* Frontend Test Suite - Dashboard Page
|
||||
* Tests the dashboard component functionality
|
||||
*
|
||||
* Run: node tests/test-frontend-dashboard.cjs
|
||||
*/
|
||||
|
||||
const http = require('http');
|
||||
|
||||
const BASE_URL = 'http://localhost:8090';
|
||||
|
||||
// Helper to make HTTP requests
|
||||
function request(path, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = new URL(path, BASE_URL);
|
||||
const req = http.request(url, {
|
||||
method: options.method || 'GET',
|
||||
headers: options.headers || {}
|
||||
}, (res) => {
|
||||
let data = '';
|
||||
res.on('data', chunk => data += chunk);
|
||||
res.on('end', () => {
|
||||
resolve({ status: res.statusCode, data, headers: res.headers });
|
||||
});
|
||||
});
|
||||
req.on('error', reject);
|
||||
if (options.body) req.write(JSON.stringify(options.body));
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
// Test cases
|
||||
const tests = [
|
||||
{
|
||||
name: 'Dashboard view loads successfully',
|
||||
async run() {
|
||||
const res = await request('/views/dashboard.html');
|
||||
if (res.status !== 200) {
|
||||
throw new Error(`Expected 200, got ${res.status}`);
|
||||
}
|
||||
if (!res.data.includes('x-data="dashboard"')) {
|
||||
throw new Error('Dashboard component not found in HTML');
|
||||
}
|
||||
if (!res.data.includes('quotaChart')) {
|
||||
throw new Error('Quota chart canvas not found');
|
||||
}
|
||||
return 'Dashboard HTML loads with component and chart';
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'Account limits API returns data',
|
||||
async run() {
|
||||
const res = await request('/account-limits');
|
||||
if (res.status !== 200) {
|
||||
throw new Error(`Expected 200, got ${res.status}`);
|
||||
}
|
||||
const data = JSON.parse(res.data);
|
||||
if (!data.accounts || !Array.isArray(data.accounts)) {
|
||||
throw new Error('accounts array not found in response');
|
||||
}
|
||||
if (!data.models || !Array.isArray(data.models)) {
|
||||
throw new Error('models array not found in response');
|
||||
}
|
||||
return `API returns ${data.accounts.length} accounts and ${data.models.length} models`;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'Dashboard has stats grid elements',
|
||||
async run() {
|
||||
const res = await request('/views/dashboard.html');
|
||||
const html = res.data;
|
||||
|
||||
const requiredElements = [
|
||||
'totalAccounts', // Total accounts stat
|
||||
'stats.total', // Total stat binding
|
||||
'stats.active', // Active stat binding
|
||||
'stats.limited', // Limited stat binding
|
||||
'quotaChart' // Chart canvas
|
||||
];
|
||||
|
||||
const missing = requiredElements.filter(el => !html.includes(el));
|
||||
if (missing.length > 0) {
|
||||
throw new Error(`Missing elements: ${missing.join(', ')}`);
|
||||
}
|
||||
return 'All required dashboard elements present';
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'Dashboard has filter controls',
|
||||
async run() {
|
||||
const res = await request('/views/dashboard.html');
|
||||
const html = res.data;
|
||||
|
||||
const filterElements = [
|
||||
'filters.account', // Account filter
|
||||
'filters.family', // Model family filter
|
||||
'filters.search', // Search input
|
||||
'computeQuotaRows' // Filter action
|
||||
];
|
||||
|
||||
const missing = filterElements.filter(el => !html.includes(el));
|
||||
if (missing.length > 0) {
|
||||
throw new Error(`Missing filter elements: ${missing.join(', ')}`);
|
||||
}
|
||||
return 'All filter controls present';
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'Dashboard table has required columns',
|
||||
async run() {
|
||||
const res = await request('/views/dashboard.html');
|
||||
const html = res.data;
|
||||
|
||||
const columns = [
|
||||
'modelIdentity', // Model name column
|
||||
'globalQuota', // Quota column
|
||||
'nextReset', // Reset time column
|
||||
'distribution' // Account distribution column
|
||||
];
|
||||
|
||||
const missing = columns.filter(col => !html.includes(col));
|
||||
if (missing.length > 0) {
|
||||
throw new Error(`Missing table columns: ${missing.join(', ')}`);
|
||||
}
|
||||
return 'All table columns present';
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
// Run tests
|
||||
async function runTests() {
|
||||
console.log('🧪 Dashboard Frontend Tests\n');
|
||||
console.log('='.repeat(50));
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
for (const test of tests) {
|
||||
try {
|
||||
const result = await test.run();
|
||||
console.log(`✅ ${test.name}`);
|
||||
console.log(` ${result}\n`);
|
||||
passed++;
|
||||
} catch (error) {
|
||||
console.log(`❌ ${test.name}`);
|
||||
console.log(` Error: ${error.message}\n`);
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('='.repeat(50));
|
||||
console.log(`Results: ${passed} passed, ${failed} failed`);
|
||||
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
runTests().catch(err => {
|
||||
console.error('Test runner failed:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user