dispatch_251_shell_v2.cjs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // 251 langgraph pytest via SHELL channel v2 (POST /api/shell direct, bash) - R117 retry
  2. const BASE = process.env.OPENCODE_251_BASE || 'http://192.168.16.251:4096';
  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 || '720000', 10);
  5. const CMD = 'cd /sc-data/cfc/cfc-langgraph && git fetch origin 2>&1 | tail -2; git reset --hard origin/cfclub 2>&1 | tail -2; timeout 650 .venv/bin/python -m pytest tests --ignore=tests/qna --ignore=tests/test_chat.py -q --tb=line; echo EXIT=$?';
  6. async function j(url, opt) {
  7. const r = await fetch(url, Object.assign({ headers: { 'Authorization': AUTH, 'Content-Type': 'application/json' } }, opt));
  8. const t = await r.text();
  9. try { return { status: r.status, json: JSON.parse(t) }; } catch { return { status: r.status, text: t }; }
  10. }
  11. async function main() {
  12. const cr = await j(BASE + '/api/shell', { method: 'POST', body: JSON.stringify({ command: CMD }) });
  13. const shellId = (cr.json.data && cr.json.data.id) || cr.json.id;
  14. if (!shellId) throw new Error('no shell id on create: ' + JSON.stringify(cr.json).slice(0, 200));
  15. console.log('SHELL_ID', shellId, 'status', cr.json.data && cr.json.data.status);
  16. const start = Date.now();
  17. let last = '';
  18. while (Date.now() - start < capMs) {
  19. await new Promise(r => setTimeout(r, 8000));
  20. const st = await j(BASE + '/api/shell/' + shellId);
  21. const status = (st.json && ((st.json.data && st.json.data.status) || st.json.status)) || '?';
  22. if (status !== last) { console.log('SHELL_STATUS', status, '@', Math.round((Date.now() - start) / 1000) + 's'); last = status; }
  23. if (status && status !== 'running' && status !== 'pending' && status !== 'queued') {
  24. const out = await j(BASE + '/api/shell/' + shellId + '/output');
  25. const o = (out.json && out.json.data && out.json.data.output) || '';
  26. console.log('OUTPUT_BEGIN');
  27. console.log(o.slice(-6000));
  28. console.log('OUTPUT_END');
  29. return;
  30. }
  31. }
  32. console.log('SHELL_TIMEOUT after ' + capMs + 'ms');
  33. }
  34. main().catch(e => { console.error('ERR', e.message); process.exit(1); });