| 123456789101112131415161718192021222324252627 |
- const BASE = 'http://192.168.16.204:4091';
- const AUTH = 'Basic ' + Buffer.from('opencode:' + (process.env.OPENCODE_SERVER_PASSWORD || 'IwinTrue@123')).toString('base64');
- const H = { Authorization: AUTH, 'Content-Type': 'application/json' };
- const LOC = '?location%5Bdirectory%5D=' + encodeURIComponent('D:\\cfc');
- async function j(url, opt) { try { const r = await fetch(url, Object.assign({ headers: H }, opt)); const t = await r.text(); try { return { status: r.status, json: JSON.parse(t) }; } catch { return { status: r.status, text: t }; } } catch (e) { return { status: 0, err: e.message }; } }
- async function sh(cmd, capMs) {
- const cr = await j(BASE + '/api/shell' + LOC, { method: 'POST', body: JSON.stringify({ command: cmd, cwd: 'D:\\cfc' }) });
- const id = cr.json && cr.json.data && cr.json.data.id;
- if (!id) return { err: 'create ' + cr.status + ' ' + JSON.stringify(cr).slice(0,200) };
- const t0 = Date.now();
- while (Date.now() - t0 < (capMs || 120000)) {
- await new Promise(r=>setTimeout(r,3000));
- const s = await j(BASE + '/api/shell/' + id + LOC);
- const d = (s.json && s.json.data) || null;
- if (!d) continue;
- if (d.status && d.status !== 'running') {
- const o = await j(BASE + '/api/shell/' + id + '/output' + LOC + '&limit=200000');
- return { code: d.status, out: (o.json && o.json.data && o.json.data.output) || '' };
- }
- }
- return { err: 'timeout' };
- }
- (async () => {
- // 前台同步跑(不重定向,直接输出),用 POSIX 风格路径避免 PowerShell 反斜杠转义
- const r = await sh('Set-Location D:/cfc/tests; $env:PLAYWRIGHT_HTML_REPORT="false"; npx playwright test -c playwright.config.live.js --project=frontend-mobile --reporter=line', 180000);
- console.log(r.err ? 'ERR=' + r.err : 'CODE=' + r.code + '\n' + r.out.slice(-1800));
- })().catch(e=>{console.error('ERR',e.message);process.exit(1);});
|