feat: redesign the web console with Vue and isolated account workspaces

This commit is contained in:
AttilaNet
2026-11-11 09:35:54 +08:00
parent 99aff423d8
commit ff6a828f58
46 changed files with 4549 additions and 748 deletions
@@ -6,6 +6,7 @@ Only temporary demo accounts and a synthetic administrator password are used.
from __future__ import annotations
import json
import re
from pathlib import Path
import socket
import tempfile
@@ -13,8 +14,9 @@ import threading
import time
import unittest
from unittest.mock import patch
from urllib.parse import urlsplit
from .test_workbench_browser import AVAILABLE, EDGE, OfflineUpdates
from .test_workbench_browser import AVAILABLE, EDGE, OfflineUpdates, assert_navigation
if AVAILABLE:
from playwright.sync_api import expect
@@ -81,9 +83,11 @@ class AdminLoginBrowserTests(unittest.TestCase):
self.context.route("**/*", offline_only)
self.page = self.context.new_page()
self.requests = []
self.script_requests = []
self.errors = []
self.csp_errors = []
self.page.on("request", lambda request: self.requests.append(request.url))
self.page.on("request", lambda request: self.script_requests.append(request.url) if request.resource_type == "script" else None)
self.page.on("pageerror", lambda failure: self.errors.append(str(failure)))
self.page.on("console", lambda message: self.csp_errors.append(message.text)
if message.type == "error" and ("security policy" in message.text.lower() or "csp" in message.text.lower()) else None)
@@ -98,7 +102,7 @@ class AdminLoginBrowserTests(unittest.TestCase):
expect(page).to_have_url(self.base + "/login")
expect(page.locator("#auth-form")).to_be_visible()
expect(page.locator("#admin-password")).to_be_enabled()
self.assertEqual(page.locator("#app, nav, #account-tabs, #page-tabs, #page-host, #auth-dialog").count(), 0)
self.assertEqual(page.locator("#app, nav, #sidebar, #topbar, #account-select, #account-tabs, #page-tabs, #page-host, #auth-dialog").count(), 0)
self.assertEqual(page.locator("script:not([src]), [style], [onclick], [onsubmit]").count(), 0)
self.assertEqual(page.locator("script").count(), 1)
expect(page.locator("script")).to_have_attribute("type", "module")
@@ -112,11 +116,15 @@ class AdminLoginBrowserTests(unittest.TestCase):
self.page.locator('#auth-form button[type="submit"]').click()
self.assertEqual(pending.value.status, 200)
self.assertEqual(pending.value.request.post_data_json, {"password": self.password})
expect(self.page).to_have_url(self.base + "/")
expect(self.page).to_have_url(re.compile("^" + re.escape(self.base + "/") + r"(?:#.*)?$"))
expect(self.page.locator("#app")).to_be_visible()
expect(self.page.locator("#page-tabs [role=tab]")).to_have_count(15)
expect(self.page.locator("#status-text")).to_have_text("工作台已连接")
assert_navigation(self.page)
expect(self.page.locator('.nav-link[data-page="overview"]')).to_have_attribute("aria-current", "page")
expect(self.page.locator("#status-text")).to_contain_text("已连接")
self.assertEqual(self.page.locator("#auth-dialog, #auth-form").count(), 0)
self.console_assets = self.page.locator('script[src], link[rel="stylesheet"], link[rel="modulepreload"]').evaluate_all(
"nodes => nodes.map(node => node.src || node.href)")
self.assertTrue(self.console_assets)
def observe_login_transition(self):
snapshots = []
@@ -147,15 +155,16 @@ class AdminLoginBrowserTests(unittest.TestCase):
context.add_cookies(cookies)
page = context.new_page()
requested = []
page.on("request", lambda request: requested.append(request.url))
page.on("request", lambda request: requested.append(request.url) if request.resource_type == "script" else None)
page.goto(self.base + "/", wait_until="networkidle")
self.assert_login_only(page)
self.assertFalse(any(url.endswith("/static/app.js") for url in requested))
self.assertEqual(requested, [self.base + "/static/login.js"])
response = context.request.get(self.base + "/static/index.html", max_redirects=0)
self.assertIn(response.status, (302, 303, 307, 401, 403))
self.assertNotIn('id="app"', response.text())
response = context.request.get(self.base + "/static/app.js", max_redirects=0)
self.assertIn(response.status, (302, 303, 307, 401, 403))
for url in self.console_assets:
response = context.request.get(url, max_redirects=0)
self.assertIn(response.status, (302, 303, 307, 401, 403), url)
def test_fresh_root_serves_only_login_and_public_assets_with_csp(self):
response = self.page.goto(self.base + "/", wait_until="networkidle")
@@ -169,7 +178,7 @@ class AdminLoginBrowserTests(unittest.TestCase):
self.assertIn(self.base + "/api/auth/status", self.requests)
scripts = self.page.evaluate("performance.getEntriesByType('resource').filter(item => item.initiatorType === 'script').map(item => new URL(item.name).pathname)")
self.assertEqual(scripts, ["/static/login.js"])
self.assertFalse(any(url.endswith(("/app.js", "/api.js", "/pages.js", "/dom.js", "/ui.js")) for url in self.requests))
self.assertEqual(self.script_requests, [self.base + "/static/login.js"])
for width in (1280, 390):
self.page.set_viewport_size({"width": width, "height": 800})
self.assertLessEqual(self.page.evaluate("document.documentElement.scrollWidth"), width)
@@ -185,10 +194,10 @@ class AdminLoginBrowserTests(unittest.TestCase):
self.assertEqual(self.page.evaluate("localStorage.length + sessionStorage.length"), 0)
self.assertNotIn(self.password, self.page.url)
self.page.goto(self.base + "/login", wait_until="networkidle")
expect(self.page).to_have_url(self.base + "/")
expect(self.page.locator("#page-tabs [role=tab]")).to_have_count(15)
self.assertEqual(urlsplit(self.page.url).path, "/")
assert_navigation(self.page)
snapshots = self.observe_login_transition()
self.page.locator(".menu > summary").first.click()
self.page.locator('.nav-link[data-page="system"]').click()
self.page.locator('[data-command="admin-logout"]').click()
self.assert_hidden_transition(snapshots)
self.assert_login_only()
@@ -207,12 +216,13 @@ class AdminLoginBrowserTests(unittest.TestCase):
expect(self.page.locator("#admin-password")).to_be_focused()
self.assert_login_only()
self.assertEqual(self.page.evaluate("localStorage.length + sessionStorage.length"), 0)
self.assertFalse(any("offline-wrong-admin-password" in url or url.endswith("/app.js") for url in self.requests))
self.assertFalse(any("offline-wrong-admin-password" in url for url in self.requests))
self.assertEqual(self.script_requests, [self.base + "/static/login.js"])
def test_expired_server_session_hides_workbench_and_rejects_old_cookie(self):
self.login()
cookies = self.context.cookies()
self.page.locator(".menu > summary").nth(3).click()
self.page.locator('.nav-link[data-page="system"]').click()
self.page.locator('[data-command="about"]').click()
expect(self.page.locator("#action-dialog")).to_be_visible()
snapshots = self.observe_login_transition()
@@ -233,6 +243,8 @@ class AdminLoginBrowserTests(unittest.TestCase):
route.fulfill(status=401, content_type="application/json", body=json.dumps({"detail": "会话已失效"}))
self.page.route("**/api/accounts/*/actions/refresh", unauthorized)
self.page.locator('.nav-link[data-page="login"]').click()
expect(self.page.locator('.page-panel[data-page="login"]:not([hidden]) .page-loading[data-loading="false"]')).to_have_count(1)
self.page.locator('#page-host input[type="password"]').fill("unsent-offline-game-password")
self.page.locator("#refresh").click()
self.assert_hidden_transition(snapshots)
@@ -272,7 +284,7 @@ class AdminLoginBrowserTests(unittest.TestCase):
response = page.goto(self.base + "/", wait_until="networkidle")
expect(page).to_have_url(self.base + "/login")
self.assertNotIn('id="app"', response.text())
self.assertEqual(page.locator("#app, nav, #account-tabs, #page-tabs").count(), 0)
self.assertEqual(page.locator("#app, nav, #sidebar, #topbar, #account-select, #account-tabs, #page-tabs").count(), 0)
expect(page.locator("#auth-form")).to_be_visible()
expect(page.locator("#auth-form button")).to_be_disabled()
expect(page.locator("noscript")).to_be_visible()