@smoothdeploy/mainsail 0.1.0-beta.2

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.md ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) SmoothDeploy. All rights reserved.
2
+
3
+ Use of this software is subject to the SmoothDeploy Terms of Service: https://smoothdeploy.com/legal/terms-of-service/
package/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # mainsail
2
+
3
+ Run your Playwright tests on SmoothDeploy from a terminal or a CI job. `mainsail test` packs the project, uploads it, starts a run, waits for the result and prints a summary with links to the run and the report.
4
+
5
+ Node 22 or newer. No runtime dependencies.
6
+
7
+ ## Install and run
8
+
9
+ ```bash
10
+ npm install -D @smoothdeploy/mainsail
11
+ export SMOOTHDEPLOY_API_KEY=sd_...
12
+ export SMOOTHDEPLOY_PROJECT_ID=3f8a1b2c-...
13
+ npx mainsail test
14
+ ```
15
+
16
+ Run it in the directory that holds `playwright.config.*`. In a monorepo, run it in the test package: the CLI walks up to the lockfile, packs from there and tells the runner where the tests are.
17
+
18
+ Create the API key under **Operations → API Keys** with the **Test Runs** `create` and `read` scopes. To find the project ID, call `GET /v1/actions/projects.list?lightweight=true` with a key that has the **Projects** `read` scope.
19
+
20
+ ## Environment
21
+
22
+ | Variable | Meaning |
23
+ |---|---|
24
+ | `SMOOTHDEPLOY_API_KEY` | API key (required). Never printed: any occurrence in output is replaced by `***`. |
25
+ | `SMOOTHDEPLOY_PROJECT_ID` | UUID of the project (required). |
26
+ | `SMOOTHDEPLOY_API_URL` | API base URL. Default `https://api.smoothdeploy.com`. |
27
+ | `SMOOTHDEPLOY_COMMIT_SHA` | Commit to record on the run. Overrides detection. 7 to 64 hex characters. |
28
+ | `SMOOTHDEPLOY_BRANCH` | Branch to record on the run. Overrides detection. |
29
+ | `SMOOTHDEPLOY_CI_URL` | Link to the CI job. Overrides detection. `http` or `https`. |
30
+ | `NO_COLOR` | Turns off colors. |
31
+
32
+ ## Options
33
+
34
+ | Option | Meaning |
35
+ |---|---|
36
+ | `--size <size>` | Runner size: `micro` (1 worker, default), `small` (2), `medium` (4), `large` (8). |
37
+ | `--timeout <time>` | Stop waiting after this long, for example `45m` or `2h`. Default `2h`. The run continues. |
38
+ | `--json` | Print the finished run (the `runs.get` payload) as JSON on stdout. Progress goes to stderr. |
39
+ | `-h`, `--help` | Show help. |
40
+ | `-v`, `--version` | Show the version. |
41
+
42
+ ## Secrets
43
+
44
+ Every secret belongs to one project. Runs of a project receive all of its secrets automatically as environment variables, and no other project's runs see them. A secret that several projects need is set once in each.
45
+
46
+ ```bash
47
+ npx mainsail secret set DB_PASSWORD
48
+ printf %s "$VALUE" | npx mainsail secret set DB_PASSWORD
49
+ ```
50
+
51
+ `secret set` saves a secret. The value is encrypted on this machine before upload: the CLI fetches a public key (`secrets.public-key`), encrypts the value with AES-256-GCM under a fresh key, wraps that key with RSA-OAEP-SHA256 and sends only the result (`secrets.set`). The encryption is bound to the name and the project. On a terminal the value is read from a hidden prompt; otherwise all of stdin is read and one trailing newline is dropped. The value is never read from a flag, an environment variable or a config file. The secret is saved in the `SMOOTHDEPLOY_PROJECT_ID` project, and an existing name in that project is replaced. The API key needs the **Test Runs** `create` scope; a key restricted to a project can set secrets of that project only. Names the runner relies on are reserved (`PATH`, `HOME`, `CI`, `NODE_*`, `PLAYWRIGHT_*`, `LD_*` and others) and are refused.
52
+
53
+ ## Exit codes
54
+
55
+ | Code | Meaning |
56
+ |---|---|
57
+ | `0` | All tests passed. Flaky tests count as passed. |
58
+ | `1` | Tests failed. |
59
+ | `2` | Could not run: usage, configuration, upload or API error, the run failed before its tests, it was cancelled, the timeout passed or the connection was lost. |
60
+ | `130` | Interrupted with Ctrl+C. The run continues on SmoothDeploy. |
61
+
62
+ Ctrl+C stops waiting and prints the run link. It does not cancel the run. Cancel it in the app if you need to.
63
+
64
+ ## What is uploaded
65
+
66
+ The archive root is the directory that holds the lockfile (`package-lock.json`, `pnpm-lock.yaml`, `yarn.lock` or `bun.lock`), found by walking up from the current directory to the Git root.
67
+
68
+ - In a Git repository: every file Git would include, which is tracked files plus untracked files that are not ignored (`git ls-files --cached --others --exclude-standard`). Tracked files deleted from disk are skipped.
69
+ - Outside Git: every file, minus what the `.gitignore` files at each level ignore.
70
+ - Never uploaded, at any depth, even when tracked: `node_modules`, `.git`, `.env`, and every `.env.*` file, `.env.example` included. A secret pasted into an example file must not leak, so there are no exceptions. Load test configuration from secrets or CI variables instead.
71
+ - Symbolic links that stay inside the project are kept as links. Links that point outside the project or use absolute paths are skipped and reported.
72
+ - The archive must be 250 MB or less. Over that, the CLI names the biggest directories and files and uploads nothing.
73
+
74
+ The Playwright version comes from the `@playwright/test` entry in the lockfile. `bun.lockb` is not supported: run `bun install --save-text-lockfile` to get a `bun.lock`. `npm-shrinkwrap.json` is not supported.
75
+
76
+ ## Commit, branch and CI link
77
+
78
+ Detected in this order: the `SMOOTHDEPLOY_*` overrides, then the CI provider, then `git` in the current directory.
79
+
80
+ | Provider | Detected by | Commit | Branch | Job link |
81
+ |---|---|---|---|---|
82
+ | GitHub Actions | `GITHUB_ACTIONS` | `pull_request.head.sha` from `GITHUB_EVENT_PATH`, else `GITHUB_SHA` | `GITHUB_HEAD_REF`, else `GITHUB_REF_NAME` | `GITHUB_SERVER_URL/GITHUB_REPOSITORY/actions/runs/GITHUB_RUN_ID` |
83
+ | GitLab CI | `GITLAB_CI` | `CI_COMMIT_SHA` | `CI_MERGE_REQUEST_SOURCE_BRANCH_NAME`, else `CI_COMMIT_REF_NAME` | `CI_JOB_URL` |
84
+ | CircleCI | `CIRCLECI` | `CIRCLE_SHA1` | `CIRCLE_BRANCH` | `CIRCLE_BUILD_URL` |
85
+ | Bitbucket Pipelines | `BITBUCKET_BUILD_NUMBER` | `BITBUCKET_COMMIT` | `BITBUCKET_BRANCH` | `https://bitbucket.org/BITBUCKET_REPO_FULL_NAME/pipelines/results/BITBUCKET_BUILD_NUMBER` |
86
+ | Azure Pipelines | `TF_BUILD` | `BUILD_SOURCEVERSION` | `SYSTEM_PULLREQUEST_SOURCEBRANCH`, else `BUILD_SOURCEBRANCH` (only `refs/heads/...`) | `SYSTEM_COLLECTIONURI` + `SYSTEM_TEAMPROJECT` + `/_build/results?buildId=BUILD_BUILDID` |
87
+ | Jenkins | `JENKINS_URL` | `GIT_COMMIT` | `CHANGE_BRANCH`, else `BRANCH_NAME`, else `GIT_BRANCH` without `origin/` | `BUILD_URL` |
88
+ | Buildkite | `BUILDKITE` | `BUILDKITE_COMMIT` | `BUILDKITE_BRANCH` | `BUILDKITE_BUILD_URL` |
89
+
90
+ Values the API would reject (a commit that is not hex, a link that is not `http` or `https`) are dropped. An invalid override prints a warning.
91
+
92
+ ## CI examples
93
+
94
+ GitHub Actions:
95
+
96
+ ```yaml
97
+ e2e:
98
+ runs-on: ubuntu-latest
99
+ steps:
100
+ - uses: actions/checkout@v4
101
+ - uses: actions/setup-node@v4
102
+ with:
103
+ node-version: 22
104
+ - run: npm ci
105
+ - run: npx mainsail test
106
+ env:
107
+ SMOOTHDEPLOY_API_KEY: ${{ secrets.SMOOTHDEPLOY_API_KEY }}
108
+ SMOOTHDEPLOY_PROJECT_ID: ${{ vars.SMOOTHDEPLOY_PROJECT_ID }}
109
+ ```
110
+
111
+ GitLab CI (store both variables under **Settings → CI/CD → Variables**, the key masked):
112
+
113
+ ```yaml
114
+ e2e:
115
+ image: node:22
116
+ script:
117
+ - npm ci
118
+ - npx mainsail test
119
+ ```
120
+
121
+ The HTTP calls behind the CLI are documented in the [Run API reference](https://docs.smoothdeploy.com/api-reference/test-runs).
122
+
123
+ The summary prints the report link. It is a signed link: anyone who can read the CI log can open the report until the link expires. Keep that in mind for public CI logs.
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ pnpm --filter @smoothdeploy/mainsail build
129
+ pnpm --filter @smoothdeploy/mainsail test
130
+ bash scripts/cli-pack-check.sh
131
+ ```
132
+
133
+ `cli-pack-check.sh` packs the CLI, installs the tarball in an empty directory and runs it.
134
+
135
+ ## Release
136
+
137
+ The CLI has its own version, changelog and tag. On `master`:
138
+
139
+ ```bash
140
+ pnpm cli bump
141
+ git push --follow-tags origin master
142
+ ```
143
+
144
+ `bump` bumps the version from the commits that touch `apps/mainsail`, writes `CHANGELOG.md` and creates the tag `mainsail-v<version>`. The tag starts the `Release CLI` workflow, which publishes to npm through trusted publishing. No npm token is stored.
145
+
146
+ The version decides the npm channel:
147
+
148
+ | Command | Version | Channel | Install |
149
+ |---|---|---|---|
150
+ | `pnpm cli bump` | `0.2.0` | `latest` | `npm install -D @smoothdeploy/mainsail` |
151
+ | `pnpm cli bump --prerelease beta` | `0.2.0-beta.0` | `beta` | `npm install -D @smoothdeploy/mainsail@beta` |
152
+ | `pnpm cli bump --prerelease alpha` | `0.2.0-alpha.0` | `next` | `npm install -D @smoothdeploy/mainsail@next` |
package/dist/cli.js ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ import{spawn as $t,spawnSync as Rt}from"node:child_process";import{mkdtempSync as It,readFileSync as bt,readdirSync as Pt,rmSync as Ae}from"node:fs";import{readFile as Ut}from"node:fs/promises";import{hostname as Ct,tmpdir as kt}from"node:os";import R from"node:path";import{parseArgs as Lt}from"node:util";import{createReadStream as Ye}from"node:fs";import ze from"node:http";import Je from"node:https";var w=class extends Error{constructor(n,r,s,o){super(s);this.status=n;this.code=r;this.details=o}status;code;details};function C(e,t,n,r){let s={...t&&{"x-api-key":t},...n&&{"x-project-id":n}};async function o(i,c){let a=new URL(`/v1/actions/${i}`,e);for(let[h,f]of Object.entries(c.query??{}))a.searchParams.set(h,f);let l;try{l=await fetch(a,{method:c.method,headers:{...s,"content-type":"application/json",accept:"application/json","user-agent":r},body:c.body?JSON.stringify(c.body):void 0,signal:AbortSignal.timeout(3e4)})}catch(h){let f=h;throw new w(0,"network_error",`Could not reach ${a.origin}: ${f.cause?.message??f.message}`)}let p=await l.text(),u={};try{u=JSON.parse(p)}catch{if(l.ok)throw new w(l.status,"bad_response",`${a.origin} answered with something that is not JSON. Check SMOOTHDEPLOY_API_URL.`)}if(!l.ok)throw new w(l.status,u.errorCode??`http_${l.status}`,u.error??`HTTP ${l.status}`,u.details);return u.data}return{post:(i,c)=>o(i,{method:"POST",body:c}),get:(i,c)=>o(i,{method:"GET",query:c})}}function se(e,t,n,r,s){return new Promise((o,i)=>{let c=new URL(e),a=(c.protocol==="https:"?Je:ze).request(c,{method:"PUT",headers:t,timeout:12e4},u=>{let h="";u.setEncoding("utf8"),u.on("data",f=>h+=f.slice(0,4096)),u.on("end",()=>{if(u.statusCode&&u.statusCode<300)return o();let f=u.statusCode===403&&/expired/i.test(h);i(new w(u.statusCode??0,f?"upload_expired":"upload_failed",f?"The upload link expired":`The storage server answered HTTP ${u.statusCode}`))})});a.on("timeout",()=>a.destroy(new Error("no response for 2 minutes"))),a.on("error",u=>i(new w(0,"upload_failed",u.message)));let l=0,p=Ye(n);p.on("data",u=>{l+=u.length,s(Math.min(l,r))}),p.on("error",u=>a.destroy(u)),p.pipe(a)})}import{execFileSync as Ke}from"node:child_process";import{readFileSync as Fe}from"node:fs";var oe=e=>e?.startsWith("refs/heads/")?e.slice(11):void 0;function Ge(e){if(!(!e.GITHUB_EVENT_NAME?.startsWith("pull_request")||!e.GITHUB_EVENT_PATH))try{return JSON.parse(Fe(e.GITHUB_EVENT_PATH,"utf8")).pull_request?.head?.sha}catch{return}}var Ve=[{name:"GitHub Actions",detect:"GITHUB_ACTIONS",read:e=>({commitSha:Ge(e)??e.GITHUB_SHA,branch:e.GITHUB_HEAD_REF||e.GITHUB_REF_NAME,ciUrl:e.GITHUB_SERVER_URL&&e.GITHUB_REPOSITORY&&e.GITHUB_RUN_ID?`${e.GITHUB_SERVER_URL}/${e.GITHUB_REPOSITORY}/actions/runs/${e.GITHUB_RUN_ID}`:void 0})},{name:"GitLab CI",detect:"GITLAB_CI",read:e=>({commitSha:e.CI_COMMIT_SHA,branch:e.CI_MERGE_REQUEST_SOURCE_BRANCH_NAME||e.CI_COMMIT_REF_NAME,ciUrl:e.CI_JOB_URL})},{name:"CircleCI",detect:"CIRCLECI",read:e=>({commitSha:e.CIRCLE_SHA1,branch:e.CIRCLE_BRANCH,ciUrl:e.CIRCLE_BUILD_URL})},{name:"Bitbucket Pipelines",detect:"BITBUCKET_BUILD_NUMBER",read:e=>({commitSha:e.BITBUCKET_COMMIT,branch:e.BITBUCKET_BRANCH,ciUrl:e.BITBUCKET_REPO_FULL_NAME?`https://bitbucket.org/${e.BITBUCKET_REPO_FULL_NAME}/pipelines/results/${e.BITBUCKET_BUILD_NUMBER}`:void 0})},{name:"Azure Pipelines",detect:"TF_BUILD",read:e=>({commitSha:e.BUILD_SOURCEVERSION,branch:oe(e.SYSTEM_PULLREQUEST_SOURCEBRANCH)??oe(e.BUILD_SOURCEBRANCH),ciUrl:e.SYSTEM_COLLECTIONURI&&e.SYSTEM_TEAMPROJECT&&e.BUILD_BUILDID?`${e.SYSTEM_COLLECTIONURI.replace(/\/?$/,"/")}${encodeURIComponent(e.SYSTEM_TEAMPROJECT)}/_build/results?buildId=${e.BUILD_BUILDID}`:void 0})},{name:"Jenkins",detect:"JENKINS_URL",read:e=>({commitSha:e.GIT_COMMIT,branch:e.CHANGE_BRANCH||e.BRANCH_NAME||e.GIT_BRANCH?.replace(/^origin\//,""),ciUrl:e.BUILD_URL})},{name:"Buildkite",detect:"BUILDKITE",read:e=>({commitSha:e.BUILDKITE_COMMIT,branch:e.BUILDKITE_BRANCH,ciUrl:e.BUILDKITE_BUILD_URL})}];function ae(e,t){try{return Ke("git",t,{cwd:e,encoding:"utf8",stdio:["ignore","pipe","ignore"],windowsHide:!0}).trim()||void 0}catch{return}}var K=e=>e&&/^[0-9a-f]{7,64}$/i.test(e)?e:void 0,F=e=>e&&e.length<=255?e:void 0,ce=e=>e&&e.length<=2048&&URL.canParse(e)&&/^https?:$/.test(new URL(e).protocol)?e:void 0;function le(e,t,n){let r=Ve.find(i=>e[i.detect]),s=r?.read(e)??{},o=(i,c,a)=>{if(c)return a(c)||n(`Ignoring ${i}: "${c}" is not valid.`),a(c)};return{provider:r?.name,commitSha:o("SMOOTHDEPLOY_COMMIT_SHA",e.SMOOTHDEPLOY_COMMIT_SHA,K)??K(s.commitSha)??K(ae(t,["rev-parse","HEAD"])),branch:o("SMOOTHDEPLOY_BRANCH",e.SMOOTHDEPLOY_BRANCH,F)??F(s.branch)??F(ae(t,["symbolic-ref","--short","-q","HEAD"])),ciUrl:o("SMOOTHDEPLOY_CI_URL",e.SMOOTHDEPLOY_CI_URL,ce)??ce(s.ciUrl)}}import{chmodSync as We,mkdirSync as qe,readFileSync as Xe,rmSync as de,writeFileSync as Qe}from"node:fs";import{homedir as Ze}from"node:os";import G from"node:path";function k(e){let t=process.platform==="win32"&&e.APPDATA?e.APPDATA:e.XDG_CONFIG_HOME||G.join(Ze(),".config");return G.join(t,"mainsail","credentials.json")}function V(e){let t;try{t=JSON.parse(Xe(k(e),"utf8"))}catch{return null}return!t?.apiUrl||!t.token?null:{apiUrl:t.apiUrl,token:t.token}}function ue(e,t){let n=k(e);return qe(G.dirname(n),{recursive:!0,mode:448}),de(n,{force:!0}),Qe(n,`${JSON.stringify(t)}
3
+ `,{mode:384,flag:"wx"}),We(n,384),n}function W(e){de(k(e),{force:!0})}import{promises as et}from"node:fs";import q from"node:path";var pe=["package-lock.json","pnpm-lock.yaml","yarn.lock","bun.lock","bun.lockb"],S=class extends Error{};async function fe(e,t){for(let n=e;;n=q.dirname(n)){let r=new Set(await et.readdir(n)),s=pe.find(o=>r.has(o));if(s)return{dir:n,name:s};if(r.has("npm-shrinkwrap.json"))throw new S(`npm-shrinkwrap.json is not supported. Use package-lock.json instead (${q.join(n,"npm-shrinkwrap.json")}).`);if(n===t||q.dirname(n)===n)throw new S(`No lockfile found in ${e} or its parent directories. Commit one of ${pe.slice(0,4).join(", ")} by running your package manager's install.`)}}var T="@playwright/test",X=e=>[...new Set(e)];function tt(e,t){let n=JSON.parse(e),s=(t==="."?void 0:n.packages?.[`${t}/node_modules/${T}`]?.version)??n.packages?.[`node_modules/${T}`]?.version??n.dependencies?.[T]?.version;return s?[s]:[]}function nt(e,t){let n=e.split(/\r?\n/),r=X(n.flatMap(o=>o.match(/^\s+'?\/?@playwright\/test[@/](\d[^:'(\s]*)/)?.[1]??[]));if(r.length<=1)return r;let s=n.findIndex(o=>o===` ${t}:`||o===` '${t}':`);if(s===-1)return r;for(let o=s+1;o<n.length&&/^\s{3,}|^$/.test(n[o]);o++){if(!/^\s+'?@playwright\/test'?:/.test(n[o]))continue;let i=n[o].match(/:\s*(\d[^\s(]*)/)?.[1],c=n.slice(o+1,o+3).join(`
4
+ `).match(/version:\s*(\d[^\s(]*)/)?.[1],a=i??c;if(a)return[a]}return r}function rt(e){let t=[],n=!1;for(let r of e.split(/\r?\n/)){/^\s/.test(r)||(n=r.includes(`${T}@`));let s=n&&r.match(/^\s+version:?\s+"?([^"\s]+)"?/)?.[1];s&&t.push(s)}return X(t)}var it=e=>X([...e.matchAll(/"@playwright\/test@(\d[^"]*)"/g)].map(t=>t[1]));function ge(e,t,n){if(e==="bun.lockb")throw new S("bun.lockb is binary and cannot be read. Run `bun install --save-text-lockfile` to create bun.lock, commit it, and run again.");let r=e==="package-lock.json"?tt(t,n):e==="pnpm-lock.yaml"?nt(t,n):e==="yarn.lock"?rt(t):it(t);if(r.length===0)throw new S(`${e} has no ${T}. Add it with your package manager, for example \`npm install -D ${T}\`.`);if(r.length>1)throw new S(`${e} has several ${T} versions (${r.join(", ")}). Use one version across the project.`);let[s]=r;if(!/^\d+\.\d+\.\d+$/.test(s))throw new S(`${T} ${s} is a pre-release. Use a released version.`);return s}var he=[];function O(e){e&&he.push(e)}var L=e=>he.reduce((t,n)=>t.replaceAll(n,"***"),e);function v(e,t){let n=e?process.stderr:process.stdout,r=!!n.isTTY&&!t.NO_COLOR&&t.TERM!=="dumb",s=!!n.isTTY&&!t.CI,o=!1,i=a=>l=>r?`\x1B[${a}m${l}\x1B[0m`:l,c=()=>{o&&n.write("\r\x1B[2K"),o=!1};return{live:s,green:i(32),red:i(31),yellow:i(33),dim:i(2),bold:i(1),line(a=""){c(),n.write(`${L(a)}
5
+ `)},status(a){if(!s)return void n.write(`${L(a)}
6
+ `);n.write(`\r\x1B[2K${L(a)}`),o=!0},error(a){c(),process.stderr.write(`${L(a)}
7
+ `)},json(a){process.stdout.write(`${L(JSON.stringify(a,null,2))}
8
+ `)},done:c}}import{execFile as ct}from"node:child_process";import{createWriteStream as lt,promises as D}from"node:fs";import $ from"node:path";import{Readable as dt}from"node:stream";import{pipeline as ut}from"node:stream/promises";import{promisify as pt}from"node:util";import{createGzip as ft}from"node:zlib";function st(e){let t="";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*"&&e[n+1]==="*"){let s=n===0||e[n-1]==="/",o=n+2===e.length||e[n+2]==="/";if(s&&o){t+=n+2===e.length?".*":"(?:.*/)?",n+=2;continue}}if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="\\"&&n+1<e.length)t+=`\\${e[++n]}`;else if(r==="["){let s=e.indexOf("]",n+2);if(s===-1)t+="\\[";else{let o=e.slice(n+1,s).replace(/^!/,"^").replace(/\\/g,"\\\\");t+=`[${o}]`,n=s}}else t+=r.replace(/[.+^${}()|\]\\]/g,"\\$&")}return t}function me(e){let t=[];for(let n of e.split(/\r?\n/)){let r=n.replace(/(?<!\\)\s+$/,"");if(!r||r.startsWith("#"))continue;let s=r.startsWith("!");s&&(r=r.slice(1)),(r.startsWith("\\#")||r.startsWith("\\!"))&&(r=r.slice(1));let o=r.endsWith("/");o&&(r=r.slice(0,-1));let i=r.includes("/");r.startsWith("/")&&(r=r.slice(1)),r&&t.push({regex:new RegExp(`${i?"^":"(?:^|/)"}${st(r)}$`),negate:s,dirOnly:o})}return t}function we(e,t,n){let r;for(let s of e)s.dirOnly&&!n||s.regex.test(t)&&(r=!s.negate);return r}import{createReadStream as ot}from"node:fs";var A=512;function b(e,t){return e.toString(8).padStart(t-1,"0")+"\0"}function ye(e,t){let n=` ${e}=${t}
9
+ `,r=Buffer.byteLength(n);for(;String(r).length+Buffer.byteLength(n)!==r;)r=String(r).length+Buffer.byteLength(n);return`${r}${n}`}function Q(e,t,n,r,s,o=""){let i=Buffer.alloc(A);i.write(e,0,100,"utf8"),i.write(b(n,8),100,"ascii"),i.write(b(0,8),108,"ascii"),i.write(b(0,8),116,"ascii"),i.write(b(t,12),124,"ascii"),i.write(b(r,12),136,"ascii"),i.fill(" ",148,156),i.write(s,156,"ascii"),i.write(o,157,100,"utf8"),i.write("ustar\0",257,"ascii"),i.write("00",263,"ascii");let c=0;for(let a of i)c+=a;return i.write(b(c,7)+" ",148,"ascii"),i}var Se=e=>Buffer.byteLength(e)<=100&&/^[\x20-\x7e]*$/.test(e),_e=e=>Buffer.alloc((A-e%A)%A);function*at(e){let t="linkTarget"in e?e.linkTarget:"";if(!Se(e.name)||!Se(t)){let r=Buffer.from(ye("path",e.name)+(t?ye("linkpath",t):""));yield Q("PaxHeader",r.length,420,e.mtime,"x"),yield r,yield _e(r.length)}let n=e.name.slice(0,100);"linkTarget"in e?yield Q(n,0,511,e.mtime,"2",t.slice(0,100)):yield Q(n,e.size,e.mode,e.mtime,"0")}async function*Te(e){for(let t of e){if(yield*at(t),"linkTarget"in t)continue;let n=0;for await(let r of ot(t.source)){if(n+=r.length,n>t.size)break;yield r}if(n!==t.size)throw new Error(`${t.name} changed while it was being packed. Run again.`);yield _e(t.size)}yield Buffer.alloc(A*2)}var Z=250*1024**2,gt=pt(ct),Ee=e=>e.split("/").some(t=>t==="node_modules"||t===".git"||t===".env"||t.startsWith(".env."));async function ht(e){let n=await gt("git",["ls-files","-z","--cached","--others","--exclude-standard"],{cwd:e,maxBuffer:1073741824,windowsHide:!0}).catch(()=>null);return n?[...new Set(n.stdout.split("\0").filter(Boolean))]:null}function mt(e,t,n){let r=!1;for(let{base:s,rules:o}of e){let i=we(o,s?t.slice(s.length+1):t,n);i!==void 0&&(r=i)}return r}async function Oe(e,t="",n=[]){let r=await D.readdir($.join(e,t),{withFileTypes:!0}),o=r.find(c=>c.name===".gitignore"&&c.isFile())?[...n,{base:t,rules:me(await D.readFile($.join(e,t,".gitignore"),"utf8"))}]:n,i=[];for(let c of r){let a=t?`${t}/${c.name}`:c.name;Ee(a)||mt(o,a,c.isDirectory())||(c.isDirectory()?i.push(...await Oe(e,a,o)):i.push(a))}return i}var wt=(e,t)=>{let n=$.posix.normalize($.posix.join($.posix.dirname(e),t));return $.posix.isAbsolute(t)||/^[a-zA-Z]:/.test(t)||n===".."||n.startsWith("../")};async function $e(e){let t=await ht(e),n=(t??await Oe(e)).filter(i=>!Ee(i)).sort(),r=[],s=[],o=0;for(let i of n){let c=$.join(e,i),a=await D.lstat(c).catch(()=>null);if(!a)continue;let l=Math.floor(a.mtimeMs/1e3);if(a.isSymbolicLink()){let p=(await D.readlink(c)).replaceAll("\\","/");wt(i,p)?s.push(i):r.push({name:i,linkTarget:p,mtime:l});continue}a.isFile()&&(r.push({name:i,source:c,size:a.size,mode:a.mode&73?493:420,mtime:l}),o+=a.size)}return{entries:r,bytes:o,git:t!==null,skippedLinks:s}}async function Re(e,t){return await ut(dt.from(Te(e)),ft(),lt(t)),(await D.stat(t)).size}function Ie(e,t=5){let n=new Map,r=[];for(let o of e){if(!("size"in o))continue;r.push([o.name,o.size]);let i=o.name.indexOf("/");i>0&&n.set(o.name.slice(0,i+1),(n.get(o.name.slice(0,i+1))??0)+o.size)}let s=o=>o.sort((i,c)=>c[1]-i[1]).slice(0,t);return{dirs:s([...n]),files:s(r)}}import{constants as yt,createCipheriv as St,publicEncrypt as _t,randomBytes as be}from"node:crypto";var Tt=(e,t)=>Buffer.from(`smoothdeploy-secret/v1\0${e}\0${t}`,"utf8");function Pe(e,t,n,r){let s=be(32),o=be(12);try{let i=St("aes-256-gcm",s,o,{authTagLength:16});i.setAAD(Tt(t,n));let c=Buffer.concat([i.update(r,"utf8"),i.final()]);return{encryptedKey:_t({key:e,padding:yt.RSA_PKCS1_OAEP_PADDING,oaepHash:"sha256"},s).toString("base64"),iv:o.toString("base64"),ciphertext:c.toString("base64"),tag:i.getAuthTag().toString("base64")}}finally{s.fill(0)}}function H(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}var Et=e=>`${[e.file,...e.describePath,e.title].filter(Boolean).join(" \u203A ")}${e.projectName?` [${e.projectName}]`:""}`;function Ue(e,t,n,r){if(n.length!==0){e.line(),e.line(e.bold(t));for(let s of n.slice(0,20)){e.line(` ${Et(s)}`);for(let o of r(s))e.line(e.dim(` ${o}`))}n.length>20&&e.line(` and ${n.length-20} more on the run page`)}}var Ot=e=>(e.error??"").split(/\r?\n/).filter(t=>t.trim()).slice(0,6);function Ce(e,t){let{passed:n,failed:r,flaky:s,skipped:o}=t.counts,i=[r&&e.red(`${r} failed`),`${n} passed`,s&&e.yellow(`${s} flaky`),o&&`${o} skipped`].filter(Boolean),c=t.durationMs?` in ${H(t.durationMs)}`:"";Ue(e,"Failed tests",t.tests.filter(a=>a.status==="failed"),Ot),Ue(e,"Flaky tests (passed on retry)",t.tests.filter(a=>a.status==="flaky"),a=>[`passed after ${a.retries} ${a.retries===1?"retry":"retries"}`]),t.testsTruncated&&(e.line(),e.line(`Only the first ${t.tests.length} test results are listed. See the run page for all of them.`)),e.line(),t.status==="completed"?e.line(`${e.green(e.bold("Passed"))} ${i.join(", ")}${c}`):t.status==="cancelled"?e.line(`${e.yellow(e.bold("Cancelled"))} The run was cancelled before it finished.`):t.failureReason?e.line(`${e.red(e.bold("Could not run the tests"))} ${t.failureReason}`):e.line(`${e.red(e.bold("Failed"))} ${i.join(", ")}${c}`),t.reportUrl&&e.line(`Report ${t.reportUrl}`),e.line(`Run ${t.url}`)}var te=JSON.parse(bt(new URL("../package.json",import.meta.url),"utf8")),g="mainsail",Y=`${g}/${te.version}`,m={passed:0,failed:1,error:2,interrupted:130},ke={micro:1,small:2,medium:4,large:8},ne="https://api.smoothdeploy.com",At=[".ts",".js",".mts",".mjs",".cts",".cjs"].map(e=>`playwright.config${e}`),Dt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,De=6,B=`${g} ${te.version}: run your Playwright tests on SmoothDeploy.
10
+
11
+ Usage
12
+ ${g} login
13
+ ${g} test [options]
14
+ ${g} secret set <NAME>
15
+
16
+ Commands
17
+ login Sign in from a browser. Prints a code and a link, opens the browser
18
+ when it can, and saves a credential for one organization on this
19
+ machine. Over SSH, open the link on any device.
20
+ logout Revoke the saved credential and delete it from this machine
21
+ whoami Print the signed-in user and organization
22
+ test Run the Playwright project in this directory: pack it, upload it,
23
+ start a run, wait for the result and print a summary. Run it in the
24
+ directory that holds playwright.config.*
25
+ secret set <NAME> Save a secret. The value is encrypted on this machine before upload.
26
+ See ${g} secret --help
27
+
28
+ Runs receive the project's secrets automatically.
29
+
30
+ Options for test
31
+ --size <size> Runner size: micro (1 worker, default), small (2), medium (4), large (8)
32
+ --timeout <time> Stop waiting after this long, e.g. 45m or 2h (default 2h); the run continues
33
+ --json Print the finished run as JSON on stdout; progress goes to stderr
34
+ -h, --help Show this help
35
+ -v, --version Show the version
36
+
37
+ Environment
38
+ SMOOTHDEPLOY_API_KEY API key with the Test Runs create and read scopes. When it is set,
39
+ it is used instead of the ${g} login credential
40
+ SMOOTHDEPLOY_PROJECT_ID UUID of the SmoothDeploy project (required for test and secret set)
41
+ SMOOTHDEPLOY_API_URL API base URL (default ${ne})
42
+ SMOOTHDEPLOY_COMMIT_SHA, SMOOTHDEPLOY_BRANCH, SMOOTHDEPLOY_CI_URL
43
+ Override the detected commit, branch and CI job link
44
+
45
+ Exit codes
46
+ 0 All tests passed (flaky tests count as passed)
47
+ 1 Tests failed
48
+ 2 Could not run: usage, configuration, upload or API error, the run failed
49
+ before its tests, it was cancelled, the timeout passed or the connection was lost
50
+ 130 Interrupted; the run continues
51
+ `,ee=`Usage
52
+ ${g} secret set <NAME>
53
+
54
+ Save a secret for the runs of the SMOOTHDEPLOY_PROJECT_ID project. If a secret
55
+ with this name exists, its value is replaced.
56
+
57
+ The value is encrypted on this machine before upload: ${g} fetches a public key
58
+ from SmoothDeploy, encrypts the value with it and sends only the ciphertext. The
59
+ encryption is bound to the secret name and the project.
60
+
61
+ Secrets belong to one project. Runs receive the project's secrets automatically
62
+ as environment variables, and no other project sees them. A secret that several
63
+ projects need is set once per project.
64
+
65
+ The value is never read from a flag, an environment variable or a config file:
66
+ On a terminal type it at the hidden prompt
67
+ From a pipe ${g} reads all of stdin and drops one trailing newline,
68
+ for example: ${g} secret set DB_PASSWORD < password.txt
69
+
70
+ NAME has letters, digits and underscores only, at most 64 characters. Names the
71
+ runner relies on are reserved: PATH, HOME, CI, NODE_*, PLAYWRIGHT_*, LD_* and others.
72
+
73
+ Environment
74
+ SMOOTHDEPLOY_API_KEY API key with the Test Runs create scope, or sign in with ${g} login
75
+ SMOOTHDEPLOY_PROJECT_ID UUID of the SmoothDeploy project (required)
76
+ SMOOTHDEPLOY_API_URL API base URL (default ${ne})
77
+
78
+ Exit codes
79
+ 0 The secret was saved
80
+ 2 Nothing was saved
81
+ `,d=class extends Error{},E=e=>e<1024**2?`${Math.ceil(e/1024)} KB`:`${(e/1024**2).toFixed(1)} MB`,j=e=>new Promise(t=>setTimeout(t,e));function xt(e){let t=/^(\d+(?:\.\d+)?)(s|m|h)?$/.exec(e.trim());if(!t)throw new d(`--timeout "${e}" is not a duration. Use for example 30m, 2h or 90s.`);let n=t[2]==="s"?1e3:t[2]==="h"?36e5:6e4;return Number(t[1])*n}var Mt=new Map([["invalid_api_key","Check SMOOTHDEPLOY_API_KEY: the key is wrong, deleted or expired."],["unauthorized",`Check SMOOTHDEPLOY_API_KEY, or run ${g} login again.`],["api_key_forbidden","This credential cannot do that."],["ip_not_allowed","The API key does not allow requests from this IP address. Edit its allowed IPs under Operations > API Keys."],["api_key_wrong_project","The API key is restricted to another project. Check SMOOTHDEPLOY_PROJECT_ID or use another key."],["project_not_found","Check SMOOTHDEPLOY_PROJECT_ID: no project with this id exists in the key's organization."],["LICENSE_REQUIRED","The organization has no active subscription. See Organization > Billing in the app."],["runner_size_unavailable","Try another --size."],["parallel_limit_exceeded","Pick a smaller --size or raise the organization's parallels."],["queue_full","Too many runs are waiting. Try again when some have started."],["too_many_requests","Too many runs were created in the last minutes. Wait a little and run again."],["test_run_not_found","The run is not in the SMOOTHDEPLOY_PROJECT_ID project."],["run_already_started","The run was already started and continues."],["archive_missing","The uploaded archive did not arrive. Run again."]]);function z(e,t){if(e.code==="playwright_version_unsupported"){let r=e.details?.versions??[];return`${e.message}. Supported versions: ${r.join(", ")||"none listed"}. Install one of them, for example \`npm install -D @playwright/test@${r.at(-1)??"<version>"}\`, and commit the lockfile.`}if(e.code==="minutes_exhausted"||e.code==="payment_failed")return`${e.message} Nothing ran.`;if(e.code==="run_not_startable")return`${t} failed: the run is ${e.details?.status??"finished"} and can no longer be started. Run again.`;if(e.code==="archive_too_large")return`${t} failed: the archive is over the ${E(e.details?.max??Z)} limit.`;if(e.status===0)return`${t} failed: ${e.message}. Check your network and SMOOTHDEPLOY_API_URL.`;let n=Mt.get(e.code);return`${t} failed: ${e.message} (${e.code}, HTTP ${e.status}).${n?` ${n}`:""}`}async function I(e,t){try{return await t()}catch(n){throw n instanceof w?new d(z(n,e)):n}}async function Nt(e,t,n,r){let s=-1,o=i=>{let c=Math.floor(i/r*100);!e.live||c===s||(s=c,e.status(`Uploading ${c}% (${E(i)} of ${E(r)})`))};e.live||e.line(`Uploading ${E(r)}`);for(let i=1;;i++)try{await se(t.uploadUrl,t.uploadHeaders,n,r,o),e.line(`Uploaded ${E(r)}`);return}catch(c){let a=c;if(a.code==="upload_expired")throw new d("Upload failed: the upload link expired (it is valid for 15 minutes). Run again.");if(!(a.status===0||a.status>=500)||i>=3)throw new d(`Upload failed: ${a.message}. Nothing ran. Check your network and run again.`);e.line(`Upload failed (${a.message}), retrying`),await j(1e3*i)}}var vt=new Map([["created","Waiting to start"],["pending","Waiting for a free parallel"],["queued","Starting a runner"],["running","Running tests"]]);async function Ht(e,t,n,r,s,o){let i=Date.now(),c="",a=0,l=()=>e.status(`${c} ${e.dim(H(Date.now()-i))}`),p=e.live?setInterval(()=>c&&l(),1e3):void 0;try{for(;;){let u;try{u=await t.get("runs.get",{runId:n}),a=0}catch(f){let y=f;if(!(y instanceof w&&(y.status===0||y.status===429||y.status>=500)))throw f instanceof w?new d(z(y,"Reading the run")):f;if(a++,a>=De)throw new d(`Lost the connection to SmoothDeploy (${y.message}). The run continues: ${r}`);e.line(`Could not read the run (${y.message}), retrying`),await j(Math.min(o*2**(a-1),6e4));continue}if(u.terminal)return u;let h=vt.get(u.status)??u.status;if(h!==c&&(c=h,e.live?l():e.line(`${H(Date.now()-i)} ${c}`)),Date.now()+o>s)throw new d(`Stopped waiting after the --timeout. The run is still going: ${r}`);await j(o)}}finally{clearInterval(p),e.done()}}function xe(e){let t=e.SMOOTHDEPLOY_API_URL?.trim()||ne;if(!URL.canParse(t))throw new d(`SMOOTHDEPLOY_API_URL "${t}" is not a URL.`);return new URL(t).origin}function Me(e,t){let n=xe(e),r=e.SMOOTHDEPLOY_API_KEY?.trim();if(r)return O(r),{apiUrl:n,apiKey:r};let s=V(e);if(!s)throw new d(`Not signed in. Run ${g} login, or create an API key with the ${t} under Operations > API Keys in SmoothDeploy and set SMOOTHDEPLOY_API_KEY.`);if(O(s.token),s.apiUrl!==n)throw new d(`Signed in to ${s.apiUrl}, not ${n}. Run ${g} login again.`);return{apiUrl:n,apiKey:s.token}}function Ne(e,t){let{apiUrl:n,apiKey:r}=Me(e,t),s=e.SMOOTHDEPLOY_PROJECT_ID?.trim();if(!s)throw new d("SMOOTHDEPLOY_PROJECT_ID is not set. Set it to the UUID of the SmoothDeploy project the runs belong to.");if(!Dt.test(s))throw new d(`SMOOTHDEPLOY_PROJECT_ID "${s}" is not a project UUID.`);return{projectId:s,client:C(n,r,s,Y)}}function Bt(e,t){if(e.SSH_CONNECTION||e.SSH_TTY||!process.stdout.isTTY)return!1;let[n,r]=process.platform==="darwin"?["open",[t]]:process.platform==="win32"?["rundll32",["url.dll,FileProtocolHandler",t]]:["xdg-open",[t]];try{let s=$t(n,r,{stdio:"ignore",detached:!0,windowsHide:!0});return s.on("error",()=>{}),s.unref(),!0}catch{return!1}}async function jt(e,t,n){let r=Number(n.SMOOTHDEPLOY_POLL_INTERVAL_MS)||t.interval*1e3,s=Date.now()+t.expiresIn*1e3,o=0;for(;;){if(await j(r),Date.now()>s)throw new d(`The code expired. Run ${g} login again.`);try{let i=await e.post("cli-sessions.token",{deviceCode:t.deviceCode});return O(i.token),i}catch(i){if(!(i instanceof w))throw i;if(i.code==="cli_login_pending")continue;if(i.code==="cli_login_slow_down"){r+=5e3;continue}if(i.code==="cli_login_denied")throw new d("The sign-in was denied in the browser. Nothing was saved.");if(i.code==="cli_login_expired")throw new d(`The code expired. Run ${g} login again.`);if(!(i.status===0||i.status===429||i.status>=500)||++o>=De)throw new d(z(i,"Signing in"))}}}async function Yt(e,t){let n=xe(t),r=C(n,void 0,void 0,Y),s=Ct().replace(/[^\x20-\x7e]/g,"").trim().slice(0,64)||"unknown",o=await I("Starting the sign-in",()=>r.post("cli-sessions.start",{machineName:s}));O(o.deviceCode);let i=URL.canParse(o.verificationUriComplete)?new URL(o.verificationUriComplete):null;if(!i||!["https:","http:"].includes(i.protocol))throw new d("Starting the sign-in failed: the server sent no valid link.");e.line(`Code: ${o.userCode.replace(/^(.{4})(.+)$/,"$1-$2")}`),e.line(`Open ${i.href} and approve the sign-in for ${s}. Check that the page shows this code.`),Bt(t,i.href)&&e.line("Opened the browser."),e.line("Waiting for approval...");let c=await jt(r,o,t),a=ue(t,{apiUrl:n,token:c.token});return e.line(`Signed in as ${c.email} to ${c.organization}. Saved the credential to ${a}.`),t.SMOOTHDEPLOY_API_KEY?.trim()&&e.line("SMOOTHDEPLOY_API_KEY is set and is used instead of this credential while it is set."),m.passed}async function zt(e,t){let n=V(t);if(!n)return W(t),e.line("Not signed in."),m.passed;O(n.token);let r=C(n.apiUrl,n.token,void 0,Y);try{await r.post("cli-sessions.logout",{})}catch(s){if(!(s instanceof w&&(s.status===401||s.status===404)))throw s instanceof w?new d(`${z(s,"Signing out")} The credential is kept in ${k(t)}.`):s}return W(t),e.line("Signed out. The credential is revoked and deleted from this machine."),m.passed}async function Jt(e,t){if(t.SMOOTHDEPLOY_API_KEY?.trim())return e.line("Using the API key in SMOOTHDEPLOY_API_KEY. An API key belongs to an organization, not to a user."),m.passed;let{apiUrl:n,apiKey:r}=Me(t,"Test Runs create and read scopes"),s=C(n,r,void 0,Y),o=await I("Reading the sign-in",()=>s.get("cli-sessions.whoami",{}));return e.line(`Signed in as ${o.email} to ${o.organization} on ${o.machineName}.`),m.passed}var Le={login:Yt,logout:zt,whoami:Jt};async function Kt(e,t,n,r){let s=t.size??"micro";if(!(s in ke))throw new d(`--size "${s}" is not a runner size. Use one of ${Object.keys(ke).join(", ")}.`);let o=Date.now()+xt(t.timeout??"2h"),{projectId:i,client:c}=Ne(n,"Test Runs create and read scopes"),a=process.cwd();if(!At.some(_=>Pt(a).includes(_)))throw new d(`No playwright.config.{ts,js,mts,mjs,cts,cjs} in ${a}. Run ${g} test in the directory of your Playwright project.`);let l=le(n,a,_=>e.error(_)),p=Rt("git",["rev-parse","--show-toplevel"],{cwd:a,encoding:"utf8",windowsHide:!0}).stdout?.trim(),u=p?R.resolve(p):R.parse(a).root,h=await fe(a,u),f=R.relative(h.dir,a).split(R.sep).join("/")||".",y=ge(h.name,await Ut(R.join(h.dir,h.name),"utf8"),f),x=It(R.join(kt(),`${g}-`));r.tmp=x;try{let _=await $e(h.dir);for(let N of _.skippedLinks)e.error(`Skipped ${N}: the link points outside ${h.dir}`);let re=R.join(x,"project.tgz"),P=await Re(_.entries,re),ve=f==="."?"":`, tests in ${f}`;if(e.line(`Packed ${_.entries.length} files from ${h.dir} (${E(P)}${ve}), Playwright ${y}`),P>Z){let N=Ie(_.entries),He=[...N.dirs,...N.files].map(([Be,je])=>` ${E(je).padStart(9)} ${Be}`);throw new d(`The archive is ${E(P)}, over the 250 MB limit. Biggest directories and files:
82
+ ${He.join(`
83
+ `)}
84
+ Add large files that the tests do not need to .gitignore and run again.`)}let ie=[l.branch,l.commitSha?.slice(0,7),l.provider].filter(Boolean).join(" \xB7 ");ie&&e.line(e.dim(ie));let M=await I("Creating the run",()=>c.post("runs.create",{projectId:i,playwrightVersion:y,size:s,archiveBytes:P,directory:f==="."?void 0:f,commitSha:l.commitSha,branch:l.branch,ciUrl:l.ciUrl})),J=await I("Reading the run",()=>c.get("runs.get",{runId:M.id}));r.url=J.url,e.line(`Run ${J.url}`),await Nt(e,M,re,P),await I("Starting the run",()=>c.post("runs.start",{runId:M.id})),r.started=!0;let U=await Ht(e,c,M.id,J.url,o,Number(n.SMOOTHDEPLOY_POLL_INTERVAL_MS)||1e4);return Ce(e,U),t.json&&e.json(U),U.status==="completed"?m.passed:U.status==="failed"&&!U.failureReason?m.failed:m.error}finally{Ae(x,{recursive:!0,force:!0})}}async function Ft(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf8").replace(/\r?\n$/,"")}function Gt(e){let t=process.stdin;return new Promise((n,r)=>{let s="",o=c=>{t.off("data",i),t.setRawMode(!1),t.pause(),process.stderr.write(`
85
+ `),c?r(c):n(s)},i=c=>{for(let a of c){if(a==="\r"||a===`
86
+ `||a==="")return o();if(a==="")return o(new d("Stopped. Nothing was saved."));a==="\x7F"||a==="\b"?s=[...s].slice(0,-1).join(""):s+=a}};process.stderr.write(e),t.setEncoding("utf8"),t.setRawMode(!0),t.on("data",i),t.resume()})}async function Vt(e,t,n){if(!/^[A-Za-z0-9_]{1,64}$/.test(t))throw new d(`"${t}" is not a secret name. Use letters, digits and underscores, at most 64 characters.`);let{projectId:r,client:s}=Ne(n,"Test Runs create scope"),{publicKey:o}=await I("Reading the encryption key",()=>s.get("secrets.public-key",{})),i=process.stdin.isTTY?await Gt(`Value for ${t} (hidden): `):await Ft();if(!i)throw new d("The value is empty. Nothing was saved.");O(i);let c=await I("Saving the secret",()=>s.post("secrets.set",{projectId:r,name:t,...Pe(o,r,t,i)}));return e.line(`${c.created?"Created":"Updated"} secret ${t}. It was encrypted on this machine before upload. Runs of this project receive it automatically.`),m.passed}async function Wt(e,t){let n,r;try{({values:n,positionals:r}=Lt({args:e,allowPositionals:!0,options:{size:{type:"string"},timeout:{type:"string"},json:{type:"boolean"},help:{type:"boolean",short:"h"},version:{type:"boolean",short:"v"}}}))}catch(l){return process.stderr.write(`${l.message}
87
+
88
+ ${B}`),m.error}let s=r[0]==="secret"?ee:B;if(n.version||n.help)return process.stdout.write(n.version?`${te.version}
89
+ `:s),m.passed;let o=r.length===1&&Object.hasOwn(Le,r[0])?Le[r[0]]:null;if(o){let l=v(!1,t);try{return await o(l,t)}catch(p){return l.error(p instanceof d?p.message:`Unexpected error: ${p.message}`),m.error}}if(r[0]==="secret"){if(r[1]!=="set"||r.length!==3)return process.stderr.write(r.length>1?`Unknown command "${r.join(" ")}".
90
+
91
+ ${ee}`:ee),m.error;let l=v(!1,t);try{return await Vt(l,r[2],t)}catch(p){return l.error(p instanceof d?p.message:`Unexpected error: ${p.message}`),m.error}}if(r.length!==1||r[0]!=="test")return process.stderr.write(r.length?`Unknown command "${r.join(" ")}".
92
+
93
+ ${B}`:B),m.error;let i=v(!!n.json,t),c={},a=()=>{c.tmp&&Ae(c.tmp,{recursive:!0,force:!0}),i.done(),c.url?c.started?i.error(`Stopped waiting. The run continues: ${c.url}`):i.error(`Stopped. The run was not started: ${c.url}`):i.error("Stopped."),process.exit(m.interrupted)};process.once("SIGINT",a),process.once("SIGTERM",a);try{return await Kt(i,n,t,c)}catch(l){return l instanceof d||l instanceof S?i.error(l.message):i.error(`Unexpected error: ${l.message}`),m.error}}process.exitCode=await Wt(process.argv.slice(2),process.env);
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@smoothdeploy/mainsail",
3
+ "version": "0.1.0-beta.2",
4
+ "description": "Run your Playwright tests on SmoothDeploy remote runners, from a terminal or CI",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
+ "homepage": "https://smoothdeploy.com",
7
+ "type": "module",
8
+ "bin": {
9
+ "mainsail": "dist/cli.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "engines": {
15
+ "node": ">=22"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^24.3.0",
22
+ "commit-and-tag-version": "^12.4.4",
23
+ "esbuild": "^0.28.2",
24
+ "oxlint": "1.90.0",
25
+ "typescript": "7.0.2",
26
+ "vitest": "^5.1.0"
27
+ },
28
+ "scripts": {
29
+ "build": "rm -rf dist && esbuild src/cli.ts --bundle --minify --platform=node --format=esm --target=node22 --outfile=dist/cli.js",
30
+ "test": "pnpm build && vitest run",
31
+ "lint": "oxlint .",
32
+ "typecheck": "tsc",
33
+ "bump": "commit-and-tag-version"
34
+ }
35
+ }