@webority/sandbox-gate 0.164.0 → 0.165.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/LICENSE +1 -1
- package/dist/log.d.ts +1 -0
- package/dist/sandbox-gate.js +8 -8
- package/package.json +2 -2
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Copyright (c) Webority Technologies. All rights reserved.
|
|
2
2
|
|
|
3
|
-
This software and its
|
|
3
|
+
This software and its Webority packages are the proprietary and confidential property
|
|
4
4
|
of Webority Technologies. They are published publicly only for the convenience of
|
|
5
5
|
Webority's own projects and internal consumption.
|
|
6
6
|
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function gateLog(message: string): void;
|
package/dist/sandbox-gate.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
|
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 M(e){if(process.platform===`win32`){let n=t(`netstat`,[`-ano`],{encoding:`utf8`}).stdout||``,r=new Set(n.split(`
|
|
4
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
|
|
6
|
-
`),i=r.findIndex(e=>/Exception: |^\s*Error: /.test(e));i!==-1&&i<r.length-25&&
|
|
7
|
-
`)}`),
|
|
8
|
-
`)}`)}}}}function
|
|
9
|
-
`)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms}})();return
|
|
10
|
-
`).filter(Boolean):null}function
|
|
11
|
-
`)),t=typeof e==`object`&&e&&`Version`in e?e.Version:void 0;return typeof t==`string`?t:null}catch{return null}}function
|
|
5
|
+
`).filter(Boolean);for(let e of n)t(`kill`,[`-9`,e],{stdio:`ignore`});return n.length>0}var N=[`react`,`razor`,`phoneWeb`];function P(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(!N.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=r.map(t=>{let[n,r]=y(t),a=b(t),o=i(a,`w`),s=e(O(n,r),{stdio:[`ignore`,o,o],shell:!0,env:{...process.env,...g,WEBORITY_GATE_SANDBOX:`1`}});return s.on(`exit`,(e,n)=>{s.killed||S.push({name:t,code:e,signal:n,log:a})}),s}),w=r.map(e=>d[e]??v(e));async function T(){for(let e of w)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 T())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
|
+
`),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
|
+
`)}`),D(`\n──── ${e} sandbox log, last 25 lines (${t}) ────\n${r.slice(-25).join(`
|
|
8
|
+
`)}`)}}}}function F({ports:e=[],children:t=[]}={}){for(let e of t)e.kill();for(let t of e)M(t);return w()}function I({name:e,code:t,signal:n,log:r}){return`The ${e} sandbox ended before the run did (${n?`signal ${n}`:`exit ${t}`}): ${n===`SIGKILL`||t===137?`the system killed it, usually for lack of memory`:`it stopped on its own`}. This is an infrastructure failure, not a test failure: rerun the gate. Log: ${r}`}var L=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,R=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,z=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`;function B(e,t=2){if(!Number.isInteger(t)||t<1||t>8)throw RangeError(`derivePorts: count must be 1 to 8, got ${t}`);let n=2e4+d(`sha1`).update(e).digest().readUInt16BE(0)%1e3*8;return Array.from({length:t},(e,t)=>n+t)}function V({command:t,args:n,label:r},i={}){return new Promise(a=>{let o=performance.now(),s=[],c=e(O(t,n),{shell:!0,env:{...process.env,...i}});c.stdout.on(`data`,e=>s.push(e)),c.stderr.on(`data`,e=>s.push(e)),c.on(`close`,e=>a({label:r,code:e??1,output:Buffer.concat(s).toString(),ms:Math.round(performance.now()-o)}))})}var H=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,U=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function W(e,t){let n=await V(e,t);if(n.code===0||!e.retryArgs||!H.test(n.output)||U.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 V({...e,args:e.retryArgs},t);return{...r,ms:n.ms+r.ms,output:`${n.output}\n──── retry ────\n${r.output}`}}async function G(e,t={}){if(e.length===0)return[];let{env:n={},heartbeatMs:r=6e4,maxParallel:i}=t;if(i!==void 0&&!(Number.isInteger(i)&&i>=1))throw Error(`runTasks: maxParallel must be a whole number of at least 1, not ${i}.`);let a=i??1/0,o=[],s=()=>a>0?(--a,Promise.resolve()):new Promise(e=>o.push(e)),c=()=>{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} ────`);let t;try{t=await W(e,n)}finally{c()}return u.add(t.label),D(`\n──── ${t.label} → ${t.code===0?`ok`:`FAIL`} (${A(t.ms)}) ────`),process.stdout.write(t.output.endsWith(`
|
|
9
|
+
`)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms}})();return f.set(e.label,t),t}))}finally{clearInterval(d)}return D(`──── group wall time: ${A(Math.round(performance.now()-l))} ────`),p}function K(e,n){let r=t(`git`,n,{cwd:e,encoding:`utf8`});return r.status===0?r.stdout.split(`
|
|
10
|
+
`).filter(Boolean):null}function q(e,t=process.env.GATE_BASE||null){let n=t?K(e,[`diff`,`--name-only`,`--no-renames`,t,`HEAD`]):K(e,[`diff`,`--name-only`,`--no-renames`,`origin/development...HEAD`]);if(n===null)return null;let r=K(e,[`diff`,`--name-only`,`--no-renames`,`HEAD`])??[],i=K(e,[`ls-files`,`--others`,`--exclude-standard`])??[];return[.../* @__PURE__ */ new Set([...n,...r,...i])].sort()}function J(e,t){return t||K(e,[`merge-base`,`origin/development`,`HEAD`])?.[0]||null}function Y(e,t){let n=K(e,[`show`,`${t}:version.json`]);if(n===null)return null;try{let e=JSON.parse(n.join(`
|
|
11
|
+
`)),t=typeof e==`object`&&e&&`Version`in e?e.Version:void 0;return typeof t==`string`?t:null}catch{return null}}function X(e,t,n){let r=J(e,n);if(!r)return!1;let i=Y(e,r),a=Y(e,`HEAD`);if(i===null||a===null||i===a)return!1;let o=K(e,[`status`,`--porcelain`,`--`,t]);if(o===null||o.length>0)return!1;let s=K(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,E as LIGHT_SCHEME_ARG,z as PHONE_WEB_ORIGIN,R as RAZOR_ORIGIN,L as REACT_ORIGIN,f as accessibilityTree,J as baseCommitOf,P as bootSandboxes,q as changedFiles,B as derivePorts,I as describeSandboxDeath,k as exitAfterOutput,_ as gateOwnerPid,K as gitLines,M as killPort,p as parseAriaSnapshot,y as playwrightGateArgs,v as profileDir,j as reachable,C as reapOrphanGateChrome,w as reapOwnGateChrome,V as runBuffered,G as runTasks,A as secs,O as shellLine,F as stopAll,X as versionStampOnly};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/sandbox-gate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.165.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.165.0",
|
|
29
29
|
"typescript": "^7.0.2",
|
|
30
30
|
"vite": "^8.3.6"
|
|
31
31
|
},
|