v0.33.2
This commit is contained in:
1 parent
b757b34a31
commit
5a36bb0c4b
20 files changed
+356
-186
No files matched your search
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
"""System Load RAM meter updates using the actual combined panel JavaScript.
|
||||
|
||||
This is a simulated authenticated DOM/status test, not a Rust runtime integration test.
|
||||
"""
|
||||
from pathlib import Path
|
||||
import json
|
||||
import re
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
router = (ROOT / 'src/admin/router.rs').read_text()
|
||||
|
||||
def bundle_for(section):
|
||||
match = re.search(r'fn ' + section + r'\([^)]*\)[^{]*\{', router)
|
||||
assert match, section
|
||||
text = router[match.end():]
|
||||
text = text[:re.search(r'\]\s*\.join\("\\n"\)', text).start()]
|
||||
result = []
|
||||
for line in text.splitlines():
|
||||
line = line.strip()
|
||||
if 'include_str!("' in line:
|
||||
path = re.search(r'include_str!\("([^"]+)"\)', line).group(1)
|
||||
result.append((ROOT / 'src/admin' / path).read_text())
|
||||
elif line == 'admin_vhosts_javascript(),':
|
||||
result.append('(() => {\n' + ''.join((ROOT / 'src/admin/web/vhosts' / f'{part}.js').read_text() + '\n'
|
||||
for part in ['core', 'protocol', 'health', 'rates', 'editor', 'render']) + '})();')
|
||||
elif line.startswith('"') and line.endswith('",'):
|
||||
result.append(json.loads(line[:-1]))
|
||||
return '\n'.join(result)
|
||||
|
||||
html = (ROOT / 'src/admin/web/index.html').read_text()
|
||||
css = (ROOT / 'src/admin/web/style.css').read_text()
|
||||
js = bundle_for('admin_app_javascript')
|
||||
with sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(headless=True, executable_path='/usr/bin/chromium', args=['--no-sandbox'])
|
||||
for width in (375, 1440):
|
||||
page = browser.new_page(viewport={'width': width, 'height': 900})
|
||||
errors = []
|
||||
page.on('pageerror', lambda error: errors.append(str(error)))
|
||||
page.set_content(html.replace('/assets/app___RUSTPROXY_ASSET_ID__.js', '').replace('/assets/style___RUSTPROXY_ASSET_ID__.css', ''))
|
||||
page.add_style_tag(content=css)
|
||||
page.add_script_tag(content=js)
|
||||
page.wait_for_timeout(100)
|
||||
report = page.evaluate('''() => {
|
||||
currentPanel = "overview";
|
||||
document.getElementById('workspace').hidden = false;
|
||||
document.getElementById('panel-overview').hidden = false;
|
||||
const meter = document.getElementById('memory-meter');
|
||||
const fill = document.getElementById('memory-meter-fill');
|
||||
const snapshot = (used, total) => ({system: {source:'measured',cpu_percent:2.1,
|
||||
memory_used_bytes:used, memory_total_bytes:total},
|
||||
live_system:{cpu_percent:2.1}, cache:{}, metrics:{}, listeners:{}});
|
||||
const values = [];
|
||||
for (const [used, total] of [[250,1000],[800,1000],[0,1000],[null,null]]) {
|
||||
renderDiagnostics(snapshot(used,total), false, true);
|
||||
values.push({fill:fill.style.width, now:meter.getAttribute('aria-valuenow'),
|
||||
hidden:meter.hidden, text:meter.getAttribute('aria-valuetext')});
|
||||
}
|
||||
return { values, role:meter.getAttribute('role'), cssHeight:getComputedStyle(meter).height,
|
||||
scrollbar:document.documentElement.scrollWidth>window.innerWidth+2 };
|
||||
}''')
|
||||
assert report['role'] == 'progressbar' and report['cssHeight'] == '5px', report
|
||||
assert report['values'][0]['fill'] == '25%' and report['values'][0]['now'] == '25', report
|
||||
assert report['values'][1]['fill'] == '80%' and report['values'][1]['now'] == '80', report
|
||||
assert report['values'][2]['fill'] == '0%' and report['values'][2]['now'] == '0', report
|
||||
assert report['values'][3]['fill'] == '0%' and report['values'][3]['now'] is None and report['values'][3]['hidden'], report
|
||||
assert not report['scrollbar'] and not errors, (width, errors, report)
|
||||
page.close()
|
||||
browser.close()
|
||||
print('PASS: System RAM meter live percentage and unknown/zero handling on 375/1440px in bundled panel.')
|
||||
Reference in new issue
Block a user