CloudLab CI/CD / 门禁 doctor (push) Failing after 4m59s
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
- 数据看板支持自定义数据:粘贴 CSV/TSV 或上传文件,本机解析后直接 统计/绘图/预览(与预设数据同一套分析能力),用自己的数据做实验 - 新增基础实验「稀释配制」:稀释定律 C₁V₁=C₂V₂,填三项求第四项, 含计算过程展示与常用预设,真实计算可操作 - 验证:不变量 216/FAIL 0、自定义数据 6/6、稀释计算 4/4、拖拽 7/7 Co-Authored-By: WorkBuddy <noreply@workbuddy.ai>
57 lines
3.8 KiB
JavaScript
57 lines
3.8 KiB
JavaScript
#!/usr/bin/env node
|
||
// 自定义数据实验验证
|
||
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 OUT = join(ROOT, '..', '.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 b; try { b = readFileSync(join(ROOT, p)); } 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=9239', '--user-data-dir=' + join(OUT, '_pc2'), '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:9239/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();
|
||
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); } };
|
||
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('Page.navigate', { url: BASE + '/app/lab.html' });
|
||
await sleep(2200);
|
||
|
||
// 展开自定义数据区
|
||
await ev(`(function(){var b=document.getElementById('dt-custom-toggle'); if(b) b.click(); return 1;})()`);
|
||
await sleep(300);
|
||
check('自定义数据区展开', await ev(`!document.getElementById('dt-custom-area').hidden`));
|
||
|
||
// 粘贴自定义 CSV 并载入
|
||
const r = await ev(`(function(){
|
||
var csv='time,growth,temp\\n0,0.10,37\\n1,0.18,37\\n2,0.32,36.8\\n3,0.55,36.9\\n4,0.92,37.1\\n5,1.40,37.0';
|
||
document.getElementById('dt-custom-text').value=csv;
|
||
document.getElementById('dt-custom-run').click();
|
||
return 1;
|
||
})()`);
|
||
await sleep(1000);
|
||
|
||
check('自定义数据载入(数据看板)', await ev(`document.getElementById('dt-name').textContent.indexOf('自定义')>=0`));
|
||
check('行列统计正确(6 行 × 3 列)', (await ev(`document.getElementById('dt-shape').textContent`)).indexOf('6 行 × 3 列') >= 0);
|
||
check('数据表预览渲染', await ev(`document.querySelectorAll('#dt-table table tbody tr').length > 0`));
|
||
check('统计区有输出', await ev(`document.getElementById('dt-stats').children.length > 0 || document.getElementById('dt-stats').innerHTML.length > 20`));
|
||
check('图表区已绘制(canvas 有内容)', await ev(`(function(){var c=document.getElementById('dt-chart'); return c && c.width>0;})()`));
|
||
|
||
// 截图
|
||
const rr = await send('Page.captureScreenshot', { format: 'png' });
|
||
if (rr.result && rr.result.data) writeFileSync(join(OUT, 'custom-data.png'), Buffer.from(rr.result.data, 'base64'));
|
||
|
||
console.log(`\n结果: ${pass} 通过 / ${fail} 失败`);
|
||
ws.close(); chrome.kill(); srv.close(); process.exit(fail ? 1 : 0);
|