@webority/sandbox-gate 0.148.0 → 0.149.0

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.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @webority/sandbox-gate
2
2
  The gate runner the Webority repos share: sandbox boot, a parallel task runner, gate Chrome ownership, accessibility trees and changed-file helpers.
3
3
  - `derivePorts(root, count)`: the port block a checkout owns.
4
- - `runTasks(tasks, options)`: runs tasks in parallel and buffers each one's output.
4
+ - `runTasks(tasks, options)`: runs tasks in parallel and buffers each one's output; `options.maxParallel` caps how many run at once.
5
5
  - `bootSandboxes(options)`: starts the sandboxes on the given ports.
6
6
  - `stopAll(options)`: stops the children, frees their ports and reaps gate Chrome.
7
7
  - `describeSandboxDeath(death)`: the one-line infrastructure-failure message for a sandbox that ended before the run did (from `bootSandboxes(...).deaths()`).
package/dist/index.d.ts CHANGED
@@ -24,6 +24,8 @@ export interface RunTasksOptions {
24
24
  env?: Record<string, string>;
25
25
  heartbeatMs?: number;
26
26
  quick?: boolean;
27
+ /** How many tasks run at once; the rest start in list order as slots free. Unset: all at once. */
28
+ maxParallel?: number;
27
29
  }
28
30
 
29
31
  export interface BootSandboxesOptions {
@@ -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}var M=[`react`,`razor`,`phoneWeb`];function N(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;for(let e of r){if(!M.includes(e))throw Error(`bootSandboxes: unknown sandbox "${e}"`);if(o[e]===void 0)throw Error(`bootSandboxes: no port for "${e}"`);if(l[e]===void 0)throw Error(`bootSandboxes: no origin for "${e}"`)}let _={react:[`corepack`,[`pnpm`,`--filter`,f,`dev`,`--port`,String(o.react),`--strictPort`]],razor:[`dotnet`,[`run`,`--project`,p,`--no-build`,`--`,`--urls`,l.razor]],phoneWeb:[`corepack`,[`pnpm`,`--dir`,m,`exec`,`vite`,`--port`,String(o.phoneWeb),`--strictPort`]]},v={};for(let e of r)v[e]=u(c(),`webority-gate-${h?`${e}-${h}`:e}-sandbox-${process.pid}.log`);let y=[];console.log(`\nStarting the sandboxes (${r.join(`, `)})... (output: ${r.map(e=>v[e]).join(`, `)})`);let b=r.map(t=>{let[n,r]=_[t],a=i(v[t],`w`),o=e(D(n,r),{stdio:[`ignore`,a,a],shell:!0,env:{...process.env,...g}});return o.on(`exit`,(e,n)=>{o.killed||y.push({name:t,code:e,signal:n,log:v[t]})}),o}),x=r.map(e=>d[e]??l[e]);async function S(){for(let e of x)if(!await A(e))return!1;return!0}return{children:b,logs:v,deaths:()=>[...y],async waitReady({attempts:e=600,intervalMs:t=300}={}){for(let n=0;n<e;n+=1){if(await S())return!0;await new Promise(e=>setTimeout(e,t))}return!1},finish(e){if(e===0)for(let e of Object.values(v))s(e,{force:!0});else for(let[e,t]of Object.entries(v)){if(!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&&console.log(`\n──── ${e} sandbox log, first error (${t}:${i+1}) ────\n${r.slice(i,i+3).join(`
7
7
  `)}`),console.log(`\n──── ${e} sandbox log, last 25 lines (${t}) ────\n${r.slice(-25).join(`
8
- `)}`)}}}}function P({ports:e=[],children:t=[]}={}){for(let e of t)e.kill();for(let t of e)j(t);return w()}function F({name:e,code:t,signal:n,log:r}){return`The ${e} sandbox ended before the run did (${n?`signal ${n}`:`exit ${t}`}): ${n===`SIGKILL`||t===137?`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: ${r}`}var I=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,L=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,R=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`;function z(e,t=2){if(!Number.isInteger(t)||t<1||t>8)throw RangeError(`derivePorts: count must be 1 to 8, got ${t}`);let n=2e4+d(`sha1`).update(e).digest().readUInt16BE(0)%1e3*8;return Array.from({length:t},(e,t)=>n+t)}function B({command:t,args:n,label:r},i={}){return new Promise(a=>{let o=performance.now(),s=[],c=e(D(t,n),{shell:!0,env:{...process.env,...i}});c.stdout.on(`data`,e=>s.push(e)),c.stderr.on(`data`,e=>s.push(e)),c.on(`close`,e=>a({label:r,code:e??1,output:Buffer.concat(s).toString(),ms:Math.round(performance.now()-o)}))})}var V=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,H=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function U(e,t){let n=await B(e,t);if(n.code===0||!e.retryArgs||!V.test(n.output)||H.test(n.output))return n;console.log(`\n──── RETRY ${e.label}: the vitest worker pool did not start in time (machine load, ${k(n.ms)}); running it once more with half the workers ────`);let r=await B({...e,args:e.retryArgs},t);return{...r,ms:n.ms+r.ms,output:`${n.output}\n──── retry ────\n${r.output}`}}async function W(e,t={}){if(e.length===0)return[];let{env:n={},heartbeatMs:r=6e4}=t;console.log(`\n──── running in parallel: ${e.map(e=>e.label).join(` · `)} ────`);let i=performance.now(),a=/* @__PURE__ */ new Set,o=setInterval(()=>{let t=e.map(e=>e.label).filter(e=>!a.has(e));console.log(`still running after ${Math.round((performance.now()-i)/1e3)} s: ${t.join(`, `)}`)},r),s=/* @__PURE__ */ new Map,c;try{c=await Promise.all(e.map(e=>{let t=(async()=>{await null,e.after&&s.has(e.after)&&await s.get(e.after),console.log(`\n──── start ${e.label} ────`);let t=await U(e,n);return a.add(t.label),console.log(`\n──── ${t.label} → ${t.code===0?`ok`:`FAIL`} (${k(t.ms)}) ────`),process.stdout.write(t.output.endsWith(`
9
- `)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms}})();return s.set(e.label,t),t}))}finally{clearInterval(o)}return console.log(`──── group wall time: ${k(Math.round(performance.now()-i))} ────`),c}function G(e,n){let r=t(`git`,n,{cwd:e,encoding:`utf8`});return r.status===0?r.stdout.split(`
8
+ `)}`)}}}}function P({ports:e=[],children:t=[]}={}){for(let e of t)e.kill();for(let t of e)j(t);return w()}function F({name:e,code:t,signal:n,log:r}){return`The ${e} sandbox ended before the run did (${n?`signal ${n}`:`exit ${t}`}): ${n===`SIGKILL`||t===137?`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: ${r}`}var I=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,L=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,R=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`;function z(e,t=2){if(!Number.isInteger(t)||t<1||t>8)throw RangeError(`derivePorts: count must be 1 to 8, got ${t}`);let n=2e4+d(`sha1`).update(e).digest().readUInt16BE(0)%1e3*8;return Array.from({length:t},(e,t)=>n+t)}function B({command:t,args:n,label:r},i={}){return new Promise(a=>{let o=performance.now(),s=[],c=e(D(t,n),{shell:!0,env:{...process.env,...i}});c.stdout.on(`data`,e=>s.push(e)),c.stderr.on(`data`,e=>s.push(e)),c.on(`close`,e=>a({label:r,code:e??1,output:Buffer.concat(s).toString(),ms:Math.round(performance.now()-o)}))})}var V=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,H=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function U(e,t){let n=await B(e,t);if(n.code===0||!e.retryArgs||!V.test(n.output)||H.test(n.output))return n;console.log(`\n──── RETRY ${e.label}: the vitest worker pool did not start in time (machine load, ${k(n.ms)}); running it once more with half the workers ────`);let r=await B({...e,args:e.retryArgs},t);return{...r,ms:n.ms+r.ms,output:`${n.output}\n──── retry ────\n${r.output}`}}async function W(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}.`);let a=i??1/0,o=[],s=()=>a>0?(--a,Promise.resolve()):new Promise(e=>o.push(e)),c=()=>{o.length>0?o.shift()():a+=1},l=i!==void 0&&i<e.length?`, ${i} at a time`:``;console.log(`\n──── running in parallel${l}: ${e.map(e=>e.label).join(` · `)} ────`);let u=performance.now(),d=/* @__PURE__ */ new Set,f=setInterval(()=>{let t=e.map(e=>e.label).filter(e=>!d.has(e));console.log(`still running after ${Math.round((performance.now()-u)/1e3)} s: ${t.join(`, `)}`)},r),p=/* @__PURE__ */ new Map,m;try{m=await Promise.all(e.map(e=>{let t=(async()=>{await null,e.after&&p.has(e.after)&&await p.get(e.after),await s(),console.log(`\n──── start ${e.label} ────`);let t;try{t=await U(e,n)}finally{c()}return d.add(t.label),console.log(`\n──── ${t.label} → ${t.code===0?`ok`:`FAIL`} (${k(t.ms)}) ────`),process.stdout.write(t.output.endsWith(`
9
+ `)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms}})();return p.set(e.label,t),t}))}finally{clearInterval(f)}return console.log(`──── group wall time: ${k(Math.round(performance.now()-u))} ────`),m}function G(e,n){let r=t(`git`,n,{cwd:e,encoding:`utf8`});return r.status===0?r.stdout.split(`
10
10
  `).filter(Boolean):null}function K(e,t=process.env.GATE_BASE||null){let n=t?G(e,[`diff`,`--name-only`,`--no-renames`,t,`HEAD`]):G(e,[`diff`,`--name-only`,`--no-renames`,`origin/development...HEAD`]);if(n===null)return null;let r=G(e,[`diff`,`--name-only`,`--no-renames`,`HEAD`])??[],i=G(e,[`ls-files`,`--others`,`--exclude-standard`])??[];return[.../* @__PURE__ */ new Set([...n,...r,...i])].sort()}function q(e,t){return t||G(e,[`merge-base`,`origin/development`,`HEAD`])?.[0]||null}function J(e,t){let n=G(e,[`show`,`${t}:version.json`]);if(n===null)return null;try{let e=JSON.parse(n.join(`
11
11
  `)).Version;return typeof e==`string`?e:null}catch{return null}}function Y(e,t,n){let r=q(e,n);if(!r)return!1;let i=J(e,r),a=J(e,`HEAD`);if(i===null||a===null||i===a)return!1;let o=G(e,[`status`,`--porcelain`,`--`,t]);if(o===null||o.length>0)return!1;let s=G(e,[`diff`,`-U0`,`--no-renames`,r,`HEAD`,`--`,t]);if(s===null)return!1;let c=[];for(let e of s)e.startsWith(`@@`)?c.push({removed:[],added:[]}):c.length&&e.startsWith(`-`)?c.at(-1).removed.push(e.slice(1)):c.length&&e.startsWith(`+`)&&c.at(-1).added.push(e.slice(1));return c.length!==0&&c.every(({removed:e,added:t})=>e.length===t.length&&e.every((e,n)=>e.split(i).join(a)===t[n]))}export{h as GATE_CHROME_MARKER,E as LIGHT_SCHEME_ARG,R as PHONE_WEB_ORIGIN,L as RAZOR_ORIGIN,I as REACT_ORIGIN,f as accessibilityTree,q as baseCommitOf,N as bootSandboxes,K as changedFiles,z as derivePorts,F as describeSandboxDeath,O as exitAfterOutput,_ as gateOwnerPid,G as gitLines,j as killPort,p as parseAriaSnapshot,y as playwrightGateArgs,v as profileDir,A as reachable,C as reapOrphanGateChrome,w as reapOwnGateChrome,B as runBuffered,W as runTasks,k as secs,D as shellLine,P as stopAll,Y as versionStampOnly};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/sandbox-gate",
3
- "version": "0.148.0",
3
+ "version": "0.149.0",
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",