Files
hmandWorkBuddy 2a10d0371b
CloudLab CI/CD / 门禁 doctor (push) Failing after 44s
CloudLab CI/CD / 单元测试 (push) Skipped
CloudLab CI/CD / 归档完整性 (push) Skipped
CloudLab CI/CD / 构建站点与归档 (push) Skipped
CloudLab CI/CD / 部署到 lab.hdtime.space(rsync) (push) Skipped
CloudLab CI/CD / 构建镜像并推送 Gitea 容器仓库 (push) Skipped
CloudLab CI/CD / 容器部署到 lab.hdtime.space (push) Skipped
CloudLab CI/CD / 发布版本(Tag) (push) Skipped
perf+ui: 分子设计台 42MB→5.3MB 瘦身 + 全屏下书架功能可达
性能优化:
- 两个「分子设计台.html」(AtomLab 与生命科学资料库副本)内嵌 41.6MB JSON
  改为 gzip+base64(5.1MB),页面 42MB→5.32MB(压缩 87%),
  用内嵌 pako 同步解压,保持「双击即用、零网络依赖」的离线单文件特性
- build_ui.py / ui_template.html 同步改造,以后生成的页面也是压缩版
  (新增 src/pako_inflate.min.js,21KB)
- 验证解压后 118 元素 / 622 分子 / 23 顶层键完整,UI 下拉已填充,无 JS 异常

交互修复:
- 默认全屏此前把「我的书架 / 最近阅读 / 我的资料架」一并隐藏,功能不可达;
  现只隐藏「八个资料库」介绍与 footer,个人功能保留并紧凑化(标题缩小、描述隐藏)

验证:不变量 216/FAIL 0,全套 16 个 UI 测试全过(新 optimize 10/10)

Co-Authored-By: WorkBuddy <noreply@workbuddy.ai>
2026-11-21 19:56:02 +08:00

85 lines
4.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
// 验证:AtomLab 压缩页面数据完整 + 默认全屏下书架功能可达
import { spawn } from 'node:child_process';
import { createServer } from 'node:http';
import { readFileSync, writeFileSync } from 'node:fs';
import { dirname, join, extname } from 'node:path';
import { fileURLToPath } from 'node:url';
const HERE = dirname(fileURLToPath(import.meta.url));
const ROOT = join(HERE, '..');
const REPO = join(ROOT, '..');
const OUT = join(REPO, '.workbuddy', 'shots');
const MIME = { '.html': 'text/html', '.css': 'text/css', '.js': 'text/javascript', '.svg': 'image/svg+xml', '.json': 'application/json' };
const srv = createServer((q, r) => {
let p = decodeURIComponent(q.url.split('?')[0]); if (p.endsWith('/')) p += 'index.html';
let fp = p.startsWith('/app/') ? join(ROOT, p) : join(REPO, p);
let b; try { b = readFileSync(fp); } catch { r.writeHead(404); r.end(); return; }
r.writeHead(200, { 'Content-Type': MIME[extname(p)] || 'application/octet-stream' }); r.end(b);
});
await new Promise(r => srv.listen(0, '127.0.0.1', r));
const BASE = `http://127.0.0.1:${srv.address().port}`;
const chrome = spawn('C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe', ['--headless=new', '--disable-gpu', '--remote-debugging-port=9251', '--user-data-dir=' + join(OUT, '_po'), '--window-size=1440,1000', 'about:blank']);
const sleep = ms => new Promise(r => setTimeout(r, ms));
let targets;
for (let i = 0; i < 40; i++) { try { targets = await (await fetch('http://127.0.0.1:9251/json/list')).json(); if (targets.length) break; } catch {} await sleep(400); }
const ws = new WebSocket(targets.find(t => t.type === 'page').webSocketDebuggerUrl);
await new Promise(r => ws.onopen = r);
let id = 0; const pending = new Map(); const errors = [];
ws.onmessage = e => {
const m = JSON.parse(e.data);
if (m.id && pending.has(m.id)) { pending.get(m.id)(m); pending.delete(m.id); }
if (m.method === 'Runtime.exceptionThrown') errors.push(m.params.exceptionDetails.text);
};
const send = (m, p = {}) => new Promise(res => { const i = ++id; pending.set(i, res); ws.send(JSON.stringify({ id: i, method: m, params: p })); });
const ev = async ex => { const r = await send('Runtime.evaluate', { expression: ex, returnByValue: true }); return r.result && r.result.result ? r.result.result.value : undefined; };
let pass = 0, fail = 0;
const check = (n, c) => { console.log((c ? ' ✅ ' : ' ❌ ') + n); c ? pass++ : fail++; };
await send('Runtime.enable');
// ---------- 1) AtomLab 压缩页 ----------
const t0 = Date.now();
await send('Page.navigate', { url: BASE + '/AtomLab/分子设计台.html' });
await sleep(4000);
const d = await ev(`(function(){
var D=window.ATOM_DATA;
if(!D) return null;
return {
elements: D.elements && D.elements.meta && D.elements.meta.n,
molecules: (D.molecules && D.molecules.molecules) ? D.molecules.molecules.length : null,
keys: Object.keys(D).length,
hasUI: !!document.querySelector('.stage-foot') || document.body.textContent.indexOf('分子浏览器')>=0,
selectOptions: document.querySelectorAll('select option').length,
bodyLen: document.body.textContent.length
};
})()`);
check('gzip 数据解压成功', d && d.elements === 118);
check('分子库完整(622)', d && d.molecules >= 600);
check('数据驱动 UI(下拉选项已填充)', d && d.selectOptions > 100);
check('页面 UI 已渲染', d && d.bodyLen > 500);
check('无 JS 运行时异常', errors.length === 0);
console.log(' 数据:', d, '加载耗时约', Date.now() - t0, 'ms', errors.length ? '异常:' + errors[0] : '');
// ---------- 2) 默认全屏下书架可达 ----------
await send('Page.navigate', { url: BASE + '/app/browse.html' });
await sleep(2500);
const vis = await ev(`(function(){
function shown(sel){var e=document.querySelector(sel); return e && getComputedStyle(e).display!=='none';}
return {
full: document.documentElement.classList.contains('cl-focus-work'),
fav: shown('#fav-section'), recent: shown('#recent-section'), uploads: shown('#uploads-section'),
intro: (function(){var all=document.querySelectorAll('.home-section'); for(var i=0;i<all.length;i++){if(!all[i].id && getComputedStyle(all[i]).display!=='none') return true;} return false;})()
};
})()`);
check('默认全屏仍生效', vis && vis.full === true);
check('我的书架在全屏下可达', vis && vis.fav === true);
check('最近阅读在全屏下可达', vis && vis.recent === true);
check('我的资料架在全屏下可达', vis && vis.uploads === true);
check('八个资料库介绍仍隐藏', vis && vis.intro === false);
console.log(' ', vis);
const r = await send('Page.captureScreenshot', { format: 'png' });
if (r.result && r.result.data) writeFileSync(join(OUT, 'shelf-visible.png'), Buffer.from(r.result.data, 'base64'));
console.log(`\n结果: ${pass} 通过 / ${fail} 失败`);
ws.close(); chrome.kill(); srv.close(); process.exit(fail ? 1 : 0);