@webority/sandbox-gate 0.171.3 → 0.172.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.
- package/README.md +2 -2
- package/dist/boot.d.ts +7 -0
- package/dist/index.d.ts +2 -2
- package/dist/runner.d.ts +35 -2
- package/dist/sandbox-gate.js +11 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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. 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`).
|
|
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
|
-
- `stopAll(options)`: stops the children, frees their ports and reaps gate Chrome.
|
|
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
7
|
- `describeSandboxDeath(death)`: the one-line infrastructure-failure message for a sandbox that ended before the run did (from `bootSandboxes(...).deaths()`).
|
|
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
|
@@ -14,6 +14,8 @@ export interface BootSandboxesOptions {
|
|
|
14
14
|
tag?: string;
|
|
15
15
|
/** Merged over process.env for both children. */
|
|
16
16
|
env?: Record<string, string>;
|
|
17
|
+
/** The dotnet configuration the Razor sandbox runs; it must match the configuration it was built in. */
|
|
18
|
+
configuration?: "Debug" | "Release";
|
|
17
19
|
}
|
|
18
20
|
export interface BootedSandboxes {
|
|
19
21
|
children: ChildProcess[];
|
|
@@ -25,6 +27,11 @@ export interface BootedSandboxes {
|
|
|
25
27
|
finish(code: number): void;
|
|
26
28
|
deaths(): SandboxDeath[];
|
|
27
29
|
}
|
|
30
|
+
export declare function razorRunArgs({ razorProject, origin, configuration, }: {
|
|
31
|
+
razorProject: string;
|
|
32
|
+
origin: string;
|
|
33
|
+
configuration?: "Debug" | "Release";
|
|
34
|
+
}): string[];
|
|
28
35
|
/**
|
|
29
36
|
* Whether a sandbox that exited on its own is booted again: once, and only when its log says its port was taken.
|
|
30
37
|
* A port is only reserved by its block, not by the system, which can lend it to any outgoing connection meanwhile.
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ 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
10
|
export { descendantsOf, endDescendants, endProcessTree, exitAfterOutput, killPort, reachable, secs, shellLine, treeMemoryGiB, } from "./process.ts";
|
|
11
|
-
export type { BufferedResult, GateTask, RunTasksOptions, TaskResult } from "./runner.ts";
|
|
12
|
-
export { HUNG_EXIT_CODE, HUNG_LIMIT_MULTIPLIER, runBuffered, runTasks } from "./runner.ts";
|
|
11
|
+
export type { BufferedResult, GateClock, GateTask, RunTasksOptions, TaskResult } from "./runner.ts";
|
|
12
|
+
export { HUNG_EXIT_CODE, HUNG_LIMIT_MULTIPLIER, pausedMs, runBuffered, runTasks, STOPPED_EXIT_CODE, stopRunning, systemClock, } from "./runner.ts";
|
|
13
13
|
export { baseCommitOf, changedFiles, gitLines, versionStampOnly } from "./scope.ts";
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** The exit code of a task the runner ended as hung (the code timeout(1) uses). */
|
|
2
2
|
export declare const HUNG_EXIT_CODE = 124;
|
|
3
|
+
/** The exit code of a task that was still running when the gate was stopped. */
|
|
4
|
+
export declare const STOPPED_EXIT_CODE = 143;
|
|
3
5
|
export declare const HUNG_LIMIT_MULTIPLIER = 3;
|
|
4
6
|
export interface GateTask {
|
|
5
7
|
command: string;
|
|
@@ -7,7 +9,7 @@ export interface GateTask {
|
|
|
7
9
|
label: string;
|
|
8
10
|
retryArgs?: string[];
|
|
9
11
|
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. */
|
|
12
|
+
/** How long one attempt is expected to take at most, in ms, not counting the gate's own pauses. 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
13
|
limitMs: number;
|
|
12
14
|
/** The memory in GiB one run of the task needs, for an admission hook (RunTasksOptions.admit). */
|
|
13
15
|
memoryGiB?: number;
|
|
@@ -22,6 +24,10 @@ export interface TaskResult {
|
|
|
22
24
|
slow?: true;
|
|
23
25
|
/** The peak resident memory of the task's process tree in GiB, sampled while it ran; absent when no sample was taken. */
|
|
24
26
|
peakMemoryGiB?: number;
|
|
27
|
+
/** How long the gate itself did not run while this task was open, in ms; limits are measured without it. */
|
|
28
|
+
pausedMs?: number;
|
|
29
|
+
/** Present when the gate was told to stop while the task ran; `code` is then STOPPED_EXIT_CODE. */
|
|
30
|
+
stopped?: true;
|
|
25
31
|
}
|
|
26
32
|
export interface BufferedResult extends TaskResult {
|
|
27
33
|
output: string;
|
|
@@ -31,6 +37,21 @@ export interface MemorySampling {
|
|
|
31
37
|
sample: (pid: number) => number | null;
|
|
32
38
|
everyMs: number;
|
|
33
39
|
}
|
|
40
|
+
/** How often the gate's tick runs, and the gap between two ticks that counts as a pause; both in ms. */
|
|
41
|
+
export interface PauseWatch {
|
|
42
|
+
sampleMs: number;
|
|
43
|
+
gapMs: number;
|
|
44
|
+
}
|
|
45
|
+
/** The runner's time source: every limit, pause, memory sample, grace wait and heartbeat reads it. */
|
|
46
|
+
export interface GateClock {
|
|
47
|
+
/** Milliseconds on a monotonic scale; only differences are read. */
|
|
48
|
+
now(): number;
|
|
49
|
+
/** Calls `fn` every `ms` until the returned function is called. */
|
|
50
|
+
every(ms: number, fn: () => void): () => void;
|
|
51
|
+
/** Calls `fn` once after `ms` unless the returned function is called first. */
|
|
52
|
+
after(ms: number, fn: () => void): () => void;
|
|
53
|
+
}
|
|
54
|
+
export declare const systemClock: GateClock;
|
|
34
55
|
export interface RunTasksOptions {
|
|
35
56
|
env?: Record<string, string>;
|
|
36
57
|
heartbeatMs?: number;
|
|
@@ -46,7 +67,19 @@ export interface RunTasksOptions {
|
|
|
46
67
|
sampleMemory?: (pid: number) => number | null;
|
|
47
68
|
/** How often each running task's memory is sampled, in ms. Unset: 1000 on macOS and Linux, 5000 on Windows. */
|
|
48
69
|
memorySampleMs?: number;
|
|
70
|
+
/** How often the gate's tick runs while a task is open, in ms. Unset: 5000. */
|
|
71
|
+
pauseSampleMs?: number;
|
|
72
|
+
/** A gap between two ticks over this many ms is a pause of the gate. Unset: 30000. */
|
|
73
|
+
pauseGapMs?: number;
|
|
74
|
+
/** The time source for limits, pauses, samples and the heartbeat. Unset: systemClock. A test passes a clock it advances by hand. */
|
|
75
|
+
clock?: GateClock;
|
|
76
|
+
/** Receives the runner's step headers and each task's buffered output. Unset: standard output. */
|
|
77
|
+
write?: (text: string) => void;
|
|
49
78
|
}
|
|
79
|
+
/** Total ms the gate did not run since start, from its tick whose gaps over the pause gap count. */
|
|
80
|
+
export declare function pausedMs(): number;
|
|
50
81
|
export declare function ignorableKillError(error: unknown): boolean;
|
|
51
|
-
|
|
82
|
+
/** Ends every running task, prints `STOPPED <label> after <n> s` and the last 40 lines of its output for each. @returns the labels */
|
|
83
|
+
export declare function stopRunning(reason: string): string[];
|
|
84
|
+
export declare function runBuffered(task: GateTask, env?: Record<string, string>, sampling?: MemorySampling, pause?: PauseWatch, clock?: GateClock): Promise<BufferedResult>;
|
|
52
85
|
export declare function runTasks(tasks: GateTask[], options?: RunTasksOptions): Promise<TaskResult[]>;
|
package/dist/sandbox-gate.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
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=(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
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
|
|
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
|
|
6
|
-
`),i=r.findIndex(e=>/Exception: |^\s*Error: /.test(e));i!==-1&&i<r.length-25&&
|
|
7
|
-
`)}`),
|
|
8
|
-
`)}`)}}}}function
|
|
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(`
|
|
9
9
|
`)?``:`
|
|
10
10
|
`}${i.join(`
|
|
11
|
-
`)}`,
|
|
12
|
-
`)
|
|
13
|
-
`).
|
|
14
|
-
`)),t
|
|
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(`
|
|
12
|
+
`).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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/sandbox-gate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.172.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.
|
|
28
|
+
"@webority/biome-config": "0.172.1",
|
|
29
29
|
"typescript": "^7.0.2",
|
|
30
30
|
"vite": "^8.3.6"
|
|
31
31
|
},
|