@webority/sandbox-gate 0.165.0 → 0.168.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 +1 -1
- package/dist/boot.d.ts +9 -0
- package/dist/deaths.d.ts +3 -1
- package/dist/index.d.ts +2 -2
- package/dist/ports.d.ts +5 -0
- package/dist/process.d.ts +8 -0
- package/dist/runner.d.ts +10 -1
- package/dist/sandbox-gate.js +9 -7
- package/package.json +2 -2
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; `options.maxParallel` caps how many run at once.
|
|
4
|
+
- `runTasks(tasks, options)`: runs tasks in parallel and buffers each one's output; `options.maxParallel` caps how many run at once. 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`). A script that handles SIGINT or SIGTERM ends with `process.exit`, which is when the runner ends tasks still running.
|
|
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/boot.d.ts
CHANGED
|
@@ -25,6 +25,15 @@ export interface BootedSandboxes {
|
|
|
25
25
|
finish(code: number): void;
|
|
26
26
|
deaths(): SandboxDeath[];
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Whether a sandbox that exited on its own is booted again: once, and only when its log says its port was taken.
|
|
30
|
+
* A port is only reserved by its block, not by the system, which can lend it to any outgoing connection meanwhile.
|
|
31
|
+
*/
|
|
32
|
+
export declare function retriesBoot({ log, retriesLeft, killed }: {
|
|
33
|
+
log: string;
|
|
34
|
+
retriesLeft: number;
|
|
35
|
+
killed: boolean;
|
|
36
|
+
}): boolean;
|
|
28
37
|
export declare function bootSandboxes(options: BootSandboxesOptions): BootedSandboxes;
|
|
29
38
|
export declare function stopAll({ ports, children }?: {
|
|
30
39
|
ports?: number[];
|
package/dist/deaths.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { SandboxName } from "./boot.ts";
|
|
2
2
|
export interface SandboxDeath {
|
|
3
3
|
name: SandboxName;
|
|
4
|
+
port: number;
|
|
4
5
|
code: number | null;
|
|
5
6
|
signal: string | null;
|
|
6
7
|
log: string;
|
|
8
|
+
stoppedByGate: boolean;
|
|
7
9
|
}
|
|
8
|
-
export declare function describeSandboxDeath({ name, code, signal, log }: SandboxDeath): string;
|
|
10
|
+
export declare function describeSandboxDeath({ name, port, code, signal, log, stoppedByGate }: SandboxDeath): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export type { SandboxDeath } from "./deaths.ts";
|
|
|
7
7
|
export { describeSandboxDeath } from "./deaths.ts";
|
|
8
8
|
export { PHONE_WEB_ORIGIN, RAZOR_ORIGIN, REACT_ORIGIN } from "./origins.ts";
|
|
9
9
|
export { derivePorts } from "./ports.ts";
|
|
10
|
-
export { exitAfterOutput, killPort, reachable, secs, shellLine } from "./process.ts";
|
|
10
|
+
export { descendantsOf, endDescendants, endProcessTree, exitAfterOutput, killPort, reachable, secs, shellLine, } from "./process.ts";
|
|
11
11
|
export type { BufferedResult, GateTask, RunTasksOptions, TaskResult } from "./runner.ts";
|
|
12
|
-
export { runBuffered, runTasks } from "./runner.ts";
|
|
12
|
+
export { HUNG_EXIT_CODE, HUNG_LIMIT_MULTIPLIER, runBuffered, runTasks } from "./runner.ts";
|
|
13
13
|
export { baseCommitOf, changedFiles, gitLines, versionStampOnly } from "./scope.ts";
|
package/dist/ports.d.ts
CHANGED
package/dist/process.d.ts
CHANGED
|
@@ -4,3 +4,11 @@ export declare const secs: (ms: number) => string;
|
|
|
4
4
|
export declare function reachable(url: string): Promise<boolean>;
|
|
5
5
|
/** Kill the process listening on a port, and its descendants. */
|
|
6
6
|
export declare function killPort(port: number): boolean;
|
|
7
|
+
/** Whether killPort ended a listener on `port` at or after `sinceMs` (a performance.now() time). */
|
|
8
|
+
export declare function portKilledSince(port: number, sinceMs: number): boolean;
|
|
9
|
+
/** Every process below `root`, shallowest first. */
|
|
10
|
+
export declare function descendantsOf(parentOf: Map<number, number>, root: number): number[];
|
|
11
|
+
/** Kill every process below `root` (default: this one), deepest first, until none is left. @returns processes killed */
|
|
12
|
+
export declare function endDescendants(root?: number): number;
|
|
13
|
+
/** End `pid`, every process below it and, on Linux and macOS, every process left in the group `pid` leads. */
|
|
14
|
+
export declare function endProcessTree(pid: number): void;
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
+
/** The exit code of a task the runner ended as hung (the code timeout(1) uses). */
|
|
2
|
+
export declare const HUNG_EXIT_CODE = 124;
|
|
3
|
+
export declare const HUNG_LIMIT_MULTIPLIER = 3;
|
|
1
4
|
export interface GateTask {
|
|
2
5
|
command: string;
|
|
3
6
|
args: string[];
|
|
4
7
|
label: string;
|
|
5
8
|
retryArgs?: string[];
|
|
6
9
|
after?: string;
|
|
10
|
+
/** How long one attempt is expected to take at most, in ms. Past it the task is reported slow and keeps running; at HUNG_LIMIT_MULTIPLIER times it the runner ends its process tree as hung. */
|
|
11
|
+
limitMs: number;
|
|
7
12
|
}
|
|
8
13
|
export interface TaskResult {
|
|
9
14
|
label: string;
|
|
10
15
|
code: number;
|
|
11
16
|
ms: number;
|
|
17
|
+
/** Present when the runner ended the task as hung; `code` is then HUNG_EXIT_CODE. */
|
|
18
|
+
hung?: true;
|
|
19
|
+
/** Present when the task ran past its limit and finished on its own; its code is its own exit code. */
|
|
20
|
+
slow?: true;
|
|
12
21
|
}
|
|
13
22
|
export interface BufferedResult extends TaskResult {
|
|
14
23
|
output: string;
|
|
@@ -20,5 +29,5 @@ export interface RunTasksOptions {
|
|
|
20
29
|
/** How many tasks run at once; the rest start in list order as slots free. Unset: all at once. */
|
|
21
30
|
maxParallel?: number;
|
|
22
31
|
}
|
|
23
|
-
export declare function runBuffered(
|
|
32
|
+
export declare function runBuffered(task: GateTask, env?: Record<string, string>): Promise<BufferedResult>;
|
|
24
33
|
export declare function runTasks(tasks: GateTask[], options?: RunTasksOptions): Promise<TaskResult[]>;
|
package/dist/sandbox-gate.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
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
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=`webority-ui-gate-chrome`,g=RegExp(`${h}[=-](\\d+)`);function _(){let e=Number(process.env.WEBORITY_UI_GATE_PID);return Number.isFinite(e)&&e>0?e:process.pid}function v(){return r(l(c(),`${h}-${_()}-`))}function y(){return[`--${h}=${_()}`]}function b(e){try{return process.kill(e,0),!0}catch{return!1}}function x(){return process.platform===`win32`?(t(`powershell`,[`-NoProfile`,`-Command`,`Get-CimInstance Win32_Process -Filter "Name='chrome.exe'" | ForEach-Object { '{0} {1}' -f $_.ProcessId, $_.CommandLine }`],{encoding:`utf8`}).stdout||``).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):(t(`ps`,[`-A`,`-o`,`pid=,args=`],{encoding:`utf8`}).stdout||``).split(`
|
|
3
|
-
`).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 S(e){process.platform===`win32`?t(`taskkill`,[`/PID`,e,`/T`,`/F`],{stdio:`ignore`}):t(`kill`,[`-9`,e],{stdio:`ignore`})}function C(){let e=[];for(let{pid:t,commandLine:n}of x()){if(!n?.includes(`webority-ui-gate-chrome`))continue;let r=n.match(g);if(!r)continue;let i=Number(r[1]);!Number.isFinite(i)||i<=0||i!==process.pid&&(b(i)||e.push(t))}for(let t of e)S(t);return T(),e.length}function w(e=process.pid){let t=[];for(let{pid:n,commandLine:r}of x()){let i=r?.match(g);i&&Number(i[1])===e&&t.push(n)}for(let e of t)S(e);return t.length}function T(){let e=RegExp(`^${h}-(\\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||b(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 E=`--blink-settings=preferredColorScheme=1`;function D(e){process.stdout.write(`${e}\n`)}var O=(e,t=[])=>[e,...t].join(` `);async function k(e){await new Promise(e=>process.stdout.write(``,()=>e())),await new Promise(e=>process.stderr.write(``,()=>e())),process.exit(e)}var A=e=>`${(e/1e3).toFixed(1)}s`;async function j(e){try{return(await fetch(e)).ok}catch{return!1}}function
|
|
4
|
-
`).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 r)t(`taskkill`,[`/PID`,e,`/T`,`/F`],{stdio:`ignore`});return r.size>0}let n=(t(`lsof`,[`-ti`,`tcp:${e}`,`-sTCP:LISTEN`],{encoding:`utf8`}).stdout||``).split(`
|
|
5
|
-
`).filter(Boolean);for(let e of n)t(`kill`,[`-9`,e],{stdio:`ignore`});return n.length>0}var
|
|
3
|
+
`).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 S(e){process.platform===`win32`?t(`taskkill`,[`/PID`,e,`/T`,`/F`],{stdio:`ignore`}):t(`kill`,[`-9`,e],{stdio:`ignore`})}function C(){let e=[];for(let{pid:t,commandLine:n}of x()){if(!n?.includes(`webority-ui-gate-chrome`))continue;let r=n.match(g);if(!r)continue;let i=Number(r[1]);!Number.isFinite(i)||i<=0||i!==process.pid&&(b(i)||e.push(t))}for(let t of e)S(t);return T(),e.length}function w(e=process.pid){let t=[];for(let{pid:n,commandLine:r}of x()){let i=r?.match(g);i&&Number(i[1])===e&&t.push(n)}for(let e of t)S(e);return t.length}function T(){let e=RegExp(`^${h}-(\\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||b(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 E=`--blink-settings=preferredColorScheme=1`;function D(e){process.stdout.write(`${e}\n`)}var O=(e,t=[])=>[e,...t].join(` `);async function k(e){await new Promise(e=>process.stdout.write(``,()=>e())),await new Promise(e=>process.stderr.write(``,()=>e())),process.exit(e)}var A=e=>`${(e/1e3).toFixed(1)}s`;async function j(e){try{return(await fetch(e)).ok}catch{return!1}}var M=/* @__PURE__ */ new Map;function N(e){if(process.platform===`win32`){let n=t(`netstat`,[`-ano`],{encoding:`utf8`}).stdout||``,r=new Set(n.split(`
|
|
4
|
+
`).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 r)t(`taskkill`,[`/PID`,e,`/T`,`/F`],{stdio:`ignore`});return r.size>0&&M.set(e,performance.now()),r.size>0}let n=(t(`lsof`,[`-ti`,`tcp:${e}`,`-sTCP:LISTEN`],{encoding:`utf8`}).stdout||``).split(`
|
|
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
|
|
9
|
-
`)
|
|
10
|
-
`).
|
|
11
|
-
`)),t
|
|
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(`
|
|
9
|
+
`)?``:`
|
|
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
|
+
`)?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(`
|
|
12
|
+
`).filter(Boolean):null}function me(e,t=process.env.GATE_BASE||null){let n=t?Z(e,[`diff`,`--name-only`,`--no-renames`,t,`HEAD`]):Z(e,[`diff`,`--name-only`,`--no-renames`,`origin/development...HEAD`]);if(n===null)return null;let r=Z(e,[`diff`,`--name-only`,`--no-renames`,`HEAD`])??[],i=Z(e,[`ls-files`,`--others`,`--exclude-standard`])??[];return[.../* @__PURE__ */ new Set([...n,...r,...i])].sort()}function Q(e,t){return t||Z(e,[`merge-base`,`origin/development`,`HEAD`])?.[0]||null}function $(e,t){let n=Z(e,[`show`,`${t}:version.json`]);if(n===null)return null;try{let e=JSON.parse(n.join(`
|
|
13
|
+
`)),t=typeof e==`object`&&e&&`Version`in e?e.Version:void 0;return typeof t==`string`?t:null}catch{return null}}function he(e,t,n){let r=Q(e,n);if(!r)return!1;let i=$(e,r),a=$(e,`HEAD`);if(i===null||a===null||i===a)return!1;let o=Z(e,[`status`,`--porcelain`,`--`,t]);if(o===null||o.length>0)return!1;let s=Z(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{h as GATE_CHROME_MARKER,se as HUNG_EXIT_CODE,ce as HUNG_LIMIT_MULTIPLIER,E as LIGHT_SCHEME_ARG,H as PHONE_WEB_ORIGIN,V as RAZOR_ORIGIN,oe as REACT_ORIGIN,f as accessibilityTree,Q as baseCommitOf,re as bootSandboxes,me as changedFiles,K as derivePorts,I as descendantsOf,ae as describeSandboxDeath,L as endDescendants,B as endProcessTree,k as exitAfterOutput,_ as gateOwnerPid,Z as gitLines,N as killPort,p as parseAriaSnapshot,y as playwrightGateArgs,v as profileDir,j as reachable,C as reapOrphanGateChrome,w as reapOwnGateChrome,X as runBuffered,pe as runTasks,A as secs,O as shellLine,ie as stopAll,he as versionStampOnly};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/sandbox-gate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.168.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.
|
|
28
|
+
"@webority/biome-config": "0.168.0",
|
|
29
29
|
"typescript": "^7.0.2",
|
|
30
30
|
"vite": "^8.3.6"
|
|
31
31
|
},
|