@webority/sandbox-gate 0.174.1 → 0.175.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
@@ -4,6 +4,6 @@ The gate runner the Webority repos share: sandbox boot, a parallel task runner,
4
4
  - `runTasks(tasks, options)`: runs tasks in parallel and buffers each one's output; `options.maxParallel` caps how many run at once, and `options.write` receives the step headers and each task's output (standard output when unset). Every task states `limitMs`. Past it the task is reported SLOW: it keeps running, its result carries `slow`, and the gate result is unchanged. At 3 times the limit (`HUNG_LIMIT_MULTIPLIER`) the runner ends the task's process tree and returns it with `hung` and exit code 124 (`HUNG_EXIT_CODE`). Limits count time the gate ran, not wall time: while a task runs, a 5 s tick watches for gaps over 30 s (the machine slept or the process was stopped), moves every running limit by the gap, and reports it on the task's result as `pausedMs`; `pausedMs()` gives the gate's total. `stopRunning(reason)` ends every running task with exit code `STOPPED_EXIT_CODE` and returns their labels. A script that handles SIGINT or SIGTERM calls it, then ends with `process.exit`.
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. Every port is tried even when one fails; the failures are then thrown together as one `AggregateError`.
7
- - `describeSandboxDeath(death)`: the one-line infrastructure-failure message for a sandbox that ended before the run did (from `bootSandboxes(...).deaths()`).
7
+ - `describeSandboxDeath(death, readLog?)`: the message for a sandbox that ended before the run did (from `bootSandboxes(...).deaths()`), with the last lines of its log; `logEvidence(text)` picks those lines.
8
8
  - `accessibilityTree(page, options)`: the flat accessibility tree of an element.
9
9
  Node only; not for browsers.
package/dist/boot.d.ts CHANGED
@@ -41,6 +41,16 @@ export declare function retriesBoot({ log, retriesLeft, killed }: {
41
41
  retriesLeft: number;
42
42
  killed: boolean;
43
43
  }): boolean;
44
+ /**
45
+ * Polls until every target is reachable or a sandbox has died. A death ends the wait at once: a server that has exited
46
+ * never becomes reachable, so waiting out the attempts only delays the report of why the run failed.
47
+ */
48
+ export declare function pollReady({ attempts, intervalMs, reachable, died, }: {
49
+ attempts: number;
50
+ intervalMs: number;
51
+ reachable: () => Promise<boolean>;
52
+ died: () => boolean;
53
+ }): Promise<boolean>;
44
54
  export declare function bootSandboxes(options: BootSandboxesOptions): BootedSandboxes;
45
55
  export declare function stopAll({ ports, children }?: {
46
56
  ports?: number[];
package/dist/deaths.d.ts CHANGED
@@ -7,4 +7,6 @@ export interface SandboxDeath {
7
7
  log: string;
8
8
  stoppedByGate: boolean;
9
9
  }
10
- export declare function describeSandboxDeath({ name, port, code, signal, log, stoppedByGate }: SandboxDeath): string;
10
+ export declare function readLogTail(path: string): string | null;
11
+ export declare function logEvidence(text: string): string[];
12
+ export declare function describeSandboxDeath({ name, port, code, signal, log, stoppedByGate }: SandboxDeath, readLog?: (path: string) => string | null): string;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export type { BootedSandboxes, BootSandboxesOptions, SandboxName } from "./boot.
4
4
  export { bootSandboxes, stopAll } from "./boot.ts";
5
5
  export * from "./chrome.ts";
6
6
  export type { SandboxDeath } from "./deaths.ts";
7
- export { describeSandboxDeath } from "./deaths.ts";
7
+ export { describeSandboxDeath, logEvidence } from "./deaths.ts";
8
8
  export { PHONE_WEB_ORIGIN, RAZOR_ORIGIN, REACT_ORIGIN } from "./origins.ts";
9
9
  export { derivePorts } from "./ports.ts";
10
10
  export { descendantsOf, endDescendants, endProcessTree, exitAfterOutput, killPort, reachable, secs, shellLine, treeMemoryGiB, } from "./process.ts";
package/dist/process.d.ts CHANGED
@@ -4,8 +4,8 @@ export declare function exitAfterOutput(code: number): Promise<void>;
4
4
  export declare class GateCommandError extends Error {
5
5
  name: string;
6
6
  }
7
- /** Run a helper command hidden, to completion; throws GateCommandError when it cannot start or exits non-zero. */
8
- export declare function runChecked(command: string, args: string[], okStatuses?: number[]): string;
7
+ /** Run a helper command hidden, to completion; throws GateCommandError when it cannot start, outgrows maxBuffer or exits non-zero. */
8
+ export declare function runChecked(command: string, args: string[], okStatuses?: number[], maxBuffer?: number): string;
9
9
  /** Kill `pid` (and on Windows its tree); a kill that fails while the process is still alive throws. */
10
10
  export declare function killPidHard(pid: string): void;
11
11
  export declare const secs: (ms: number) => string;
@@ -1,16 +1,19 @@
1
- import{spawn as e,spawnSync as t}from"node:child_process";import{existsSync as n,mkdtempSync as r,openSync as i,readFileSync as a,readdirSync as o,rmSync as s}from"node:fs";import{tmpdir as c}from"node:os";import{join as l,resolve as u}from"node:path";import{createHash as d}from"node:crypto";async function f(e,t={}){return p(await e.locator(t.selector??`body`).ariaSnapshot())}function p(e){let t=[];for(let n of e.split(`
2
- `)){let e=n.trimStart();if(!e.startsWith(`- `))continue;let r=(n.length-e.length)/2,i=e.slice(2).trimEnd();if(i.startsWith(`/`))continue;i.endsWith(`:`)&&(i=i.slice(0,-1));let a=[];for(;i.endsWith(`]`);){let e=i.lastIndexOf(` [`);if(e===-1)break;a.unshift(i.slice(e+2,-1)),i=i.slice(0,e)}let o=i,s=``,c=i.indexOf(` `),l=i.indexOf(`:`);l!==-1&&(c===-1||l<c)?(o=i.slice(0,l),s=m(i.slice(l+1).trim())):c!==-1&&(o=i.slice(0,c),s=m(i.slice(c+1).trim())),t.push({depth:r,role:o,name:s,states:a})}return t}function m(e){return e.length>=2&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e}var h=(e,t=[])=>[e,...t].join(` `);async function g(e){await new Promise(e=>process.stdout.write(``,()=>e())),await new Promise(e=>process.stderr.write(``,()=>e())),process.exit(e)}var _=class extends Error{name=`GateCommandError`};function v(e,n,r=[0]){let i=t(e,n,{encoding:`utf8`,windowsHide:!0});if(i.error)throw new _(`${e} failed to start: ${i.error.message}`);if(i.status===null||!r.includes(i.status))throw new _(`${e} ${n.join(` `)} failed (exit ${i.status??i.signal}): ${i.stderr.trim()}`);return i.stdout}function y(e){try{return process.kill(Number(e),0),!0}catch(e){let t=e instanceof Error&&`code`in e?e.code:void 0;if(t===`ESRCH`)return!1;if(t===`EPERM`)return!0;throw e}}function b(e){let[n,r]=process.platform===`win32`?[`taskkill`,[`/PID`,e,`/T`,`/F`]]:[`kill`,[`-9`,e]],i=t(n,r,{encoding:`utf8`,windowsHide:!0});if(i.error)throw new _(`${n} failed to start: ${i.error.message}`);if(i.status!==0&&y(e))throw new _(`${n} ${r.join(` `)} failed (exit ${i.status}): ${i.stderr.trim()}`)}var x=e=>`${(e/1e3).toFixed(1)}s`;async function S(e){try{return(await fetch(e)).ok}catch{return!1}}var C=/* @__PURE__ */ new Map;function w(e){if(process.platform===`win32`){let t=v(`netstat`,[`-ano`]),n=new Set(t.split(`
3
- `).filter(e=>e.includes(`LISTENING`)).filter(t=>t.trim().split(/\s+/)[1]?.endsWith(`:${e}`)).map(e=>e.trim().split(/\s+/).pop()).filter(e=>!!e&&e!==`0`));for(let e of n)b(e);return n.size>0&&C.set(e,performance.now()),n.size>0}let t=v(`lsof`,[`-ti`,`tcp:${e}`,`-sTCP:LISTEN`],[0,1]).split(`
4
- `).filter(Boolean);for(let e of t)b(e);return t.length>0&&C.set(e,performance.now()),t.length>0}function T(e,t){let n=C.get(e);return n!==void 0&&n>=t}function E(){let e=process.platform===`win32`?v(`powershell`,[`-NoProfile`,`-Command`,`Get-CimInstance Win32_Process | ForEach-Object { '{0} {1}' -f $_.ProcessId, $_.ParentProcessId }`]):v(`ps`,[`-A`,`-o`,`pid=,ppid=`]),t=/* @__PURE__ */ new Map;for(let n of e.split(/\r?\n/)){let e=n.trim().match(/^(\d+)\s+(\d+)$/);e&&t.set(Number(e[1]),Number(e[2]))}return t}function D(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}var O=2**30;function k(e){return typeof e==`object`&&!!e&&`ProcessId`in e&&typeof e.ProcessId==`number`&&`ParentProcessId`in e&&typeof e.ParentProcessId==`number`&&`WorkingSetSize`in e&&typeof e.WorkingSetSize==`number`}function A(){let e=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;if(process.platform===`win32`){let r=t(`powershell`,[`-NoProfile`,`-NonInteractive`,`-Command`,`Get-CimInstance Win32_Process | Select ProcessId,ParentProcessId,WorkingSetSize | ConvertTo-Json -Compress`],{encoding:`utf8`,windowsHide:!0});if(r.status!==0)throw new _(`powershell failed (exit ${r.status}): ${r.error?.message??r.stderr}`);let i=JSON.parse(r.stdout),a=Array.isArray(i)?i:[i];for(let t of a){if(!k(t))throw Error(`powershell returned a process row of an unknown shape: ${JSON.stringify(t)}`);e.set(t.ProcessId,t.ParentProcessId),n.set(t.ProcessId,t.WorkingSetSize)}return{parentOf:e,bytesOf:n}}let r=t(`ps`,[`-A`,`-o`,`pid=,ppid=,rss=`],{encoding:`utf8`,windowsHide:!0});if(r.status!==0)throw new _(`ps failed (exit ${r.status}): ${r.error?.message??r.stderr}`);for(let t of r.stdout.split(/\r?\n/)){if(t.trim()===``)continue;let r=t.trim().match(/^(\d+)\s+(\d+)\s+(\d+)$/);if(!r)throw Error(`ps returned a line of an unknown shape: ${t}`);e.set(Number(r[1]),Number(r[2])),n.set(Number(r[1]),Number(r[3])*1024)}return{parentOf:e,bytesOf:n}}var j=250,M;function N(e){let t=performance.now();(M===void 0||t-M.atMs>j)&&(M={atMs:t,table:A()});let{parentOf:n,bytesOf:r}=M.table;if(!r.has(e))return null;let i=0;for(let t of[e,...D(n,e)])i+=r.get(t)??0;return i/O}function P(e=process.pid){let t=0;for(let n=0;n<3;n+=1){let n=D(E(),e);if(n.length===0)return t;for(let e of n.reverse())try{process.kill(e,`SIGKILL`),t+=1}catch(e){if(F(e)!==`ESRCH`)throw e}}return t}function F(e){return e instanceof Error&&`code`in e?e.code:void 0}function I(e){try{process.kill(e,`SIGKILL`)}catch(t){let n=F(t);if(n===`ESRCH`||n===`EPERM`&&e<0)return;throw t}}function L(e){P(e),I(e),process.platform!==`win32`&&I(-e)}var R=`webority-ui-gate-chrome`,z=RegExp(`${R}[=-](\\d+)`);function B(){let e=Number(process.env.WEBORITY_UI_GATE_PID);return Number.isFinite(e)&&e>0?e:process.pid}function ee(){return r(l(c(),`${R}-${B()}-`))}function te(){return[`--${R}=${B()}`]}function V(e){try{return process.kill(e,0),!0}catch{return!1}}function H(){return process.platform===`win32`?v(`powershell`,[`-NoProfile`,`-Command`,`Get-CimInstance Win32_Process -Filter "Name='chrome.exe'" | ForEach-Object { '{0} {1}' -f $_.ProcessId, $_.CommandLine }`]).split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.indexOf(` `);return t<0?null:{pid:e.slice(0,t).trim(),commandLine:e.slice(t+1)}}).filter(e=>e!==null):v(`ps`,[`-A`,`-o`,`pid=,args=`]).split(`
5
- `).map(e=>e.trim()).filter(e=>/(?:^|[/\s])(chrome|chromium)(?:\s|$|\.exe)/i.test(e)).map(e=>{let t=e.match(/^(\d+)\s+(.*)$/);if(!t)return null;let[,n,r]=t;return n===void 0||r===void 0?null:{pid:n,commandLine:r}}).filter(e=>e!==null)}function ne(){let e=[];for(let{pid:t,commandLine:n}of H()){if(!n?.includes(`webority-ui-gate-chrome`))continue;let r=n.match(z);if(!r)continue;let i=Number(r[1]);!Number.isFinite(i)||i<=0||i!==process.pid&&(V(i)||e.push(t))}for(let t of e)b(t);return re(),e.length}function U(e=process.pid){let t=[];for(let{pid:n,commandLine:r}of H()){let i=r?.match(z);i&&Number(i[1])===e&&t.push(n)}for(let e of t)b(e);return t.length}function re(){let e=RegExp(`^${R}-(\\d+)-`),t;try{t=o(c())}catch{return}for(let n of t){let t=n.match(e);if(!t)continue;let r=Number(t[1]);if(!(r===process.pid||V(r)))try{s(l(c(),n),{recursive:!0,force:!0})}catch(e){if((e instanceof Error&&`code`in e?e.code:void 0)!==`ENOENT`)throw e}}}var ie=`--blink-settings=preferredColorScheme=1`;function W(e){process.stdout.write(`${e}\n`)}var ae=[`react`,`razor`,`phoneWeb`];function oe({razorProject:e,origin:t,configuration:n=`Debug`}){return[`run`,`--project`,e,`--no-build`,`-c`,n,`--`,`--urls`,t]}var se=/Port \d+ is already in use|address already in use|EADDRINUSE/i;function ce({log:e,retriesLeft:t,killed:n}){return!n&&t>0&&se.test(e)}function le(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:g,env:_={},configuration:v=`Debug`}=t,y=e=>{let t=o[e];if(t===void 0)throw Error(`bootSandboxes: no port for "${e}"`);return t},b=e=>{let t=l[e];if(t===void 0)throw Error(`bootSandboxes: no origin for "${e}"`);return t};for(let e of r){if(!ae.includes(e))throw Error(`bootSandboxes: unknown sandbox "${e}"`);y(e),b(e)}let x=e=>{switch(e){case`react`:return[`corepack`,[`pnpm`,`--filter`,f,`dev`,`--port`,String(y(`react`)),`--strictPort`]];case`razor`:return[`dotnet`,oe({razorProject:p,origin:b(`razor`),configuration:v})];case`phoneWeb`:return[`corepack`,[`pnpm`,`--dir`,m,`exec`,`vite`,`--port`,String(y(`phoneWeb`)),`--strictPort`]]}},C=e=>u(c(),`webority-gate-${g?`${e}-${g}`:e}-sandbox-${process.pid}.log`),E={};for(let e of r)E[e]=C(e);let D=[];W(`\nStarting the sandboxes (${r.join(`, `)})... (output: ${r.map(e=>C(e)).join(`, `)})`);let O=[],k=(t,r,o)=>{let[s,c]=x(t),l=C(t);w(y(t));let u=i(l,`w`),d=e(h(s,c),{stdio:[`ignore`,u,u],shell:!0,windowsHide:!0,env:{...process.env,..._,WEBORITY_GATE_SANDBOX:`1`}}),f=performance.now();return d.on(`exit`,(e,i)=>{ce({log:n(l)?a(l,`utf8`):``,retriesLeft:o,killed:d.killed})?(W(`\nThe ${t} sandbox's port ${y(t)} was taken; freeing it and starting the sandbox once more.`),O[r]=k(t,r,o-1)):d.killed||D.push({name:t,port:y(t),code:e,signal:i,log:l,stoppedByGate:T(y(t),f)})}),d};r.forEach((e,t)=>{O[t]=k(e,t,1)});let A=r.map(e=>d[e]??b(e));async function j(){for(let e of A)if(!await S(e))return!1;return!0}return{children:O,logs:E,deaths:()=>[...D],async waitReady({attempts:e=600,intervalMs:t=300}={}){for(let n=0;n<e;n+=1){if(await j())return!0;await new Promise(e=>setTimeout(e,t))}return!1},finish(e){if(e===0)for(let e of Object.values(E))e!==void 0&&s(e,{force:!0});else for(let[e,t]of Object.entries(E)){if(t===void 0||!n(t))continue;let r=a(t,`utf8`).trimEnd().split(`
6
- `),i=r.findIndex(e=>/Exception: |^\s*Error: /.test(e));i!==-1&&i<r.length-25&&W(`\n──── ${e} sandbox log, first error (${t}:${i+1}) ────\n${r.slice(i,i+3).join(`
7
- `)}`),W(`\n──── ${e} sandbox log, last 25 lines (${t}) ────\n${r.slice(-25).join(`
8
- `)}`)}}}}function ue({ports:e=[],children:t=[]}={}){let n=[];for(let e of t)e.kill();for(let t of e)try{w(t)}catch(e){n.push(Error(`could not free port ${t}`,{cause:e}))}let r=U();if(n.length>0)throw AggregateError(n,`stopAll: ${n.length} port(s) could not be freed`);return r}function de({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 fe=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,pe=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,me=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`,he={first:7e3,end:1e4},ge=[7e3,7474,7687,8e3,8008,8080,8081,8443,8888,9e3,9090,9092,9200,9229,9300],G=12;function _e(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}=he,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(!ge.some(e=>e>=r&&e<r+G))return Array.from({length:t},(e,t)=>r+t)}throw Error(`derivePorts: no free port slot`)}var ve=124,ye=143,be=3,xe=5e3,Se=3e4,Ce=5e3,K={now:()=>performance.now(),every:(e,t)=>{let n=setInterval(t,e);return n.unref(),()=>clearInterval(n)},after:(e,t)=>{let n=setTimeout(t,e);return n.unref(),()=>clearTimeout(n)}},we=e=>{process.stdout.write(e)},q=/* @__PURE__ */ new Set,Te=!1,J=0,Y=0,X,Z;function Ee(){return Math.round(J)}function De(e,t){if(Z!==void 0&&X!==t)throw Error(`runBuffered: a task started on another clock while tasks on the first are open; one clock drives the gate at a time.`);Z===void 0&&(X=t,Y=t.now(),Z=t.every(e.sampleMs,()=>ke(e)))}function Oe(){Z!==void 0&&(Z(),Z=void 0,X=void 0)}function ke(e){let t=X?.now();if(t===void 0)return;let n=t-Y;if(Y=t,n>e.gapMs){let t=n-e.sampleMs;J+=t,W(`PAUSED: the gate did not run for ${Math.round(t/1e3)} s; every limit moved by that much`)}for(let e of q)e.check(t)}function Ae(e){return e instanceof Error&&`code`in e&&(e.code===`ESRCH`||e.code===`EPERM`)}function je(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 Me(e){let t=[...q];for(let n of t)n.stop(e);return t.map(e=>e.label)}function Q(t,n={},r,i={sampleMs:xe,gapMs:Se},a=K){je(t);let{command:o,args:s,label:c,limitMs:l}=t;return new Promise(t=>{let u=a.now(),d=J,f=[],p=!1,m=!1,g=!1,_=!1,v,y,b,S,C=e(h(o,s),{shell:!0,env:{...process.env,...n},detached:process.platform!==`win32`,windowsHide:!0});C.pid!==void 0&&!Te&&(Te=!0,process.on(`exit`,()=>{if(process.platform!==`win32`){for(let e of q)if(e.pid!==void 0)try{process.kill(-e.pid,`SIGKILL`)}catch(e){if(!Ae(e))throw e}}}));let w=e=>e-u-(J-d),T=e=>{if(_)return;_=!0,b?.(),S?.(),q.delete(E),q.size===0&&Oe();let n=Math.round(a.now()-u),r=Buffer.concat(f).toString(),i=[];y!==void 0&&i.push(`MEMORY SAMPLE FAILED: ${y}`),p&&i.push(`HUNG: ${c} was still running at ${x(l*3)}, 3 times its limit of ${x(l)}; its process tree was ended.`);let o=i.length===0?r:`${r}${r.endsWith(`
1
+ import{spawn as e,spawnSync as t}from"node:child_process";import{closeSync as n,existsSync as r,fstatSync as i,mkdtempSync as a,openSync as o,readFileSync as s,readSync as c,readdirSync as l,rmSync as u}from"node:fs";import{tmpdir as d}from"node:os";import{join as f,resolve as p}from"node:path";import{createHash as m}from"node:crypto";async function h(e,t={}){return g(await e.locator(t.selector??`body`).ariaSnapshot())}function g(e){let t=[];for(let n of e.split(`
2
+ `)){let e=n.trimStart();if(!e.startsWith(`- `))continue;let r=(n.length-e.length)/2,i=e.slice(2).trimEnd();if(i.startsWith(`/`))continue;i.endsWith(`:`)&&(i=i.slice(0,-1));let a=[];for(;i.endsWith(`]`);){let e=i.lastIndexOf(` [`);if(e===-1)break;a.unshift(i.slice(e+2,-1)),i=i.slice(0,e)}let o=i,s=``,c=i.indexOf(` `),l=i.indexOf(`:`);l!==-1&&(c===-1||l<c)?(o=i.slice(0,l),s=_(i.slice(l+1).trim())):c!==-1&&(o=i.slice(0,c),s=_(i.slice(c+1).trim())),t.push({depth:r,role:o,name:s,states:a})}return t}function _(e){return e.length>=2&&e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e}var v=(e,t=[])=>[e,...t].join(` `);async function y(e){await new Promise(e=>process.stdout.write(``,()=>e())),await new Promise(e=>process.stderr.write(``,()=>e())),process.exit(e)}var b=class extends Error{name=`GateCommandError`};function x(e,n,r=[0],i=1048576){let a=t(e,n,{encoding:`utf8`,windowsHide:!0,maxBuffer:i});if(a.error)throw new b(`${e} failed to start: ${a.error.message}`);if(a.status===null||!r.includes(a.status))throw new b(`${e} ${n.join(` `)} failed (exit ${a.status??a.signal}): ${a.stderr.trim()}`);return a.stdout}function S(e){try{return process.kill(Number(e),0),!0}catch(e){let t=e instanceof Error&&`code`in e?e.code:void 0;if(t===`ESRCH`)return!1;if(t===`EPERM`)return!0;throw e}}function C(e){let[n,r]=process.platform===`win32`?[`taskkill`,[`/PID`,e,`/T`,`/F`]]:[`kill`,[`-9`,e]],i=t(n,r,{encoding:`utf8`,windowsHide:!0});if(i.error)throw new b(`${n} failed to start: ${i.error.message}`);if(i.status!==0&&S(e))throw new b(`${n} ${r.join(` `)} failed (exit ${i.status}): ${i.stderr.trim()}`)}var w=e=>`${(e/1e3).toFixed(1)}s`;async function T(e){try{return(await fetch(e)).ok}catch{return!1}}var E=/* @__PURE__ */ new Map;function D(e){if(process.platform===`win32`){let t=x(`netstat`,[`-ano`]),n=new Set(t.split(`
3
+ `).filter(e=>e.includes(`LISTENING`)).filter(t=>t.trim().split(/\s+/)[1]?.endsWith(`:${e}`)).map(e=>e.trim().split(/\s+/).pop()).filter(e=>!!e&&e!==`0`));for(let e of n)C(e);return n.size>0&&E.set(e,performance.now()),n.size>0}let t=x(`lsof`,[`-ti`,`tcp:${e}`,`-sTCP:LISTEN`],[0,1]).split(`
4
+ `).filter(Boolean);for(let e of t)C(e);return t.length>0&&E.set(e,performance.now()),t.length>0}function ee(e,t){let n=E.get(e);return n!==void 0&&n>=t}function O(){let e=process.platform===`win32`?x(`powershell`,[`-NoProfile`,`-Command`,`Get-CimInstance Win32_Process | ForEach-Object { '{0} {1}' -f $_.ProcessId, $_.ParentProcessId }`]):x(`ps`,[`-A`,`-o`,`pid=,ppid=`]),t=/* @__PURE__ */ new Map;for(let n of e.split(/\r?\n/)){let e=n.trim().match(/^(\d+)\s+(\d+)$/);e&&t.set(Number(e[1]),Number(e[2]))}return t}function k(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}var A=2**30;function te(e){return typeof e==`object`&&!!e&&`ProcessId`in e&&typeof e.ProcessId==`number`&&`ParentProcessId`in e&&typeof e.ParentProcessId==`number`&&`WorkingSetSize`in e&&typeof e.WorkingSetSize==`number`}function ne(){let e=/* @__PURE__ */ new Map,n=/* @__PURE__ */ new Map;if(process.platform===`win32`){let r=t(`powershell`,[`-NoProfile`,`-NonInteractive`,`-Command`,`Get-CimInstance Win32_Process | Select ProcessId,ParentProcessId,WorkingSetSize | ConvertTo-Json -Compress`],{encoding:`utf8`,windowsHide:!0});if(r.status!==0)throw new b(`powershell failed (exit ${r.status}): ${r.error?.message??r.stderr}`);let i=JSON.parse(r.stdout),a=Array.isArray(i)?i:[i];for(let t of a){if(!te(t))throw Error(`powershell returned a process row of an unknown shape: ${JSON.stringify(t)}`);e.set(t.ProcessId,t.ParentProcessId),n.set(t.ProcessId,t.WorkingSetSize)}return{parentOf:e,bytesOf:n}}let r=t(`ps`,[`-A`,`-o`,`pid=,ppid=,rss=`],{encoding:`utf8`,windowsHide:!0});if(r.status!==0)throw new b(`ps failed (exit ${r.status}): ${r.error?.message??r.stderr}`);for(let t of r.stdout.split(/\r?\n/)){if(t.trim()===``)continue;let r=t.trim().match(/^(\d+)\s+(\d+)\s+(\d+)$/);if(!r)throw Error(`ps returned a line of an unknown shape: ${t}`);e.set(Number(r[1]),Number(r[2])),n.set(Number(r[1]),Number(r[3])*1024)}return{parentOf:e,bytesOf:n}}var re=250,j;function ie(e){let t=performance.now();(j===void 0||t-j.atMs>re)&&(j={atMs:t,table:ne()});let{parentOf:n,bytesOf:r}=j.table;if(!r.has(e))return null;let i=0;for(let t of[e,...k(n,e)])i+=r.get(t)??0;return i/A}function ae(e=process.pid){let t=0;for(let n=0;n<3;n+=1){let n=k(O(),e);if(n.length===0)return t;for(let e of n.reverse())try{process.kill(e,`SIGKILL`),t+=1}catch(e){if(oe(e)!==`ESRCH`)throw e}}return t}function oe(e){return e instanceof Error&&`code`in e?e.code:void 0}function se(e){try{process.kill(e,`SIGKILL`)}catch(t){let n=oe(t);if(n===`ESRCH`||n===`EPERM`&&e<0)return;throw t}}function M(e){ae(e),se(e),process.platform!==`win32`&&se(-e)}var N=`webority-ui-gate-chrome`,P=RegExp(`${N}[=-](\\d+)`);function F(){let e=Number(process.env.WEBORITY_UI_GATE_PID);return Number.isFinite(e)&&e>0?e:process.pid}function ce(){return a(f(d(),`${N}-${F()}-`))}function le(){return[`--${N}=${F()}`]}function I(e){try{return process.kill(e,0),!0}catch{return!1}}function L(){return process.platform===`win32`?x(`powershell`,[`-NoProfile`,`-Command`,`Get-CimInstance Win32_Process -Filter "Name='chrome.exe'" | ForEach-Object { '{0} {1}' -f $_.ProcessId, $_.CommandLine }`]).split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.indexOf(` `);return t<0?null:{pid:e.slice(0,t).trim(),commandLine:e.slice(t+1)}}).filter(e=>e!==null):x(`ps`,[`-A`,`-o`,`pid=,args=`],[0],67108864).split(`
5
+ `).map(e=>e.trim()).filter(e=>/(?:^|[/\s])(chrome|chromium)(?:\s|$|\.exe)/i.test(e)).map(e=>{let t=e.match(/^(\d+)\s+(.*)$/);if(!t)return null;let[,n,r]=t;return n===void 0||r===void 0?null:{pid:n,commandLine:r}}).filter(e=>e!==null)}function ue(){let e=[];for(let{pid:t,commandLine:n}of L()){if(!n?.includes(`webority-ui-gate-chrome`))continue;let r=n.match(P);if(!r)continue;let i=Number(r[1]);!Number.isFinite(i)||i<=0||i!==process.pid&&(I(i)||e.push(t))}for(let t of e)C(t);return de(),e.length}function R(e=process.pid){let t=[];for(let{pid:n,commandLine:r}of L()){let i=r?.match(P);i&&Number(i[1])===e&&t.push(n)}for(let e of t)C(e);return t.length}function de(){let e=RegExp(`^${N}-(\\d+)-`),t;try{t=l(d())}catch{return}for(let n of t){let t=n.match(e);if(!t)continue;let r=Number(t[1]);if(!(r===process.pid||I(r)))try{u(f(d(),n),{recursive:!0,force:!0})}catch(e){if((e instanceof Error&&`code`in e?e.code:void 0)!==`ENOENT`)throw e}}}var fe=`--blink-settings=preferredColorScheme=1`;function z(e){process.stdout.write(`${e}\n`)}var pe=[`react`,`razor`,`phoneWeb`];function me({razorProject:e,origin:t,configuration:n=`Debug`}){return[`run`,`--project`,e,`--no-build`,`-c`,n,`--`,`--urls`,t]}var he=/Port \d+ is already in use|address already in use|EADDRINUSE/i;function ge({log:e,retriesLeft:t,killed:n}){return!n&&t>0&&he.test(e)}async function _e({attempts:e,intervalMs:t,reachable:n,died:r}){for(let i=0;i<e;i+=1){if(r())return!1;let e=await n();if(r())return!1;if(e)return!0;await new Promise(e=>setTimeout(e,t))}return!1}function ve(t){let{which:n,ports:i,origins:a,readyUrls:c={},reactFilter:l=`@webority/react-sandbox`,razorProject:f=`samples/Razor.Sandbox`,phoneWebDir:m=`samples/mobile-sandbox-web`,tag:h,env:g={},configuration:_=`Debug`}=t,y=e=>{let t=i[e];if(t===void 0)throw Error(`bootSandboxes: no port for "${e}"`);return t},b=e=>{let t=a[e];if(t===void 0)throw Error(`bootSandboxes: no origin for "${e}"`);return t};for(let e of n){if(!pe.includes(e))throw Error(`bootSandboxes: unknown sandbox "${e}"`);y(e),b(e)}let x=e=>{switch(e){case`react`:return[`corepack`,[`pnpm`,`--filter`,l,`dev`,`--port`,String(y(`react`)),`--strictPort`]];case`razor`:return[`dotnet`,me({razorProject:f,origin:b(`razor`),configuration:_})];case`phoneWeb`:return[`corepack`,[`pnpm`,`--dir`,m,`exec`,`vite`,`--port`,String(y(`phoneWeb`)),`--strictPort`]]}},S=e=>p(d(),`webority-gate-${h?`${e}-${h}`:e}-sandbox-${process.pid}.log`),C={};for(let e of n)C[e]=S(e);let w=[];z(`\nStarting the sandboxes (${n.join(`, `)})... (output: ${n.map(e=>S(e)).join(`, `)})`);let E=[],O=(t,n,i)=>{let[a,c]=x(t),l=S(t);D(y(t));let u=o(l,`w`),d=e(v(a,c),{stdio:[`ignore`,u,u],shell:!0,windowsHide:!0,env:{...process.env,...g,WEBORITY_GATE_SANDBOX:`1`}}),f=performance.now();return d.on(`exit`,(e,a)=>{ge({log:r(l)?s(l,`utf8`):``,retriesLeft:i,killed:d.killed})?(z(`\nThe ${t} sandbox's port ${y(t)} was taken; freeing it and starting the sandbox once more.`),E[n]=O(t,n,i-1)):d.killed||w.push({name:t,port:y(t),code:e,signal:a,log:l,stoppedByGate:ee(y(t),f)})}),d};n.forEach((e,t)=>{E[t]=O(e,t,1)});let k=n.map(e=>c[e]??b(e));async function A(){for(let e of k)if(!await T(e))return!1;return!0}return{children:E,logs:C,deaths:()=>[...w],waitReady({attempts:e=600,intervalMs:t=300}={}){return _e({attempts:e,intervalMs:t,reachable:A,died:()=>w.length>0})},finish(e){if(e===0)for(let e of Object.values(C))e!==void 0&&u(e,{force:!0});else for(let[e,t]of Object.entries(C)){if(t===void 0||!r(t))continue;let n=s(t,`utf8`).trimEnd().split(`
6
+ `),i=n.findIndex(e=>/Exception: |^\s*Error: /.test(e));i!==-1&&i<n.length-25&&z(`\n──── ${e} sandbox log, first error (${t}:${i+1}) ────\n${n.slice(i,i+3).join(`
7
+ `)}`),z(`\n──── ${e} sandbox log, last 25 lines (${t}) ────\n${n.slice(-25).join(`
8
+ `)}`)}}}}function ye({ports:e=[],children:t=[]}={}){let n=[];for(let e of t)e.kill();for(let t of e)try{D(t)}catch(e){n.push(Error(`could not free port ${t}`,{cause:e}))}let r=R();if(n.length>0)throw AggregateError(n,`stopAll: ${n.length} port(s) could not be freed`);return r}var be=5,xe=65536,B=300,Se=/\b([\w.-]*(?:password|passwd|pwd|secret|token|apikey|api_key|accountkey|sharedaccesskey|sig|signature|credential)[\w.-]*)=("[^"]*"|'[^']*'|[^\s;,&]+)/gi;function Ce(e){if(!r(e))return null;let t=o(e,`r`);try{let e=i(t).size,n=Math.min(e,xe),r=Buffer.alloc(n);c(t,r,0,n,e-n);let a=r.toString(`utf8`);return n<e?a.slice(a.indexOf(`
9
+ `)+1):a}finally{n(t)}}var we=e=>{let t=e.replace(Se,`$1=[redacted]`);return t.length>B?`${t.slice(0,B)}...`:t};function V(e){let t=e.split(`
10
+ `).filter(e=>e.trim()!==``),n=t.slice(-5),r=t.findLastIndex(e=>/Exception: |^\s*Error: /.test(e)),i=t[r];return(i!==void 0&&r<t.length-be?[i,`...`,...n]:n).map(we)}function Te({name:e,port:t,code:n,signal:r,log:i,stoppedByGate:a},o=Ce){let s=r?`signal ${r}`:`exit ${n}`,c=r===`SIGKILL`||n===137,l=c&&a?`the gate itself ended it when it freed port ${t}, while the sandbox was still in use. This is an infrastructure failure, not a test failure: rerun the gate`:c?`the system killed it, usually for lack of memory. This is an infrastructure failure, not a test failure: rerun the gate`:`it stopped on its own, so a rerun fails the same way: its log below says why`,u=o(i),d=u===null?[]:V(u);return`The ${e} sandbox ended before the run did (${s}): ${l}. Log: ${i}\n${u===null?` (no log was written)`:d.length>0?d.map(e=>` ${e}`).join(`
11
+ `):` (the log is empty)`}`}var Ee=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,De=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,Oe=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`,ke={first:7e3,end:1e4},Ae=[7e3,7474,7687,8e3,8008,8080,8081,8443,8888,9e3,9090,9092,9200,9229,9300],H=12;function je(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}=ke,i=(r-n)/H,a=m(`sha1`).update(e).digest().readUInt16BE(0)%i;for(let e=0;e<i;e++){let r=n+(a+e)%i*H;if(!Ae.some(e=>e>=r&&e<r+H))return Array.from({length:t},(e,t)=>r+t)}throw Error(`derivePorts: no free port slot`)}var Me=124,Ne=143,Pe=3,U=5e3,W=3e4,G=5e3,K={now:()=>performance.now(),every:(e,t)=>{let n=setInterval(t,e);return n.unref(),()=>clearInterval(n)},after:(e,t)=>{let n=setTimeout(t,e);return n.unref(),()=>clearTimeout(n)}},Fe=e=>{process.stdout.write(e)},q=/* @__PURE__ */ new Set,Ie=!1,J=0,Y=0,X,Z;function Le(){return Math.round(J)}function Re(e,t){if(Z!==void 0&&X!==t)throw Error(`runBuffered: a task started on another clock while tasks on the first are open; one clock drives the gate at a time.`);Z===void 0&&(X=t,Y=t.now(),Z=t.every(e.sampleMs,()=>Be(e)))}function ze(){Z!==void 0&&(Z(),Z=void 0,X=void 0)}function Be(e){let t=X?.now();if(t===void 0)return;let n=t-Y;if(Y=t,n>e.gapMs){let t=n-e.sampleMs;J+=t,z(`PAUSED: the gate did not run for ${Math.round(t/1e3)} s; every limit moved by that much`)}for(let e of q)e.check(t)}function Ve(e){return e instanceof Error&&`code`in e&&(e.code===`ESRCH`||e.code===`EPERM`)}function He(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 Ue(e){let t=[...q];for(let n of t)n.stop(e);return t.map(e=>e.label)}function Q(t,n={},r,i={sampleMs:U,gapMs:W},a=K){He(t);let{command:o,args:s,label:c,limitMs:l}=t;return new Promise(t=>{let u=a.now(),d=J,f=[],p=!1,m=!1,h=!1,g=!1,_,y,b,x,S=e(v(o,s),{shell:!0,env:{...process.env,...n},detached:process.platform!==`win32`,windowsHide:!0});S.pid!==void 0&&!Ie&&(Ie=!0,process.on(`exit`,()=>{if(process.platform!==`win32`){for(let e of q)if(e.pid!==void 0)try{process.kill(-e.pid,`SIGKILL`)}catch(e){if(!Ve(e))throw e}}}));let C=e=>e-u-(J-d),T=e=>{if(g)return;g=!0,b?.(),x?.(),q.delete(E),q.size===0&&ze();let n=Math.round(a.now()-u),r=Buffer.concat(f).toString(),i=[];y!==void 0&&i.push(`MEMORY SAMPLE FAILED: ${y}`),p&&i.push(`HUNG: ${c} was still running at ${w(l*3)}, 3 times its limit of ${w(l)}; its process tree was ended.`);let o=i.length===0?r:`${r}${r.endsWith(`
9
12
  `)?``:`
10
13
  `}${i.join(`
11
- `)}`,s=v===void 0?{}:{peakMemoryGiB:v},h=Math.round(J-d),C=h>0?{pausedMs:h}:{};t(g?{label:c,code:143,stopped:!0,output:o,ms:n,...s,...C}:p?{label:c,code:124,hung:!0,output:o,ms:n,...s,...C}:{label:c,code:e,output:o,ms:n,...m?{slow:!0}:{},...s,...C})},E={label:c,pid:C.pid,check:e=>{let t=w(e);!m&&t>=l&&(m=!0,W(`SLOW: ${c} passed its limit of ${x(l)}; it keeps running and is ended as hung at ${x(l*3)}.`)),!p&&t>=l*3&&(p=!0,C.pid!==void 0&&L(C.pid),b=a.after(Ce,()=>{C.stdout.destroy(),C.stderr.destroy(),T(124)}))},stop:e=>{_||g||(g=!0,W(`STOPPED ${c} after ${Math.round(w(a.now())/1e3)} s (${e})`),W(Buffer.concat(f).toString().split(`
14
+ `)}`,s=_===void 0?{}:{peakMemoryGiB:_},v=Math.round(J-d),S=v>0?{pausedMs:v}:{};t(h?{label:c,code:143,stopped:!0,output:o,ms:n,...s,...S}:p?{label:c,code:124,hung:!0,output:o,ms:n,...s,...S}:{label:c,code:e,output:o,ms:n,...m?{slow:!0}:{},...s,...S})},E={label:c,pid:S.pid,check:e=>{let t=C(e);!m&&t>=l&&(m=!0,z(`SLOW: ${c} passed its limit of ${w(l)}; it keeps running and is ended as hung at ${w(l*3)}.`)),!p&&t>=l*3&&(p=!0,S.pid!==void 0&&M(S.pid),b=a.after(G,()=>{S.stdout.destroy(),S.stderr.destroy(),T(124)}))},stop:e=>{g||h||(h=!0,z(`STOPPED ${c} after ${Math.round(C(a.now())/1e3)} s (${e})`),z(Buffer.concat(f).toString().split(`
12
15
  `).slice(-40).join(`
13
- `)),C.pid!==void 0&&L(C.pid),b?.(),b=a.after(Ce,()=>{C.stdout.destroy(),C.stderr.destroy(),T(143)}))}};C.stdout.on(`data`,e=>f.push(e)),C.stderr.on(`data`,e=>f.push(e)),C.on(`close`,e=>T(e??1));let D=C.pid;r!==void 0&&D!==void 0&&(S=a.every(r.everyMs,()=>{try{let e=r.sample(D);e!==null&&(v===void 0||e>v)&&(v=e)}catch(e){y=e instanceof Error?e.message:String(e),S?.()}})),q.add(E),De(i,a)})}var Ne=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,Pe=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function Fe(e,t,n,r,i,a){let o=await Q(e,t,n,r,a);if(o.hung||o.stopped||o.code===0||!e.retryArgs||!Ne.test(o.output)||Pe.test(o.output))return o;let s=o.pausedMs===void 0?`machine load`:`after a pause of ${Math.round(o.pausedMs/1e3)} s`;i(`\n──── RETRY ${e.label}: the vitest worker pool did not start in time (${s}, ${x(o.ms)}); running it once more with half the workers ────\n`);let c=await Q({...e,args:e.retryArgs},t,n,r,a),l=o.slow||c.slow,u=[o.peakMemoryGiB,c.peakMemoryGiB].filter(e=>e!==void 0),d=(o.pausedMs??0)+(c.pausedMs??0);return{...c,ms:o.ms+c.ms,output:`${o.output}\n──── retry ────\n${c.output}`,...l&&!c.hung?{slow:!0}:{},...u.length>0?{peakMemoryGiB:Math.max(...u)}:{},...d>0?{pausedMs:d}:{}}}async function Ie(e,t={}){if(e.length===0)return[];let{env:n={},heartbeatMs:r=6e4,maxParallel:i,admit:a,sampleMemory:o=N,memorySampleMs:s=process.platform===`win32`?5e3:1e3,pauseSampleMs:c=xe,pauseGapMs:l=Se,write:u=we,clock:d=K}=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}.`);if(!(Number.isFinite(s)&&s>0))throw Error(`runTasks: memorySampleMs must be a positive number of milliseconds, not ${s}.`);if(!(Number.isFinite(c)&&c>0))throw Error(`runTasks: pauseSampleMs must be a positive number of milliseconds, not ${c}.`);if(!(Number.isFinite(l)&&l>0))throw Error(`runTasks: pauseGapMs must be a positive number of milliseconds, not ${l}.`);let f={sample:o,everyMs:s},p={sampleMs:c,gapMs:l};for(let t of e)je(t);let m=i??1/0,h=[],g=()=>m>0?(--m,Promise.resolve()):new Promise(e=>h.push(e)),_=()=>{let e=h.shift();e===void 0?m+=1:e()};u(`\n──── running in parallel${i!==void 0&&i<e.length?`, ${i} at a time`:``}: ${e.map(e=>e.label).join(` · `)} ────\n`);let v=d.now(),y=/* @__PURE__ */ new Set,b=0,S=d.every(r,()=>{let t=e.map(e=>e.label).filter(e=>!y.has(e));u(`still running after ${Math.round((d.now()-v)/1e3)} s: ${t.join(`, `)}\n`)}),C=/* @__PURE__ */ new Map,w;try{w=await Promise.all(e.map(e=>{let t=(async()=>{await null,e.after&&C.has(e.after)&&await C.get(e.after),await g(),await a?.(e,()=>b),u(`\n──── start ${e.label} (limit ${x(e.limitMs)}) ────\n`);let t;b+=1;try{t=await Fe(e,n,f,p,u,d)}finally{--b,_()}y.add(t.label);let r=t.peakMemoryGiB===void 0?``:`, peak ${t.peakMemoryGiB.toFixed(1)} GiB`,i=t.stopped?`${t.label} → STOPPED (${x(t.ms)}${r})`:t.hung?`${t.label} → HUNG (${x(t.ms)}${r}, limit ${x(e.limitMs)})`:`${t.label} → ${t.code===0?`ok`:`FAIL`}${t.slow?`, SLOW`:``} (${x(t.ms)}${r}${t.slow?`, limit ${x(e.limitMs)}`:``})`;return u(`\n──── ${i} ────\n`),u(t.output.endsWith(`
14
- `)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms,...t.hung?{hung:!0}:{},...t.slow?{slow:!0}:{},...t.stopped?{stopped:!0}:{},...t.peakMemoryGiB===void 0?{}:{peakMemoryGiB:t.peakMemoryGiB},...t.pausedMs===void 0?{}:{pausedMs:t.pausedMs}}})();return C.set(e.label,t),t}))}finally{S()}return u(`──── group wall time: ${x(Math.round(d.now()-v))} ────\n`),w}function $(e,n){let r=t(`git`,n,{cwd:e,encoding:`utf8`,windowsHide:!0});if(r.error)throw new _(`git failed to start: ${r.error.message}`);return r.status===0?r.stdout.split(`
15
- `).filter(Boolean):null}function Le(e,t=process.env.GATE_BASE||null){let n=t?$(e,[`diff`,`--name-only`,`--no-renames`,t,`HEAD`]):$(e,[`diff`,`--name-only`,`--no-renames`,`origin/development...HEAD`]);if(n===null)return null;let r=$(e,[`diff`,`--name-only`,`--no-renames`,`HEAD`])??[],i=$(e,[`ls-files`,`--others`,`--exclude-standard`])??[];return[.../* @__PURE__ */ new Set([...n,...r,...i])].sort()}function Re(e,t){return t||$(e,[`merge-base`,`origin/development`,`HEAD`])?.[0]||null}function ze(e,t){let n=$(e,[`show`,`${t}:version.json`]);if(n===null)return null;try{let e=JSON.parse(n.join(`
16
- `)),t=typeof e==`object`&&e&&`Version`in e?e.Version:void 0;return typeof t==`string`?t:null}catch{return null}}function Be(e,t,n){let r=Re(e,n);if(!r)return!1;let i=ze(e,r),a=ze(e,`HEAD`);if(i===null||a===null||i===a)return!1;let o=$(e,[`status`,`--porcelain`,`--`,t]);if(o===null||o.length>0)return!1;let s=$(e,[`diff`,`-U0`,`--no-renames`,r,`HEAD`,`--`,t]);if(s===null)return!1;let c=[];for(let e of s){let t=c.at(-1);e.startsWith(`@@`)?c.push({removed:[],added:[]}):t&&e.startsWith(`-`)?t.removed.push(e.slice(1)):t&&e.startsWith(`+`)&&t.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{R as GATE_CHROME_MARKER,ve as HUNG_EXIT_CODE,be as HUNG_LIMIT_MULTIPLIER,ie as LIGHT_SCHEME_ARG,me as PHONE_WEB_ORIGIN,pe as RAZOR_ORIGIN,fe as REACT_ORIGIN,ye as STOPPED_EXIT_CODE,f as accessibilityTree,Re as baseCommitOf,le as bootSandboxes,Le as changedFiles,_e as derivePorts,D as descendantsOf,de as describeSandboxDeath,P as endDescendants,L as endProcessTree,g as exitAfterOutput,B as gateOwnerPid,$ as gitLines,w as killPort,p as parseAriaSnapshot,Ee as pausedMs,te as playwrightGateArgs,ee as profileDir,S as reachable,ne as reapOrphanGateChrome,U as reapOwnGateChrome,Q as runBuffered,Ie as runTasks,x as secs,h as shellLine,ue as stopAll,Me as stopRunning,K as systemClock,N as treeMemoryGiB,Be as versionStampOnly};
16
+ `)),S.pid!==void 0&&M(S.pid),b?.(),b=a.after(G,()=>{S.stdout.destroy(),S.stderr.destroy(),T(143)}))}};S.stdout.on(`data`,e=>f.push(e)),S.stderr.on(`data`,e=>f.push(e)),S.on(`close`,e=>T(e??1));let D=S.pid;r!==void 0&&D!==void 0&&(x=a.every(r.everyMs,()=>{try{let e=r.sample(D);e!==null&&(_===void 0||e>_)&&(_=e)}catch(e){y=e instanceof Error?e.message:String(e),x?.()}})),q.add(E),Re(i,a)})}var We=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,Ge=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function Ke(e,t,n,r,i,a){let o=await Q(e,t,n,r,a);if(o.hung||o.stopped||o.code===0||!e.retryArgs||!We.test(o.output)||Ge.test(o.output))return o;let s=o.pausedMs===void 0?`machine load`:`after a pause of ${Math.round(o.pausedMs/1e3)} s`;i(`\n──── RETRY ${e.label}: the vitest worker pool did not start in time (${s}, ${w(o.ms)}); running it once more with half the workers ────\n`);let c=await Q({...e,args:e.retryArgs},t,n,r,a),l=o.slow||c.slow,u=[o.peakMemoryGiB,c.peakMemoryGiB].filter(e=>e!==void 0),d=(o.pausedMs??0)+(c.pausedMs??0);return{...c,ms:o.ms+c.ms,output:`${o.output}\n──── retry ────\n${c.output}`,...l&&!c.hung?{slow:!0}:{},...u.length>0?{peakMemoryGiB:Math.max(...u)}:{},...d>0?{pausedMs:d}:{}}}async function qe(e,t={}){if(e.length===0)return[];let{env:n={},heartbeatMs:r=6e4,maxParallel:i,admit:a,sampleMemory:o=ie,memorySampleMs:s=process.platform===`win32`?5e3:1e3,pauseSampleMs:c=U,pauseGapMs:l=W,write:u=Fe,clock:d=K}=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}.`);if(!(Number.isFinite(s)&&s>0))throw Error(`runTasks: memorySampleMs must be a positive number of milliseconds, not ${s}.`);if(!(Number.isFinite(c)&&c>0))throw Error(`runTasks: pauseSampleMs must be a positive number of milliseconds, not ${c}.`);if(!(Number.isFinite(l)&&l>0))throw Error(`runTasks: pauseGapMs must be a positive number of milliseconds, not ${l}.`);let f={sample:o,everyMs:s},p={sampleMs:c,gapMs:l};for(let t of e)He(t);let m=i??1/0,h=[],g=()=>m>0?(--m,Promise.resolve()):new Promise(e=>h.push(e)),_=()=>{let e=h.shift();e===void 0?m+=1:e()};u(`\n──── running in parallel${i!==void 0&&i<e.length?`, ${i} at a time`:``}: ${e.map(e=>e.label).join(` · `)} ────\n`);let v=d.now(),y=/* @__PURE__ */ new Set,b=0,x=d.every(r,()=>{let t=e.map(e=>e.label).filter(e=>!y.has(e));u(`still running after ${Math.round((d.now()-v)/1e3)} s: ${t.join(`, `)}\n`)}),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),await g(),await a?.(e,()=>b),u(`\n──── start ${e.label} (limit ${w(e.limitMs)}) ────\n`);let t;b+=1;try{t=await Ke(e,n,f,p,u,d)}finally{--b,_()}y.add(t.label);let r=t.peakMemoryGiB===void 0?``:`, peak ${t.peakMemoryGiB.toFixed(1)} GiB`,i=t.stopped?`${t.label} → STOPPED (${w(t.ms)}${r})`:t.hung?`${t.label} → HUNG (${w(t.ms)}${r}, limit ${w(e.limitMs)})`:`${t.label} → ${t.code===0?`ok`:`FAIL`}${t.slow?`, SLOW`:``} (${w(t.ms)}${r}${t.slow?`, limit ${w(e.limitMs)}`:``})`;return u(`\n──── ${i} ────\n`),u(t.output.endsWith(`
17
+ `)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms,...t.hung?{hung:!0}:{},...t.slow?{slow:!0}:{},...t.stopped?{stopped:!0}:{},...t.peakMemoryGiB===void 0?{}:{peakMemoryGiB:t.peakMemoryGiB},...t.pausedMs===void 0?{}:{pausedMs:t.pausedMs}}})();return S.set(e.label,t),t}))}finally{x()}return u(`──── group wall time: ${w(Math.round(d.now()-v))} ────\n`),C}function $(e,n){let r=t(`git`,n,{cwd:e,encoding:`utf8`,windowsHide:!0});if(r.error)throw new b(`git failed to start: ${r.error.message}`);return r.status===0?r.stdout.split(`
18
+ `).filter(Boolean):null}function Je(e,t=process.env.GATE_BASE||null){let n=t?$(e,[`diff`,`--name-only`,`--no-renames`,t,`HEAD`]):$(e,[`diff`,`--name-only`,`--no-renames`,`origin/development...HEAD`]);if(n===null)return null;let r=$(e,[`diff`,`--name-only`,`--no-renames`,`HEAD`])??[],i=$(e,[`ls-files`,`--others`,`--exclude-standard`])??[];return[.../* @__PURE__ */ new Set([...n,...r,...i])].sort()}function Ye(e,t){return t||$(e,[`merge-base`,`origin/development`,`HEAD`])?.[0]||null}function Xe(e,t){let n=$(e,[`show`,`${t}:version.json`]);if(n===null)return null;try{let e=JSON.parse(n.join(`
19
+ `)),t=typeof e==`object`&&e&&`Version`in e?e.Version:void 0;return typeof t==`string`?t:null}catch{return null}}function Ze(e,t,n){let r=Ye(e,n);if(!r)return!1;let i=Xe(e,r),a=Xe(e,`HEAD`);if(i===null||a===null||i===a)return!1;let o=$(e,[`status`,`--porcelain`,`--`,t]);if(o===null||o.length>0)return!1;let s=$(e,[`diff`,`-U0`,`--no-renames`,r,`HEAD`,`--`,t]);if(s===null)return!1;let c=[];for(let e of s){let t=c.at(-1);e.startsWith(`@@`)?c.push({removed:[],added:[]}):t&&e.startsWith(`-`)?t.removed.push(e.slice(1)):t&&e.startsWith(`+`)&&t.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{N as GATE_CHROME_MARKER,Me as HUNG_EXIT_CODE,Pe as HUNG_LIMIT_MULTIPLIER,fe as LIGHT_SCHEME_ARG,Oe as PHONE_WEB_ORIGIN,De as RAZOR_ORIGIN,Ee as REACT_ORIGIN,Ne as STOPPED_EXIT_CODE,h as accessibilityTree,Ye as baseCommitOf,ve as bootSandboxes,Je as changedFiles,je as derivePorts,k as descendantsOf,Te as describeSandboxDeath,ae as endDescendants,M as endProcessTree,y as exitAfterOutput,F as gateOwnerPid,$ as gitLines,D as killPort,V as logEvidence,g as parseAriaSnapshot,Le as pausedMs,le as playwrightGateArgs,ce as profileDir,T as reachable,ue as reapOrphanGateChrome,R as reapOwnGateChrome,Q as runBuffered,qe as runTasks,w as secs,v as shellLine,ye as stopAll,Ue as stopRunning,K as systemClock,ie as treeMemoryGiB,Ze as versionStampOnly};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/sandbox-gate",
3
- "version": "0.174.1",
3
+ "version": "0.175.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",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^24.0.0",
28
- "@webority/biome-config": "0.174.1",
28
+ "@webority/biome-config": "0.175.0",
29
29
  "typescript": "^7.0.2",
30
30
  "vite": "^8.3.6"
31
31
  },