| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- // 189 admin-desktop E2E via opencode SHELL channel v2 (POST /api/shell direct, PowerShell 5.1 compatible)
- // Auth: opencode:IwinTrue@123
- const BASE = process.env.OPENCODE_189_BASE || 'http://192.168.16.189:4090';
- const AUTH = 'Basic ' + Buffer.from('opencode:' + (process.env.OPENCODE_SERVER_PASSWORD || 'IwinTrue@123')).toString('base64');
- const capMs = parseInt(process.env.DISPATCH_CAP_MS || '540000', 10);
- // PowerShell 5.1: use ; as separator, $LASTEXITCODE for exit code
- const CMD = 'cd tests; git fetch origin 2>&1 | Select-Object -Last 2; git reset --hard origin/cfclub 2>&1 | Select-Object -Last 2; npx playwright test -c playwright.config.live.js --project=admin-desktop --reporter=list; echo "EXIT=$LASTEXITCODE"';
- async function j(url, opt) {
- const r = await fetch(url, Object.assign({ headers: { 'Authorization': AUTH, 'Content-Type': 'application/json' } }, opt));
- const t = await r.text();
- try { return { status: r.status, json: JSON.parse(t) }; } catch { return { status: r.status, text: t }; }
- }
- async function main() {
- const cr = await j(BASE + '/api/shell', { method: 'POST', body: JSON.stringify({ command: CMD }) });
- const shellId = (cr.json.data && cr.json.data.id) || cr.json.id;
- if (!shellId) throw new Error('no shell id on create: ' + JSON.stringify(cr.json).slice(0, 200));
- console.log('SHELL_ID', shellId, 'status', cr.json.data && cr.json.data.status);
- const start = Date.now();
- let last = '';
- while (Date.now() - start < capMs) {
- await new Promise(r => setTimeout(r, 6000));
- const st = await j(BASE + '/api/shell/' + shellId);
- const status = (st.json && ((st.json.data && st.json.data.status) || st.json.status)) || '?';
- if (status !== last) { console.log('SHELL_STATUS', status, '@', Math.round((Date.now() - start) / 1000) + 's'); last = status; }
- if (status && status !== 'running' && status !== 'pending' && status !== 'queued') {
- const out = await j(BASE + '/api/shell/' + shellId + '/output');
- const o = (out.json && out.json.data && out.json.data.output) || '';
- console.log('OUTPUT_BEGIN');
- console.log(o.slice(-6000));
- console.log('OUTPUT_END');
- return;
- }
- }
- console.log('SHELL_TIMEOUT after ' + capMs + 'ms');
- }
- main().catch(e => { console.error('ERR', e.message); process.exit(1); });
|