shiplightai 0.1.71 → 0.1.73
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/dist/cjs/debugger-manager.cjs +7 -7
- package/dist/cjs/debugger-pw.cjs +84 -83
- package/dist/cjs/fixture.cjs +46 -46
- package/dist/cjs/index.cjs +63 -63
- package/dist/cjs/reporter.cjs +35 -35
- package/dist/cli.js +93 -93
- package/dist/debugger-manager.js +9 -9
- package/dist/debugger-pw.js +85 -84
- package/dist/fixture.d.ts +24 -1
- package/dist/fixture.js +55 -55
- package/dist/index.js +90 -90
- package/dist/reporter.js +33 -33
- package/dist/static/assets/{index-BQYw0-8-.js → index-CsPWUDqs.js} +221 -23
- package/dist/static/index.html +1 -1
- package/dist/static-embedded/assets/{index-Bosp2pQJ.js → index-BEW7CdFm.js} +51 -162
- package/dist/static-embedded/assets/{index-Eah7879k.js → index-CoKedfWS.js} +2 -2
- package/dist/static-embedded/index.html +1 -1
- package/package.json +3 -3
package/dist/debugger-manager.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import*as N from"http";import*as j from"net";import*as y from"path";import*as D from"fs";import{randomUUID as M}from"crypto";import*as w from"fs";import*as m from"path";import{spawn as A}from"child_process";import{parse as B}from"yaml";function O(
|
|
1
|
+
import*as N from"http";import*as j from"net";import*as y from"path";import*as D from"fs";import{randomUUID as M}from"crypto";import*as w from"fs";import*as m from"path";import{spawn as A}from"child_process";import{parse as B}from"yaml";function O(l){let s=!1;return()=>{if(!s){s=!0;try{w.unlinkSync(l)}catch{}}}}function $(l){let s=["playwright.config.ts","playwright.config.js","playwright.config.mjs"],e=m.resolve(l);for(;;){for(let r of s){let t=m.join(e,r);if(w.existsSync(t))return t}let n=m.dirname(e);if(n===e)break;e=n}return null}function L(l,s,e,n){let r={...e},t=r.launchOptions?.args??[];return r.launchOptions={...r.launchOptions??{},args:[...t,"--remote-debugging-port=0"]},`// @generated by shiplightai \u2014 temporary debug test
|
|
2
2
|
import { test } from 'shiplightai/fixture';
|
|
3
3
|
${`
|
|
4
|
-
test.use(${JSON.stringify(
|
|
4
|
+
test.use(${JSON.stringify(r)});
|
|
5
5
|
`}
|
|
6
6
|
test('__shiplight_debug__', async ({ page, agent }) => {
|
|
7
7
|
// Disable timeout \u2014 debugger runs until user stops it
|
|
@@ -10,7 +10,7 @@ test('__shiplight_debug__', async ({ page, agent }) => {
|
|
|
10
10
|
const { startPlaywrightDebugServer } = await import('shiplightai/debugger-pw');
|
|
11
11
|
|
|
12
12
|
const server = await startPlaywrightDebugServer({
|
|
13
|
-
yamlFilePath: ${JSON.stringify(
|
|
13
|
+
yamlFilePath: ${JSON.stringify(l)},
|
|
14
14
|
port: ${s},
|
|
15
15
|
page,
|
|
16
16
|
agent,
|
|
@@ -22,14 +22,14 @@ test('__shiplight_debug__', async ({ page, agent }) => {
|
|
|
22
22
|
// Keep alive until the server is closed externally (Ctrl+C kills the process)
|
|
23
23
|
await new Promise(() => {});
|
|
24
24
|
});
|
|
25
|
-
`}async function U(
|
|
25
|
+
`}async function U(l){let{createServer:s}=await import("net");for(let e=l;e<l+20;e++)if(await new Promise(r=>{let t=s();t.once("error",()=>r(!1)),t.once("listening",()=>{t.close(()=>r(!0))}),t.listen(e,"127.0.0.1")}))return e;throw new Error(`No available port found in range ${l}-${l+19}`)}async function R(l){let{yamlFilePath:s,configPath:e,tempSuffix:n="",headed:r}=l,t=m.dirname(e),i=await U(16174),o;if(!w.existsSync(s))throw new Error(`Please select a test file before starting the debug session. File not found: ${s}`);try{let u=B(w.readFileSync(s,"utf-8"));u?.use&&typeof u.use=="object"&&!Array.isArray(u.use)&&(o=u.use),u?.base_url&&!o?.baseURL&&(o={...o,baseURL:u.base_url})}catch(u){console.error("[debugger] Could not parse YAML for `use` block:",u)}let d=m.dirname(m.resolve(s)),a=n?`-${n}`:"",c=m.join(d,`.__shiplight_debug__${a}.yaml.spec.ts`),p=L(s,i,o,t);w.writeFileSync(c,p);let h=O(c),v=["playwright","test",c,...r?["--headed"]:[]],g=A("npx",v,{stdio:["ignore","pipe","pipe"],shell:!0,cwd:t,env:{...process.env,PWDEBUG:"console",SHIPLIGHT_REGISTRY_URL:""}});g.stdout?.on("data",u=>{process.stderr.write(u)}),g.stderr?.on("data",u=>{process.stderr.write(u)});let f=()=>{g.killed||g.kill("SIGTERM")};process.on("SIGTERM",f),process.on("SIGINT",f),process.on("exit",f),g.on("close",u=>{process.removeListener("SIGTERM",f),process.removeListener("SIGINT",f),process.removeListener("exit",f),h(),u!==0&&u!==null&&console.error(`[debugger] Playwright process exited with code ${u}`)}),console.error("[debugger] Waiting for Playwright sandbox to start...");let x=["127.0.0.1","::1"];async function b(u){try{let S=u.includes(":")?`[${u}]`:u,I=await fetch(`http://${S}:${i}/api/test-flow`);if(I.ok){try{await I.text()}catch{}return!0}}catch{}return!1}let P=null;for(let u=0;u<180;u++){if(g.exitCode!==null)throw h(),new Error(`Playwright process exited with code ${g.exitCode} before sandbox was ready`);for(let S of x)if(await b(S)){P=S;break}if(P){console.error(`[debugger] Playwright sandbox ready on ${P}:${i}`);break}if(u===179)throw f(),h(),new Error("Timed out waiting for Playwright sandbox to start (180s)");await new Promise(S=>setTimeout(S,1e3))}if(!P)throw f(),h(),new Error("Sandbox poll finished without a reachable host");return{port:i,host:P,pid:g.pid??0,cleanup:async()=>{f(),h()}}}var H=1e4,E=class{sessions=new Map;byYamlPath=new Map;options;spawner;headed;constructor(s={}){this.options=s,this.spawner=s.spawner??R,this.headed=s.headed??!1}log(s){this.options.onLog?this.options.onLog(s):console.error(s)}notifyStateChange(s){try{this.options.onSessionStateChange?.({...s})}catch(e){this.log(`[manager] onSessionStateChange listener threw: ${e.message}`)}}openSession(s){let e=y.resolve(s),n=this.byYamlPath.get(e);if(n){let a=this.sessions.get(n);if(a&&a.session.status!=="ended")return{...a.session};this.byYamlPath.delete(e)}if(!D.existsSync(e))throw new Error(`YAML file not found: ${e}`);if(!$(y.dirname(e)))throw new Error(`No Playwright config found for ${e} (searched parents for playwright.config.{ts,js,mjs}).`);let t=`dbg-${M().slice(0,8)}`,i=new Date().toISOString(),o={sessionId:t,yamlPath:e,innerPort:0,innerHost:"127.0.0.1",pid:0,startedAt:i,status:"idle",exitInfo:null},d={session:o,cleanup:async()=>{},readyPromise:Promise.resolve()};return this.sessions.set(t,d),this.byYamlPath.set(e,t),this.notifyStateChange(o),this.log(`[manager] session ${t} created (idle) for ${y.basename(e)}`),{...o}}async startSandbox(s){let e=this.sessions.get(s);if(!e)throw new Error(`No session ${s} to start sandbox for`);if(e.session.status==="running"||e.session.status==="starting"){e.readyPromise&&await e.readyPromise;return}if(e.session.status==="ended")throw new Error(`Session ${s} has ended`);let n=e.session.yamlPath,r=$(y.dirname(n));if(!r)throw new Error(`No Playwright config found for ${n} (searched parents for playwright.config.{ts,js,mjs}).`);e.session.status="starting",this.notifyStateChange(e.session);let t=(async()=>{let i=H+18e4,o,d=new Promise((p,h)=>{o=setTimeout(()=>h(new Error(`Timed out after ${i/1e3}s waiting for inner playwright to register on a port.`)),i)}),a;try{a=await Promise.race([this.spawner({yamlFilePath:n,configPath:r,tempSuffix:s,headed:this.headed}),d])}finally{o&&clearTimeout(o)}e.session.innerPort=a.port,e.session.innerHost=a.host,e.session.pid=a.pid,e.session.status="running",e.cleanup=a.cleanup;let c=p=>{e.session.status!=="ended"&&(e.session.status="ended",e.session.exitInfo=p,this.notifyStateChange(e.session))};e.livenessTimer=this.startLivenessProbe(s,c),this.notifyStateChange(e.session),this.log(`[manager] session ${s} running on ${e.session.innerHost}:${e.session.innerPort} (yaml=${y.basename(n)})`)})();e.readyPromise=t;try{await t}catch(i){throw e.session.status="ended",e.session.exitInfo=i.message,this.notifyStateChange(e.session),i}}async stopSandbox(s){let e=this.sessions.get(s);if(e&&e.session.status!=="idle"&&e.session.status!=="ended"){this.log(`[manager] stopSandbox ${s}`),e.livenessTimer&&(clearInterval(e.livenessTimer),e.livenessTimer=void 0);try{await e.cleanup()}catch(n){this.log(`[manager] stopSandbox ${s} cleanup error: ${n.message}`)}e.session.innerPort=0,e.session.innerHost="127.0.0.1",e.session.pid=0,e.session.status="idle",e.session.exitInfo=null,e.cleanup=async()=>{},e.readyPromise=Promise.resolve(),this.notifyStateChange(e.session)}}startLivenessProbe(s,e){let t=0,i=setInterval(()=>{let o=this.sessions.get(s);if(!o||o.session.status==="ended"){clearInterval(i);return}let d=!1;try{process.kill(o.session.pid,0),d=!0}catch(a){a?.code!=="ESRCH"&&(d=!0)}d?t=0:(t+=1,t>=3&&(clearInterval(i),e("process-exited")))},3e3);return i.unref(),i}async closeSession(s){let e=this.sessions.get(s);if(e){this.log(`[manager] closeSession ${s} (status=${e.session.status})`),this.sessions.delete(s),this.byYamlPath.get(e.session.yamlPath)===s&&this.byYamlPath.delete(e.session.yamlPath),e.livenessTimer&&(clearInterval(e.livenessTimer),e.livenessTimer=void 0),e.session.status!=="ended"&&(e.session.status="ended",e.session.exitInfo="SIGTERM",this.notifyStateChange(e.session));try{await e.cleanup()}catch(n){this.log(`[manager] closeSession ${s} cleanup error: ${n.message}`)}}}async restartInner(s){let e=this.sessions.get(s);if(!e)throw new Error(`No session ${s} to restart`);if(e.restartInProgress)throw new Error(`Restart already in progress for session ${s}`);let n=e.session.yamlPath,r=$(y.dirname(n));if(!r)throw new Error(`No Playwright config found for ${n} (searched parents for playwright.config.{ts,js,mjs}).`);e.restartInProgress=!0;try{e.livenessTimer&&(clearInterval(e.livenessTimer),e.livenessTimer=void 0);try{await e.cleanup()}catch(a){this.log(`[manager] restartInner ${s} old cleanup error: ${a.message}`)}e.session.status="starting",e.session.innerPort=0,e.session.pid=0,this.notifyStateChange(e.session);let t=H+18e4,i,o=new Promise((a,c)=>{i=setTimeout(()=>c(new Error(`Timed out after ${t/1e3}s waiting for inner playwright to respawn.`)),t)}),d;try{d=await Promise.race([this.spawner({yamlFilePath:n,configPath:r,tempSuffix:s,headed:this.headed}),o])}catch(a){throw e.session.status="ended",e.session.exitInfo=a.message,this.notifyStateChange(e.session),a}finally{i&&clearTimeout(i)}e.session.innerPort=d.port,e.session.innerHost=d.host,e.session.pid=d.pid,e.session.status="running",e.cleanup=d.cleanup,e.livenessTimer=this.startLivenessProbe(s,a=>{e.session.status!=="ended"&&(e.session.status="ended",e.session.exitInfo=a,this.notifyStateChange(e.session))}),this.notifyStateChange(e.session),this.log(`[manager] session ${s} restarted on ${e.session.innerHost}:${e.session.innerPort} (yaml=${y.basename(n)})`)}finally{e.restartInProgress=!1}}listSessions(){return Array.from(this.sessions.values()).map(s=>({...s.session}))}getSession(s){let e=this.sessions.get(s);return e?{...e.session}:void 0}httpProxyFor(s,e={}){let{liveviewUrlBuilder:n}=e;return async(r,t,i)=>{let o=this.sessions.get(s);if(!o){t.status(404).json({status:"error",message:"Session not found"});return}if(o.session.status==="ended"){t.status(410).json({status:"error",message:"Session has ended",exitInfo:o.session.exitInfo});return}if(o.session.status==="idle"){t.status(503).json({status:"error",message:"Sandbox not started"});return}let d=`${r.method} ${r.path}`;if(d==="POST /api/int-runner/create-session"){let c=await C(r),p={};if(c.length)try{p=JSON.parse(c.toString("utf-8"))}catch{t.status(400).json({status:"error",message:"Invalid JSON body"});return}p.testFilePath=o.session.yamlPath,await _(r,t,o.session.innerHost,o.session.innerPort,Buffer.from(JSON.stringify(p),"utf-8"),"application/json");return}if(d==="POST /api/int-runner/terminate-session"){try{await this.stopSandbox(s),t.json({status:"success",details:"Sandbox stopped"})}catch(c){t.status(500).json({status:"error",message:c.message})}return}if(d==="POST /api/int-runner/liveview-url"){let c=n?.(r)??"";t.json({liveviewUrl:c,browserWsUrl:""});return}let a=await C(r);await _(r,t,o.session.innerHost,o.session.innerPort,a,r.headers["content-type"])}}wsUpgradeFor(s){return async(e,n,r,t)=>{let i=this.sessions.get(s);if(!i){T(n,`HTTP/1.1 404 Not Found\r
|
|
26
26
|
\r
|
|
27
|
-
`);return}if(
|
|
27
|
+
`);return}if(i.session.status==="ended"){T(n,`HTTP/1.1 410 Gone\r
|
|
28
28
|
\r
|
|
29
|
-
`);return}try{let
|
|
29
|
+
`);return}try{let o=i.session.innerHost.includes(":")?`[${i.session.innerHost}]`:i.session.innerHost,d=await fetch(`http://${o}:${i.session.innerPort}/api/browser-cdp`);if(!d.ok)throw new Error(`Inner /api/browser-cdp returned ${d.status}`);let{cdpUrl:a}=await d.json(),c=new URL(a.replace(/^ws/,"http")),p=parseInt(c.port||"80",10),h=c.hostname,v=c.pathname;t&&t.startsWith("/page/")&&(v=`/devtools${t}`);let g=j.createConnection(p,h);g.on("connect",()=>{let f=`GET ${v} HTTP/1.1\r
|
|
30
30
|
Host: ${h}:${p}\r
|
|
31
|
-
`;for(let[x,b]of Object.entries(e.headers)){let
|
|
31
|
+
`;for(let[x,b]of Object.entries(e.headers)){let P=x.toLowerCase();P!=="host"&&P!=="origin"&&(f+=`${x}: ${Array.isArray(b)?b.join(", "):b}\r
|
|
32
32
|
`)}f+=`\r
|
|
33
|
-
`,
|
|
33
|
+
`,g.write(f),r.length&&g.write(r),g.pipe(n),n.pipe(g)}),g.on("error",()=>{(!("destroyed"in n)||!n.destroyed)&&n.destroy()}),n.on("error",()=>{g.destroyed||g.destroy()}),n.on("close",()=>{g.destroyed||g.destroy()})}catch(o){this.log(`[manager] WS upgrade for ${s} failed: ${o.message}`),T(n,`HTTP/1.1 502 Bad Gateway\r
|
|
34
34
|
\r
|
|
35
|
-
`)}}}async shutdown(){let s=Array.from(this.sessions.keys());await Promise.allSettled(s.map(e=>this.closeSession(e)))}};function
|
|
35
|
+
`)}}}async shutdown(){let s=Array.from(this.sessions.keys());await Promise.allSettled(s.map(e=>this.closeSession(e)))}};function C(l){return new Promise((s,e)=>{if(l.body&&typeof l.body=="object")try{s(Buffer.from(JSON.stringify(l.body),"utf-8"));return}catch{}if(l.readableEnded){s(Buffer.alloc(0));return}let n=[];l.on("data",r=>n.push(r)),l.on("end",()=>s(Buffer.concat(n))),l.on("error",e)})}function _(l,s,e,n,r,t){return new Promise(i=>{let o=Array.isArray(t)?t[0]:t,d=N.request({hostname:e,port:n,path:l.originalUrl,method:l.method,headers:{"content-type":o||"application/json","content-length":String(r.length)},timeout:3e5},a=>{s.writeHead(a.statusCode??502,a.headers),a.on("data",c=>s.write(c)),a.on("end",()=>{s.end(),i()}),a.on("error",()=>{s.writableEnded||s.end(),i()})});d.on("error",a=>{s.headersSent?s.writableEnded||s.end():s.status(502).json({status:"error",message:"Inner server unavailable: "+a.message}),i()}),d.end(r)})}function T(l,s){try{(!("destroyed"in l)||!l.destroyed)&&(l.write(s),l.destroy())}catch{}}export{E as DebuggerManager};
|