dispatch_189_admin.cjs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // R150 189 admin-desktop E2E 派发(PowerShell 5.1;不 reset 工作区,仅取证 HEAD + spec blob)
  2. const BASE = process.env.OPENCODE_189_BASE || 'http://192.168.16.189:4090';
  3. const AUTH = 'Basic ' + Buffer.from('opencode:' + (process.env.OPENCODE_SERVER_PASSWORD || 'IwinTrue@123')).toString('base64');
  4. const capMs = parseInt(process.env.DISPATCH_CAP_MS || '540000', 10);
  5. const CMD = process.env.E2E_CMD ||
  6. 'cd C:\\code\\cfc; git rev-parse --short HEAD; git hash-object tests\\e2e-live\\admin-live.spec.js; cd tests; npx playwright test -c playwright.config.live.js --project=admin-desktop --reporter=list --workers=1; echo "EXIT=$LASTEXITCODE"';
  7. async function j(url, opt) {
  8. try {
  9. const r = await fetch(url, Object.assign({ headers: { 'Authorization': AUTH, 'Content-Type': 'application/json' } }, opt || {}));
  10. const t = await r.text();
  11. try { return { status: r.status, json: JSON.parse(t) }; } catch { return { status: r.status, text: t }; }
  12. } catch (e) { return { status: 0, err: e.message }; }
  13. }
  14. (async () => {
  15. const cr = await j(BASE + '/api/shell', { method: 'POST', body: JSON.stringify({ command: CMD }) });
  16. const id = (cr.json && cr.json.data && cr.json.data.id) || (cr.json && cr.json.id);
  17. if (!id) { console.log('CREATE_FAIL ' + cr.status + ' ' + JSON.stringify(cr).slice(0, 300)); return; }
  18. console.log('SHELL_ID ' + id);
  19. const t0 = Date.now();
  20. let last = '';
  21. while (Date.now() - t0 < capMs) {
  22. await new Promise(r => setTimeout(r, 6000));
  23. const st = await j(BASE + '/api/shell/' + id);
  24. const s = (st.json && ((st.json.data && st.json.data.status) || st.json.status)) || '?';
  25. if (s !== last) { console.log('STATUS ' + s + ' @' + Math.round((Date.now() - t0) / 1000) + 's'); last = s; }
  26. if (s && s !== 'running' && s !== 'pending' && s !== 'queued') {
  27. const o = await j(BASE + '/api/shell/' + id + '/output');
  28. const out = (o.json && o.json.data && o.json.data.output) || '';
  29. console.log('===OUTPUT===');
  30. console.log(out.slice(-7000));
  31. return;
  32. }
  33. }
  34. console.log('TIMEOUT ' + capMs + 'ms');
  35. })();