@webority/sandbox-gate 0.168.0 → 0.169.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import{spawn as e,spawnSync as t}from"node:child_process";import{existsSync as n
5
5
  `).filter(Boolean);for(let e of n)t(`kill`,[`-9`,e],{stdio:`ignore`});return n.length>0&&M.set(e,performance.now()),n.length>0}function P(e,t){let n=M.get(e);return n!==void 0&&n>=t}function F(){let e=process.platform===`win32`?t(`powershell`,[`-NoProfile`,`-Command`,`Get-CimInstance Win32_Process | ForEach-Object { '{0} {1}' -f $_.ProcessId, $_.ParentProcessId }`],{encoding:`utf8`}):t(`ps`,[`-A`,`-o`,`pid=,ppid=`],{encoding:`utf8`});if(e.status!==0)throw Error(`Listing processes failed (exit ${e.status}): ${e.stderr}`);let n=/* @__PURE__ */ new Map;for(let t of e.stdout.split(/\r?\n/)){let e=t.trim().match(/^(\d+)\s+(\d+)$/);e&&n.set(Number(e[1]),Number(e[2]))}return n}function I(e,t){let n=[],r=[t];for(;r.length>0;){let i=[];for(let[a,o]of e)r.includes(o)&&a!==t&&!n.includes(a)&&(n.push(a),i.push(a));r=i}return n}function L(e=process.pid){let t=0;for(let n=0;n<3;n+=1){let n=I(F(),e);if(n.length===0)return t;for(let e of n.reverse())try{process.kill(e,`SIGKILL`),t+=1}catch(e){if(R(e)!==`ESRCH`)throw e}}return t}function R(e){return e instanceof Error&&`code`in e?e.code:void 0}function z(e){try{process.kill(e,`SIGKILL`)}catch(t){let n=R(t);if(n===`ESRCH`||n===`EPERM`&&e<0)return;throw t}}function B(e){L(e),z(e),process.platform!==`win32`&&z(-e)}var ee=[`react`,`razor`,`phoneWeb`],te=/Port \d+ is already in use|address already in use|EADDRINUSE/i;function ne({log:e,retriesLeft:t,killed:n}){return!n&&t>0&&te.test(e)}function re(t){let{which:r,ports:o,origins:l,readyUrls:d={},reactFilter:f=`@webority/react-sandbox`,razorProject:p=`samples/Razor.Sandbox`,phoneWebDir:m=`samples/mobile-sandbox-web`,tag:h,env:g={}}=t,_=e=>{let t=o[e];if(t===void 0)throw Error(`bootSandboxes: no port for "${e}"`);return t},v=e=>{let t=l[e];if(t===void 0)throw Error(`bootSandboxes: no origin for "${e}"`);return t};for(let e of r){if(!ee.includes(e))throw Error(`bootSandboxes: unknown sandbox "${e}"`);_(e),v(e)}let y=e=>{switch(e){case`react`:return[`corepack`,[`pnpm`,`--filter`,f,`dev`,`--port`,String(_(`react`)),`--strictPort`]];case`razor`:return[`dotnet`,[`run`,`--project`,p,`--no-build`,`--`,`--urls`,v(`razor`)]];case`phoneWeb`:return[`corepack`,[`pnpm`,`--dir`,m,`exec`,`vite`,`--port`,String(_(`phoneWeb`)),`--strictPort`]]}},b=e=>u(c(),`webority-gate-${h?`${e}-${h}`:e}-sandbox-${process.pid}.log`),x={};for(let e of r)x[e]=b(e);let S=[];D(`\nStarting the sandboxes (${r.join(`, `)})... (output: ${r.map(e=>b(e)).join(`, `)})`);let C=[],w=(t,r,o)=>{let[s,c]=y(t),l=b(t);N(_(t));let u=i(l,`w`),d=e(O(s,c),{stdio:[`ignore`,u,u],shell:!0,env:{...process.env,...g,WEBORITY_GATE_SANDBOX:`1`}}),f=performance.now();return d.on(`exit`,(e,i)=>{ne({log:n(l)?a(l,`utf8`):``,retriesLeft:o,killed:d.killed})?(D(`\nThe ${t} sandbox's port ${_(t)} was taken; freeing it and starting the sandbox once more.`),C[r]=w(t,r,o-1)):d.killed||S.push({name:t,port:_(t),code:e,signal:i,log:l,stoppedByGate:P(_(t),f)})}),d};r.forEach((e,t)=>{C[t]=w(e,t,1)});let T=r.map(e=>d[e]??v(e));async function E(){for(let e of T)if(!await j(e))return!1;return!0}return{children:C,logs:x,deaths:()=>[...S],async waitReady({attempts:e=600,intervalMs:t=300}={}){for(let n=0;n<e;n+=1){if(await E())return!0;await new Promise(e=>setTimeout(e,t))}return!1},finish(e){if(e===0)for(let e of Object.values(x))e!==void 0&&s(e,{force:!0});else for(let[e,t]of Object.entries(x)){if(t===void 0||!n(t))continue;let r=a(t,`utf8`).trimEnd().split(`
6
6
  `),i=r.findIndex(e=>/Exception: |^\s*Error: /.test(e));i!==-1&&i<r.length-25&&D(`\n──── ${e} sandbox log, first error (${t}:${i+1}) ────\n${r.slice(i,i+3).join(`
7
7
  `)}`),D(`\n──── ${e} sandbox log, last 25 lines (${t}) ────\n${r.slice(-25).join(`
8
- `)}`)}}}}function ie({ports:e=[],children:t=[]}={}){for(let e of t)e.kill();for(let t of e)N(t);return w()}function ae({name:e,port:t,code:n,signal:r,log:i,stoppedByGate:a}){let o=r?`signal ${r}`:`exit ${n}`,s=r===`SIGKILL`||n===137;return`The ${e} sandbox ended before the run did (${o}): ${s&&a?`the gate itself ended it when it freed port ${t}, while the sandbox was still in use`:s?`the system killed it, usually for lack of memory`:`it stopped on its own`}. This is an infrastructure failure, not a test failure: rerun the gate. Log: ${i}`}var oe=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,V=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,H=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`,U={first:7e3,end:1e4},W=[7e3,7474,7687,8e3,8008,8080,8081,8443,8888,9e3,9090,9092,9200,9229,9300],G=8;function K(e,t=2){if(!Number.isInteger(t)||t<1||t>8)throw RangeError(`derivePorts: count must be 1 to 8, got ${t}`);let{first:n,end:r}=U,i=(r-n)/G,a=d(`sha1`).update(e).digest().readUInt16BE(0)%i;for(let e=0;e<i;e++){let r=n+(a+e)%i*G;if(!W.some(e=>e>=r&&e<r+G))return Array.from({length:t},(e,t)=>r+t)}throw Error(`derivePorts: no free port slot`)}var se=124,ce=3,le=5e3,q=/* @__PURE__ */ new Set,J=!1;function Y(e){if(!(Number.isFinite(e.limitMs)&&e.limitMs>0))throw Error(`${e.label}: limitMs must be a positive number of milliseconds, not ${e.limitMs}. Every gate task states its limit.`)}function X(t,n={}){Y(t);let{command:r,args:i,label:a,limitMs:o}=t;return new Promise(t=>{let s=performance.now(),c=[],l=!1,u=!1,d=!1,f,p,m,h=e(O(r,i),{shell:!0,env:{...process.env,...n},detached:process.platform!==`win32`,windowsHide:!0});h.pid!==void 0&&(q.add(h.pid),J||(J=!0,process.on(`exit`,()=>{if(process.platform!==`win32`)for(let e of q)try{process.kill(-e,`SIGKILL`)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ESRCH`))throw e}})));let g=e=>{if(d)return;d=!0,clearTimeout(f),clearTimeout(p),clearTimeout(m),h.pid!==void 0&&q.delete(h.pid);let n=Math.round(performance.now()-s),r=Buffer.concat(c).toString();if(!l){t({label:a,code:e,output:r,ms:n,...u?{slow:!0}:{}});return}let i=r.endsWith(`
8
+ `)}`)}}}}function ie({ports:e=[],children:t=[]}={}){for(let e of t)e.kill();for(let t of e)N(t);return w()}function ae({name:e,port:t,code:n,signal:r,log:i,stoppedByGate:a}){let o=r?`signal ${r}`:`exit ${n}`,s=r===`SIGKILL`||n===137;return`The ${e} sandbox ended before the run did (${o}): ${s&&a?`the gate itself ended it when it freed port ${t}, while the sandbox was still in use`:s?`the system killed it, usually for lack of memory`:`it stopped on its own`}. This is an infrastructure failure, not a test failure: rerun the gate. Log: ${i}`}var oe=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,V=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,H=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`,U={first:7e3,end:1e4},W=[7e3,7474,7687,8e3,8008,8080,8081,8443,8888,9e3,9090,9092,9200,9229,9300],G=12;function K(e,t=2){if(!Number.isInteger(t)||t<1||t>12)throw RangeError(`derivePorts: count must be 1 to 12, got ${t}`);let{first:n,end:r}=U,i=(r-n)/G,a=d(`sha1`).update(e).digest().readUInt16BE(0)%i;for(let e=0;e<i;e++){let r=n+(a+e)%i*G;if(!W.some(e=>e>=r&&e<r+G))return Array.from({length:t},(e,t)=>r+t)}throw Error(`derivePorts: no free port slot`)}var se=124,ce=3,le=5e3,q=/* @__PURE__ */ new Set,J=!1;function Y(e){if(!(Number.isFinite(e.limitMs)&&e.limitMs>0))throw Error(`${e.label}: limitMs must be a positive number of milliseconds, not ${e.limitMs}. Every gate task states its limit.`)}function X(t,n={}){Y(t);let{command:r,args:i,label:a,limitMs:o}=t;return new Promise(t=>{let s=performance.now(),c=[],l=!1,u=!1,d=!1,f,p,m,h=e(O(r,i),{shell:!0,env:{...process.env,...n},detached:process.platform!==`win32`,windowsHide:!0});h.pid!==void 0&&(q.add(h.pid),J||(J=!0,process.on(`exit`,()=>{if(process.platform!==`win32`)for(let e of q)try{process.kill(-e,`SIGKILL`)}catch(e){if(!(e instanceof Error&&`code`in e&&e.code===`ESRCH`))throw e}})));let g=e=>{if(d)return;d=!0,clearTimeout(f),clearTimeout(p),clearTimeout(m),h.pid!==void 0&&q.delete(h.pid);let n=Math.round(performance.now()-s),r=Buffer.concat(c).toString();if(!l){t({label:a,code:e,output:r,ms:n,...u?{slow:!0}:{}});return}let i=r.endsWith(`
9
9
  `)?``:`
10
10
  `;t({label:a,code:124,hung:!0,output:`${r}${i}HUNG: ${a} was still running at ${A(o*3)}, 3 times its limit of ${A(o)}; its process tree was ended.`,ms:n})};h.stdout.on(`data`,e=>c.push(e)),h.stderr.on(`data`,e=>c.push(e)),h.on(`close`,e=>g(e??1)),f=setTimeout(()=>{u=!0,D(`SLOW: ${a} passed its limit of ${A(o)}; it keeps running and is ended as hung at ${A(o*3)}.`)},o),p=setTimeout(()=>{l=!0,h.pid!==void 0&&B(h.pid),m=setTimeout(()=>{h.stdout.destroy(),h.stderr.destroy(),g(124)},le)},o*3)})}var ue=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,de=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function fe(e,t){let n=await X(e,t);if(n.hung||n.code===0||!e.retryArgs||!ue.test(n.output)||de.test(n.output))return n;D(`\n──── RETRY ${e.label}: the vitest worker pool did not start in time (machine load, ${A(n.ms)}); running it once more with half the workers ────`);let r=await X({...e,args:e.retryArgs},t),i=n.slow||r.slow;return{...r,ms:n.ms+r.ms,output:`${n.output}\n──── retry ────\n${r.output}`,...i&&!r.hung?{slow:!0}:{}}}async function pe(e,t={}){if(e.length===0)return[];let{env:n={},heartbeatMs:r=6e4,maxParallel:i}=t;if(i!==void 0&&!(Number.isInteger(i)&&i>=1))throw Error(`runTasks: maxParallel must be a whole number of at least 1, not ${i}.`);for(let t of e)Y(t);let a=i??1/0,o=[],s=()=>a>0?(--a,Promise.resolve()):new Promise(e=>o.push(e)),c=()=>{let e=o.shift();e===void 0?a+=1:e()};D(`\n──── running in parallel${i!==void 0&&i<e.length?`, ${i} at a time`:``}: ${e.map(e=>e.label).join(` · `)} ────`);let l=performance.now(),u=/* @__PURE__ */ new Set,d=setInterval(()=>{let t=e.map(e=>e.label).filter(e=>!u.has(e));D(`still running after ${Math.round((performance.now()-l)/1e3)} s: ${t.join(`, `)}`)},r),f=/* @__PURE__ */ new Map,p;try{p=await Promise.all(e.map(e=>{let t=(async()=>{await null,e.after&&f.has(e.after)&&await f.get(e.after),await s(),D(`\n──── start ${e.label} (limit ${A(e.limitMs)}) ────`);let t;try{t=await fe(e,n)}finally{c()}return u.add(t.label),D(`\n──── ${t.hung?`${t.label} → HUNG (${A(t.ms)}, limit ${A(e.limitMs)})`:`${t.label} → ${t.code===0?`ok`:`FAIL`}${t.slow?`, SLOW`:``} (${A(t.ms)}${t.slow?`, limit ${A(e.limitMs)}`:``})`} ────`),process.stdout.write(t.output.endsWith(`
11
11
  `)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms,...t.hung?{hung:!0}:{},...t.slow?{slow:!0}:{}}})();return f.set(e.label,t),t}))}finally{clearInterval(d)}return D(`──── group wall time: ${A(Math.round(performance.now()-l))} ────`),p}function Z(e,n){let r=t(`git`,n,{cwd:e,encoding:`utf8`});return r.status===0?r.stdout.split(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/sandbox-gate",
3
- "version": "0.168.0",
3
+ "version": "0.169.1",
4
4
  "description": "The gate runner Webority repos share: sandbox boot on ports derived from the checkout, a buffered parallel task runner, headless Chrome ownership and orphan reaping, accessibility trees from Playwright, and changed-file helpers for a quick scope. Node only.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^24.0.0",
28
- "@webority/biome-config": "0.168.0",
28
+ "@webority/biome-config": "0.169.1",
29
29
  "typescript": "^7.0.2",
30
30
  "vite": "^8.3.6"
31
31
  },