@webority/sandbox-gate 0.149.0 → 0.152.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.
@@ -0,0 +1,15 @@
1
+ export interface AriaNode {
2
+ depth: number;
3
+ role: string;
4
+ name: string;
5
+ states: string[];
6
+ }
7
+ export interface AriaPage {
8
+ locator(selector: string): {
9
+ ariaSnapshot(): Promise<string>;
10
+ };
11
+ }
12
+ export declare function accessibilityTree(page: AriaPage, options?: {
13
+ selector?: string;
14
+ }): Promise<AriaNode[]>;
15
+ export declare function parseAriaSnapshot(yaml: string): AriaNode[];
package/dist/boot.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import type { SandboxDeath } from "./deaths.ts";
3
+ export type SandboxName = "react" | "razor" | "phoneWeb";
4
+ export interface BootSandboxesOptions {
5
+ root: string;
6
+ which: SandboxName[];
7
+ ports: Partial<Record<SandboxName, number>>;
8
+ origins: Partial<Record<SandboxName, string>>;
9
+ readyUrls?: Partial<Record<SandboxName, string>>;
10
+ reactFilter?: string;
11
+ razorProject?: string;
12
+ phoneWebDir?: string;
13
+ /** Added to each sandbox's log file name, so several pairs booted by one run keep separate logs. */
14
+ tag?: string;
15
+ /** Merged over process.env for both children. */
16
+ env?: Record<string, string>;
17
+ }
18
+ export interface BootedSandboxes {
19
+ children: ChildProcess[];
20
+ logs: Partial<Record<SandboxName, string>>;
21
+ waitReady(options?: {
22
+ attempts?: number;
23
+ intervalMs?: number;
24
+ }): Promise<boolean>;
25
+ finish(code: number): void;
26
+ deaths(): SandboxDeath[];
27
+ }
28
+ export declare function bootSandboxes(options: BootSandboxesOptions): BootedSandboxes;
29
+ export declare function stopAll({ ports, children }?: {
30
+ ports?: number[];
31
+ children?: ChildProcess[];
32
+ }): number;
@@ -0,0 +1,30 @@
1
+ export declare const GATE_CHROME_MARKER: string;
2
+ /** PID of the gate run that owns this browser (check-all sets WEBORITY_UI_GATE_PID). */
3
+ export declare function gateOwnerPid(): number;
4
+ /** Unique Chrome user-data-dir under tmpdir, tagged for orphan reap. */
5
+ export declare function profileDir(): string;
6
+ /**
7
+ * Playwright must not pass --user-data-dir in launchOptions.args (it throws a misuse error
8
+ * and manages its own unique temp profile per worker). A ignored Chromium switch still lands
9
+ * in CommandLine so startup reap can find orphans without colliding worker profiles.
10
+ */
11
+ export declare function playwrightGateArgs(): string[];
12
+ /**
13
+ * Kill gate-tagged Chrome whose owning gate PID is no longer alive.
14
+ * Safe beside live sibling sessions: their owner PID is still running.
15
+ * @returns processes signalled
16
+ */
17
+ export declare function reapOrphanGateChrome(): number;
18
+ /**
19
+ * Kill the gate-tagged Chrome that this gate run owns. Selecting by owner tag, never by start
20
+ * time: a sibling gate on the same machine launches browsers during this run too, and killing
21
+ * those failed its tests with "Target page, context or browser has been closed".
22
+ * @returns processes signalled
23
+ */
24
+ export declare function reapOwnGateChrome(ownerPid?: number): number;
25
+ /**
26
+ * Gate browsers render the light theme whatever the machine's appearance setting: a theme that
27
+ * follows the device otherwise turns one surface dark on a dark-mode machine and fails every
28
+ * colour comparison.
29
+ */
30
+ export declare const LIGHT_SCHEME_ARG: string;
@@ -0,0 +1,8 @@
1
+ import type { SandboxName } from "./boot.ts";
2
+ export interface SandboxDeath {
3
+ name: SandboxName;
4
+ code: number | null;
5
+ signal: string | null;
6
+ log: string;
7
+ }
8
+ export declare function describeSandboxDeath({ name, code, signal, log }: SandboxDeath): string;
package/dist/index.d.ts CHANGED
@@ -1,102 +1,13 @@
1
- import type { ChildProcess } from "node:child_process";
2
-
3
- export type SandboxName = "react" | "razor" | "phoneWeb";
4
-
5
- export interface GateTask {
6
- command: string;
7
- args: string[];
8
- label: string;
9
- retryArgs?: string[];
10
- after?: string;
11
- }
12
-
13
- export interface TaskResult {
14
- label: string;
15
- code: number;
16
- ms: number;
17
- }
18
-
19
- export interface BufferedResult extends TaskResult {
20
- output: string;
21
- }
22
-
23
- export interface RunTasksOptions {
24
- env?: Record<string, string>;
25
- heartbeatMs?: number;
26
- quick?: boolean;
27
- /** How many tasks run at once; the rest start in list order as slots free. Unset: all at once. */
28
- maxParallel?: number;
29
- }
30
-
31
- export interface BootSandboxesOptions {
32
- root: string;
33
- which: SandboxName[];
34
- ports: Partial<Record<SandboxName, number>>;
35
- origins: Partial<Record<SandboxName, string>>;
36
- readyUrls?: Partial<Record<SandboxName, string>>;
37
- reactFilter?: string;
38
- razorProject?: string;
39
- phoneWebDir?: string;
40
- /** Added to each sandbox's log file name, so several pairs booted by one run keep separate logs. */
41
- tag?: string;
42
- /** Merged over process.env for both children. */
43
- env?: Record<string, string>;
44
- }
45
-
46
- export interface SandboxDeath {
47
- name: SandboxName;
48
- code: number | null;
49
- signal: string | null;
50
- log: string;
51
- }
52
-
53
- export interface BootedSandboxes {
54
- children: ChildProcess[];
55
- logs: Partial<Record<SandboxName, string>>;
56
- waitReady(options?: { attempts?: number; intervalMs?: number }): Promise<boolean>;
57
- finish(code: number): void;
58
- deaths(): SandboxDeath[];
59
- }
60
-
61
- export interface AriaNode {
62
- depth: number;
63
- role: string;
64
- name: string;
65
- states: string[];
66
- }
67
-
68
- export interface AriaPage {
69
- locator(selector: string): { ariaSnapshot(): Promise<string> };
70
- }
71
-
72
- export function derivePorts(root: string, count?: number): number[];
73
- export function runTasks(tasks: GateTask[], options?: RunTasksOptions): Promise<TaskResult[]>;
74
- export function runBuffered(task: GateTask, env?: Record<string, string>): Promise<BufferedResult>;
75
- export function bootSandboxes(options: BootSandboxesOptions): BootedSandboxes;
76
- export function stopAll(options?: { ports?: number[]; children?: ChildProcess[] }): number;
77
- export function describeSandboxDeath(death: SandboxDeath): string;
78
- export function accessibilityTree(page: AriaPage, options?: { selector?: string }): Promise<AriaNode[]>;
79
- export function parseAriaSnapshot(yaml: string): AriaNode[];
80
-
81
- export function killPort(port: number): boolean;
82
- export function reachable(url: string): Promise<boolean>;
83
- export function secs(ms: number): string;
84
- export function shellLine(command: string, args?: string[]): string;
85
- export function exitAfterOutput(code: number): Promise<void>;
86
-
87
- export function gitLines(root: string, args: string[]): string[] | null;
88
- export function changedFiles(root: string, base?: string | null): string[] | null;
89
- export function baseCommitOf(root: string, base: string | null): string | null;
90
- export function versionStampOnly(root: string, file: string, base: string | null): boolean;
91
-
92
- export const GATE_CHROME_MARKER: string;
93
- export function gateOwnerPid(): number;
94
- export function profileDir(): string;
95
- export function playwrightGateArgs(): string[];
96
- export function reapOrphanGateChrome(): number;
97
- export function reapOwnGateChrome(ownerPid?: number): number;
98
- export const LIGHT_SCHEME_ARG: string;
99
-
100
- export const REACT_ORIGIN: string;
101
- export const RAZOR_ORIGIN: string;
102
- export const PHONE_WEB_ORIGIN: string;
1
+ export type { AriaNode, AriaPage } from "./accessibility.ts";
2
+ export { accessibilityTree, parseAriaSnapshot } from "./accessibility.ts";
3
+ export type { BootedSandboxes, BootSandboxesOptions, SandboxName } from "./boot.ts";
4
+ export { bootSandboxes, stopAll } from "./boot.ts";
5
+ export * from "./chrome.ts";
6
+ export type { SandboxDeath } from "./deaths.ts";
7
+ export { describeSandboxDeath } from "./deaths.ts";
8
+ export { PHONE_WEB_ORIGIN, RAZOR_ORIGIN, REACT_ORIGIN } from "./origins.ts";
9
+ export { derivePorts } from "./ports.ts";
10
+ export { exitAfterOutput, killPort, reachable, secs, shellLine } from "./process.ts";
11
+ export type { BufferedResult, GateTask, RunTasksOptions, TaskResult } from "./runner.ts";
12
+ export { runBuffered, runTasks } from "./runner.ts";
13
+ export { baseCommitOf, changedFiles, gitLines, versionStampOnly } from "./scope.ts";
@@ -0,0 +1,3 @@
1
+ export declare const REACT_ORIGIN: string;
2
+ export declare const RAZOR_ORIGIN: string;
3
+ export declare const PHONE_WEB_ORIGIN: string;
@@ -0,0 +1 @@
1
+ export declare function derivePorts(root: string, count?: number): number[];
@@ -0,0 +1,6 @@
1
+ export declare const shellLine: (command: string, args?: string[]) => string;
2
+ export declare function exitAfterOutput(code: number): Promise<void>;
3
+ export declare const secs: (ms: number) => string;
4
+ export declare function reachable(url: string): Promise<boolean>;
5
+ /** Kill the process listening on a port, and its descendants. */
6
+ export declare function killPort(port: number): boolean;
@@ -0,0 +1,24 @@
1
+ export interface GateTask {
2
+ command: string;
3
+ args: string[];
4
+ label: string;
5
+ retryArgs?: string[];
6
+ after?: string;
7
+ }
8
+ export interface TaskResult {
9
+ label: string;
10
+ code: number;
11
+ ms: number;
12
+ }
13
+ export interface BufferedResult extends TaskResult {
14
+ output: string;
15
+ }
16
+ export interface RunTasksOptions {
17
+ env?: Record<string, string>;
18
+ heartbeatMs?: number;
19
+ quick?: boolean;
20
+ /** How many tasks run at once; the rest start in list order as slots free. Unset: all at once. */
21
+ maxParallel?: number;
22
+ }
23
+ export declare function runBuffered({ command, args, label }: GateTask, env?: Record<string, string>): Promise<BufferedResult>;
24
+ export declare function runTasks(tasks: GateTask[], options?: RunTasksOptions): Promise<TaskResult[]>;
@@ -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
- `)){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(Boolean):(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+(.*)$/);return t?{pid:t[1],commandLine:t[2]}:null}).filter(Boolean)}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.code!==`ENOENT`)throw e}}}var E=`--blink-settings=preferredColorScheme=1`,D=(e,t=[])=>[e,...t].join(` `);async function O(e){await new Promise(e=>process.stdout.write(``,e)),await new Promise(e=>process.stderr.write(``,e)),process.exit(e)}var k=e=>`${(e/1e3).toFixed(1)}s`;async function A(e){try{return(await fetch(e)).ok}catch{return!1}}function j(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}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 M=[`react`,`razor`,`phoneWeb`];function N(t){let{which:r,ports:o,origins:l,readyUrls:d={},reactFilter:f=`@webority/react-sandbox`,razorProject:p=`samples/Razor.Sandbox`,phoneWebDir:m=`samples/mobile-sandbox-web`,tag:h,env:g={}}=t;for(let e of r){if(!M.includes(e))throw Error(`bootSandboxes: unknown sandbox "${e}"`);if(o[e]===void 0)throw Error(`bootSandboxes: no port for "${e}"`);if(l[e]===void 0)throw Error(`bootSandboxes: no origin for "${e}"`)}let _={react:[`corepack`,[`pnpm`,`--filter`,f,`dev`,`--port`,String(o.react),`--strictPort`]],razor:[`dotnet`,[`run`,`--project`,p,`--no-build`,`--`,`--urls`,l.razor]],phoneWeb:[`corepack`,[`pnpm`,`--dir`,m,`exec`,`vite`,`--port`,String(o.phoneWeb),`--strictPort`]]},v={};for(let e of r)v[e]=u(c(),`webority-gate-${h?`${e}-${h}`:e}-sandbox-${process.pid}.log`);let y=[];console.log(`\nStarting the sandboxes (${r.join(`, `)})... (output: ${r.map(e=>v[e]).join(`, `)})`);let b=r.map(t=>{let[n,r]=_[t],a=i(v[t],`w`),o=e(D(n,r),{stdio:[`ignore`,a,a],shell:!0,env:{...process.env,...g}});return o.on(`exit`,(e,n)=>{o.killed||y.push({name:t,code:e,signal:n,log:v[t]})}),o}),x=r.map(e=>d[e]??l[e]);async function S(){for(let e of x)if(!await A(e))return!1;return!0}return{children:b,logs:v,deaths:()=>[...y],async waitReady({attempts:e=600,intervalMs:t=300}={}){for(let n=0;n<e;n+=1){if(await S())return!0;await new Promise(e=>setTimeout(e,t))}return!1},finish(e){if(e===0)for(let e of Object.values(v))s(e,{force:!0});else for(let[e,t]of Object.entries(v)){if(!n(t))continue;let r=a(t,`utf8`).trimEnd().split(`
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`,D=(e,t=[])=>[e,...t].join(` `);async function O(e){await new Promise(e=>process.stdout.write(``,()=>e())),await new Promise(e=>process.stderr.write(``,()=>e())),process.exit(e)}var k=e=>`${(e/1e3).toFixed(1)}s`;async function A(e){try{return(await fetch(e)).ok}catch{return!1}}function j(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}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 M=[`react`,`razor`,`phoneWeb`];function N(t){let{which:r,ports:o,origins:l,readyUrls:d={},reactFilter:f=`@webority/react-sandbox`,razorProject:p=`samples/Razor.Sandbox`,phoneWebDir:m=`samples/mobile-sandbox-web`,tag:h,env:g={}}=t,_=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(!M.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=[];console.log(`\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(D(n,r),{stdio:[`ignore`,o,o],shell:!0,env:{...process.env,...g}});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 A(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
6
  `),i=r.findIndex(e=>/Exception: |^\s*Error: /.test(e));i!==-1&&i<r.length-25&&console.log(`\n──── ${e} sandbox log, first error (${t}:${i+1}) ────\n${r.slice(i,i+3).join(`
7
7
  `)}`),console.log(`\n──── ${e} sandbox log, last 25 lines (${t}) ────\n${r.slice(-25).join(`
8
- `)}`)}}}}function P({ports:e=[],children:t=[]}={}){for(let e of t)e.kill();for(let t of e)j(t);return w()}function F({name:e,code:t,signal:n,log:r}){return`The ${e} sandbox ended before the run did (${n?`signal ${n}`:`exit ${t}`}): ${n===`SIGKILL`||t===137?`the system killed it, usually for lack of memory`:`it stopped on its own`}. This is an infrastructure failure, not a test failure: rerun the gate. Log: ${r}`}var I=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,L=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,R=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`;function z(e,t=2){if(!Number.isInteger(t)||t<1||t>8)throw RangeError(`derivePorts: count must be 1 to 8, got ${t}`);let n=2e4+d(`sha1`).update(e).digest().readUInt16BE(0)%1e3*8;return Array.from({length:t},(e,t)=>n+t)}function B({command:t,args:n,label:r},i={}){return new Promise(a=>{let o=performance.now(),s=[],c=e(D(t,n),{shell:!0,env:{...process.env,...i}});c.stdout.on(`data`,e=>s.push(e)),c.stderr.on(`data`,e=>s.push(e)),c.on(`close`,e=>a({label:r,code:e??1,output:Buffer.concat(s).toString(),ms:Math.round(performance.now()-o)}))})}var V=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,H=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function U(e,t){let n=await B(e,t);if(n.code===0||!e.retryArgs||!V.test(n.output)||H.test(n.output))return n;console.log(`\n──── RETRY ${e.label}: the vitest worker pool did not start in time (machine load, ${k(n.ms)}); running it once more with half the workers ────`);let r=await B({...e,args:e.retryArgs},t);return{...r,ms:n.ms+r.ms,output:`${n.output}\n──── retry ────\n${r.output}`}}async function W(e,t={}){if(e.length===0)return[];let{env:n={},heartbeatMs:r=6e4,maxParallel:i}=t;if(i!==void 0&&!(Number.isInteger(i)&&i>=1))throw Error(`runTasks: maxParallel must be a whole number of at least 1, not ${i}.`);let a=i??1/0,o=[],s=()=>a>0?(--a,Promise.resolve()):new Promise(e=>o.push(e)),c=()=>{o.length>0?o.shift()():a+=1},l=i!==void 0&&i<e.length?`, ${i} at a time`:``;console.log(`\n──── running in parallel${l}: ${e.map(e=>e.label).join(` · `)} ────`);let u=performance.now(),d=/* @__PURE__ */ new Set,f=setInterval(()=>{let t=e.map(e=>e.label).filter(e=>!d.has(e));console.log(`still running after ${Math.round((performance.now()-u)/1e3)} s: ${t.join(`, `)}`)},r),p=/* @__PURE__ */ new Map,m;try{m=await Promise.all(e.map(e=>{let t=(async()=>{await null,e.after&&p.has(e.after)&&await p.get(e.after),await s(),console.log(`\n──── start ${e.label} ────`);let t;try{t=await U(e,n)}finally{c()}return d.add(t.label),console.log(`\n──── ${t.label} → ${t.code===0?`ok`:`FAIL`} (${k(t.ms)}) ────`),process.stdout.write(t.output.endsWith(`
8
+ `)}`)}}}}function P({ports:e=[],children:t=[]}={}){for(let e of t)e.kill();for(let t of e)j(t);return w()}function F({name:e,code:t,signal:n,log:r}){return`The ${e} sandbox ended before the run did (${n?`signal ${n}`:`exit ${t}`}): ${n===`SIGKILL`||t===137?`the system killed it, usually for lack of memory`:`it stopped on its own`}. This is an infrastructure failure, not a test failure: rerun the gate. Log: ${r}`}var I=process.env.WUI_REACT_ORIGIN||`http://localhost:5173`,L=process.env.WUI_RAZOR_ORIGIN||`http://localhost:5299`,R=process.env.WUI_PHONE_WEB_ORIGIN||`http://localhost:5174`;function z(e,t=2){if(!Number.isInteger(t)||t<1||t>8)throw RangeError(`derivePorts: count must be 1 to 8, got ${t}`);let n=2e4+d(`sha1`).update(e).digest().readUInt16BE(0)%1e3*8;return Array.from({length:t},(e,t)=>n+t)}function B({command:t,args:n,label:r},i={}){return new Promise(a=>{let o=performance.now(),s=[],c=e(D(t,n),{shell:!0,env:{...process.env,...i}});c.stdout.on(`data`,e=>s.push(e)),c.stderr.on(`data`,e=>s.push(e)),c.on(`close`,e=>a({label:r,code:e??1,output:Buffer.concat(s).toString(),ms:Math.round(performance.now()-o)}))})}var V=/\[vitest-pool\]: Failed to start \w+ worker|\[vitest-pool-runner\]: Timeout waiting for worker to respond/,H=/^\s*(Test Files|Tests)\s.*\b\d+ failed/m;async function U(e,t){let n=await B(e,t);if(n.code===0||!e.retryArgs||!V.test(n.output)||H.test(n.output))return n;console.log(`\n──── RETRY ${e.label}: the vitest worker pool did not start in time (machine load, ${k(n.ms)}); running it once more with half the workers ────`);let r=await B({...e,args:e.retryArgs},t);return{...r,ms:n.ms+r.ms,output:`${n.output}\n──── retry ────\n${r.output}`}}async function W(e,t={}){if(e.length===0)return[];let{env:n={},heartbeatMs:r=6e4,maxParallel:i}=t;if(i!==void 0&&!(Number.isInteger(i)&&i>=1))throw Error(`runTasks: maxParallel must be a whole number of at least 1, not ${i}.`);let a=i??1/0,o=[],s=()=>a>0?(--a,Promise.resolve()):new Promise(e=>o.push(e)),c=()=>{let e=o.shift();e===void 0?a+=1:e()},l=i!==void 0&&i<e.length?`, ${i} at a time`:``;console.log(`\n──── running in parallel${l}: ${e.map(e=>e.label).join(` · `)} ────`);let u=performance.now(),d=/* @__PURE__ */ new Set,f=setInterval(()=>{let t=e.map(e=>e.label).filter(e=>!d.has(e));console.log(`still running after ${Math.round((performance.now()-u)/1e3)} s: ${t.join(`, `)}`)},r),p=/* @__PURE__ */ new Map,m;try{m=await Promise.all(e.map(e=>{let t=(async()=>{await null,e.after&&p.has(e.after)&&await p.get(e.after),await s(),console.log(`\n──── start ${e.label} ────`);let t;try{t=await U(e,n)}finally{c()}return d.add(t.label),console.log(`\n──── ${t.label} → ${t.code===0?`ok`:`FAIL`} (${k(t.ms)}) ────`),process.stdout.write(t.output.endsWith(`
9
9
  `)?t.output:`${t.output}\n`),{label:t.label,code:t.code,ms:t.ms}})();return p.set(e.label,t),t}))}finally{clearInterval(f)}return console.log(`──── group wall time: ${k(Math.round(performance.now()-u))} ────`),m}function G(e,n){let r=t(`git`,n,{cwd:e,encoding:`utf8`});return r.status===0?r.stdout.split(`
10
10
  `).filter(Boolean):null}function K(e,t=process.env.GATE_BASE||null){let n=t?G(e,[`diff`,`--name-only`,`--no-renames`,t,`HEAD`]):G(e,[`diff`,`--name-only`,`--no-renames`,`origin/development...HEAD`]);if(n===null)return null;let r=G(e,[`diff`,`--name-only`,`--no-renames`,`HEAD`])??[],i=G(e,[`ls-files`,`--others`,`--exclude-standard`])??[];return[.../* @__PURE__ */ new Set([...n,...r,...i])].sort()}function q(e,t){return t||G(e,[`merge-base`,`origin/development`,`HEAD`])?.[0]||null}function J(e,t){let n=G(e,[`show`,`${t}:version.json`]);if(n===null)return null;try{let e=JSON.parse(n.join(`
11
- `)).Version;return typeof e==`string`?e:null}catch{return null}}function Y(e,t,n){let r=q(e,n);if(!r)return!1;let i=J(e,r),a=J(e,`HEAD`);if(i===null||a===null||i===a)return!1;let o=G(e,[`status`,`--porcelain`,`--`,t]);if(o===null||o.length>0)return!1;let s=G(e,[`diff`,`-U0`,`--no-renames`,r,`HEAD`,`--`,t]);if(s===null)return!1;let c=[];for(let e of s)e.startsWith(`@@`)?c.push({removed:[],added:[]}):c.length&&e.startsWith(`-`)?c.at(-1).removed.push(e.slice(1)):c.length&&e.startsWith(`+`)&&c.at(-1).added.push(e.slice(1));return c.length!==0&&c.every(({removed:e,added:t})=>e.length===t.length&&e.every((e,n)=>e.split(i).join(a)===t[n]))}export{h as GATE_CHROME_MARKER,E as LIGHT_SCHEME_ARG,R as PHONE_WEB_ORIGIN,L as RAZOR_ORIGIN,I as REACT_ORIGIN,f as accessibilityTree,q as baseCommitOf,N as bootSandboxes,K as changedFiles,z as derivePorts,F as describeSandboxDeath,O as exitAfterOutput,_ as gateOwnerPid,G as gitLines,j as killPort,p as parseAriaSnapshot,y as playwrightGateArgs,v as profileDir,A as reachable,C as reapOrphanGateChrome,w as reapOwnGateChrome,B as runBuffered,W as runTasks,k as secs,D as shellLine,P as stopAll,Y as versionStampOnly};
11
+ `)),t=typeof e==`object`&&e&&`Version`in e?e.Version:void 0;return typeof t==`string`?t:null}catch{return null}}function Y(e,t,n){let r=q(e,n);if(!r)return!1;let i=J(e,r),a=J(e,`HEAD`);if(i===null||a===null||i===a)return!1;let o=G(e,[`status`,`--porcelain`,`--`,t]);if(o===null||o.length>0)return!1;let s=G(e,[`diff`,`-U0`,`--no-renames`,r,`HEAD`,`--`,t]);if(s===null)return!1;let c=[];for(let e of s){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,R as PHONE_WEB_ORIGIN,L as RAZOR_ORIGIN,I as REACT_ORIGIN,f as accessibilityTree,q as baseCommitOf,N as bootSandboxes,K as changedFiles,z as derivePorts,F as describeSandboxDeath,O as exitAfterOutput,_ as gateOwnerPid,G as gitLines,j as killPort,p as parseAriaSnapshot,y as playwrightGateArgs,v as profileDir,A as reachable,C as reapOrphanGateChrome,w as reapOwnGateChrome,B as runBuffered,W as runTasks,k as secs,D as shellLine,P as stopAll,Y as versionStampOnly};
@@ -0,0 +1,7 @@
1
+ export declare function gitLines(root: string, args: string[]): string[] | null;
2
+ /**
3
+ * Changed files since `base` (GATE_BASE, two-dot diff) or since origin/development (three-dot), plus uncommitted and untracked files; null when git cannot diff.
4
+ */
5
+ export declare function changedFiles(root: string, base?: string | null): string[] | null;
6
+ export declare function baseCommitOf(root: string, base: string | null): string | null;
7
+ export declare function versionStampOnly(root: string, file: string, base: string | null): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/sandbox-gate",
3
- "version": "0.149.0",
3
+ "version": "0.152.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",
@@ -24,10 +24,14 @@
24
24
  "node": ">=24.15 <27"
25
25
  },
26
26
  "devDependencies": {
27
+ "@types/node": "^24.0.0",
28
+ "@webority/biome-config": "0.152.0",
29
+ "typescript": "^7.0.2",
27
30
  "vite": "^8.3.6"
28
31
  },
29
32
  "scripts": {
30
- "build": "vite build && node scripts/copy-types.mjs",
33
+ "build": "tsc -p tsconfig.json && vite build && tsc -p tsconfig.build.json",
34
+ "typecheck": "tsc -p tsconfig.json",
31
35
  "test": "node --test"
32
36
  }
33
37
  }