@pluswithai/cli 0.2.1 → 0.3.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/README.md +28 -6
- package/dist/args.js +10 -0
- package/dist/client.js +7 -2
- package/dist/config.js +3 -2
- package/dist/main.js +2 -0
- package/dist/report.js +14 -4
- package/dist/run.js +2 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ Details: https://pluswithai.com/app?project=shop
|
|
|
28
28
|
|
|
29
29
|
## GitHub Actions
|
|
30
30
|
|
|
31
|
-
Store the key as the repository secret `PLUSWITHAI_API_KEY
|
|
31
|
+
Store the key as the repository secret `PLUSWITHAI_API_KEY` and use the action:
|
|
32
32
|
|
|
33
33
|
```yaml
|
|
34
34
|
name: Pluswithai tests
|
|
@@ -38,14 +38,34 @@ jobs:
|
|
|
38
38
|
e2e:
|
|
39
39
|
runs-on: ubuntu-latest
|
|
40
40
|
steps:
|
|
41
|
-
- uses:
|
|
41
|
+
- uses: pluswithai/cli@v0
|
|
42
42
|
with:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
PLUSWITHAI_API_KEY: ${{ secrets.PLUSWITHAI_API_KEY }}
|
|
43
|
+
api-key: ${{ secrets.PLUSWITHAI_API_KEY }}
|
|
44
|
+
project: shop
|
|
45
|
+
environment: staging # optional; default is production (the project URL)
|
|
47
46
|
```
|
|
48
47
|
|
|
48
|
+
To test every pull request's **preview deploy** (Vercel, Netlify, Cloudflare Pages)
|
|
49
|
+
and block the merge when a test fails:
|
|
50
|
+
|
|
51
|
+
```yaml
|
|
52
|
+
on: deployment_status
|
|
53
|
+
jobs:
|
|
54
|
+
e2e:
|
|
55
|
+
if: github.event.deployment_status.state == 'success'
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
steps:
|
|
58
|
+
- uses: pluswithai/cli@v0
|
|
59
|
+
with:
|
|
60
|
+
api-key: ${{ secrets.PLUSWITHAI_API_KEY }}
|
|
61
|
+
project: shop
|
|
62
|
+
base-url: ${{ github.event.deployment_status.environment_url }}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The preview's host must match a preview host pattern declared in the project's
|
|
66
|
+
Settings, e.g. `myapp-*.vercel.app`. See
|
|
67
|
+
[Environments and PR checks](https://pluswithai.com/docs/environments-and-pr-checks).
|
|
68
|
+
|
|
49
69
|
Inside GitHub Actions, the CLI also:
|
|
50
70
|
|
|
51
71
|
- writes a table of the results to the job's summary page (turn it off with `--no-summary`);
|
|
@@ -91,6 +111,8 @@ Use a key with **Agent** access to get every tool. Logs go to stderr; stdout car
|
|
|
91
111
|
| `-p, --project <name>` | — | Required |
|
|
92
112
|
| `-t, --test <file>` | every test file | Repeat it to run several files |
|
|
93
113
|
| `--region <id>` | the project's region | Where the browser runs |
|
|
114
|
+
| `-e, --env <name>` | production | An environment from the project's Settings, e.g. `staging` |
|
|
115
|
+
| `--base-url <url>` | — | A preview deploy to test; its host must match a declared preview host |
|
|
94
116
|
| `--timeout <seconds>` | 1800 | Stop waiting after this long, counted from when the runs start |
|
|
95
117
|
| `--interval <seconds>` | 5 | Time between status checks |
|
|
96
118
|
| `--junit <path>` | — | Also write a JUnit XML report |
|
package/dist/args.js
CHANGED
|
@@ -25,6 +25,8 @@ const OPTIONS = {
|
|
|
25
25
|
...PROJECT,
|
|
26
26
|
test: { type: "string", short: "t", multiple: true },
|
|
27
27
|
region: { type: "string" },
|
|
28
|
+
env: { type: "string", short: "e" },
|
|
29
|
+
"base-url": { type: "string" },
|
|
28
30
|
timeout: { type: "string" },
|
|
29
31
|
interval: { type: "string" },
|
|
30
32
|
junit: { type: "string" },
|
|
@@ -87,12 +89,17 @@ export function parseCommand(argv) {
|
|
|
87
89
|
};
|
|
88
90
|
switch (topic) {
|
|
89
91
|
case "run":
|
|
92
|
+
if (values.env !== undefined && values["base-url"] !== undefined) {
|
|
93
|
+
throw new UsageError("Pass either --env or --base-url, not both.", topic);
|
|
94
|
+
}
|
|
90
95
|
return {
|
|
91
96
|
kind: "run",
|
|
92
97
|
global,
|
|
93
98
|
project: needProject(),
|
|
94
99
|
tests: values.test ?? [],
|
|
95
100
|
region: values.region,
|
|
101
|
+
environment: values.env,
|
|
102
|
+
baseUrl: values["base-url"],
|
|
96
103
|
timeoutSec: seconds(values.timeout, 1800, "--timeout", topic),
|
|
97
104
|
intervalSec: seconds(values.interval, 5, "--interval", topic),
|
|
98
105
|
junit: values.junit,
|
|
@@ -131,6 +138,9 @@ Options:
|
|
|
131
138
|
-p, --project <name> Project to run (required)
|
|
132
139
|
-t, --test <file> Test file to run; repeat for several (default: every test file)
|
|
133
140
|
--region <id> Run region (default: the project's)
|
|
141
|
+
-e, --env <name> Environment from the project's Settings, e.g. staging (default: production)
|
|
142
|
+
--base-url <url> Preview deploy to test, e.g. a pull request's Vercel URL (its host must
|
|
143
|
+
match a preview host declared in the project's Settings)
|
|
134
144
|
--timeout <seconds> Give up waiting after this long (default 1800)
|
|
135
145
|
--interval <seconds> Time between status checks (default 5)
|
|
136
146
|
--junit <path> Also write a JUnit XML report
|
package/dist/client.js
CHANGED
|
@@ -44,8 +44,13 @@ export class Client {
|
|
|
44
44
|
const path = `/projects/${encodeURIComponent(project)}/runs/${encodeURIComponent(id)}`;
|
|
45
45
|
return (await this.request("GET", path)).run;
|
|
46
46
|
}
|
|
47
|
-
async startRun(project, tests, region) {
|
|
48
|
-
const body =
|
|
47
|
+
async startRun(project, tests, region, target = {}) {
|
|
48
|
+
const body = {
|
|
49
|
+
tests,
|
|
50
|
+
...(region ? { region } : {}),
|
|
51
|
+
...(target.environment ? { environment: target.environment } : {}),
|
|
52
|
+
...(target.baseUrl ? { baseUrl: target.baseUrl } : {}),
|
|
53
|
+
};
|
|
49
54
|
return (await this.request("POST", `/projects/${encodeURIComponent(project)}/run-tests`, body)).results;
|
|
50
55
|
}
|
|
51
56
|
async request(method, path, body) {
|
package/dist/config.js
CHANGED
|
@@ -28,8 +28,9 @@ export function resolveConfig(flags, env) {
|
|
|
28
28
|
}
|
|
29
29
|
return {
|
|
30
30
|
apiKey,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// `||`, not `??`: a blank variable (an unset CI input) means "default".
|
|
32
|
+
apiUrl: httpUrl(flags.apiUrl ?? (env.PLUSWITHAI_API_URL || DEFAULT_API_URL), "--api-url"),
|
|
33
|
+
appUrl: httpUrl(flags.appUrl ?? (env.PLUSWITHAI_APP_URL || DEFAULT_APP_URL), "--app-url"),
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
/** Removes the key — and anything shaped like a Pluswithai key — from text about to be printed. */
|
package/dist/main.js
CHANGED
|
@@ -115,6 +115,8 @@ async function runCommand(deps, config, client, command) {
|
|
|
115
115
|
project: command.project,
|
|
116
116
|
tests: command.tests,
|
|
117
117
|
region: command.region,
|
|
118
|
+
environment: command.environment,
|
|
119
|
+
baseUrl: command.baseUrl,
|
|
118
120
|
timeoutMs: command.timeoutSec * 1000,
|
|
119
121
|
intervalMs: command.intervalSec * 1000,
|
|
120
122
|
});
|
package/dist/report.js
CHANGED
|
@@ -26,8 +26,15 @@ function countsLine(outcome) {
|
|
|
26
26
|
return [`${c.passed} passed`, c.failed ? `${c.failed} failed` : "", c.error ? `${c.error} error` : ""].filter(Boolean).join(", ");
|
|
27
27
|
}
|
|
28
28
|
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
29
|
+
/** The environment the runs targeted, when it was not the project URL. */
|
|
30
|
+
function targetOf(outcome) {
|
|
31
|
+
const r = [...outcome.results, ...outcome.pending].find((x) => x.environment && x.baseUrl);
|
|
32
|
+
return r ? { environment: r.environment, baseUrl: r.baseUrl } : null;
|
|
33
|
+
}
|
|
29
34
|
export function summaryText(outcome, project, appUrl) {
|
|
30
|
-
const
|
|
35
|
+
const target = targetOf(outcome);
|
|
36
|
+
const where = target ? ` (${target.environment}: ${target.baseUrl})` : "";
|
|
37
|
+
const lines = [`Pluswithai · ${project}${where}: ${countsLine(outcome)}`];
|
|
31
38
|
for (const r of outcome.results)
|
|
32
39
|
if (r.status !== "passed")
|
|
33
40
|
lines.push(` ${progressLine(r)}`);
|
|
@@ -47,10 +54,11 @@ export function markdownSummary(outcome, project, appUrl) {
|
|
|
47
54
|
...outcome.results.map((r) => `| \`${mdCell(fileOf(r))}\` | ${MD_STATUS[r.status]} | ${formatDuration(r.duration)} |`),
|
|
48
55
|
...outcome.pending.map((r) => `| \`${mdCell(fileOf(r))}\` | ⏱️ still running | — |`),
|
|
49
56
|
];
|
|
57
|
+
const target = targetOf(outcome);
|
|
50
58
|
return [
|
|
51
|
-
`### ${icon} Pluswithai · ${project}`,
|
|
59
|
+
`### ${icon} Pluswithai · ${project}${target ? ` · ${target.environment}` : ""}`,
|
|
52
60
|
"",
|
|
53
|
-
countsLine(outcome),
|
|
61
|
+
countsLine(outcome) + (target ? `. Ran against ${target.baseUrl}` : ""),
|
|
54
62
|
"",
|
|
55
63
|
"| Test | Status | Duration |",
|
|
56
64
|
"|---|---|---|",
|
|
@@ -112,7 +120,7 @@ export function junitXml(outcome, project) {
|
|
|
112
120
|
return [
|
|
113
121
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
114
122
|
"<testsuites>",
|
|
115
|
-
`<testsuite name="${xml(`Pluswithai · ${project}`)}" tests="${outcome.results.length + c.pending}" failures="${c.failed}" errors="${c.error}" skipped="${c.pending}" time="${secs(total)}">`,
|
|
123
|
+
`<testsuite name="${xml(`Pluswithai · ${project}${targetOf(outcome) ? ` · ${targetOf(outcome).environment}` : ""}`)}" tests="${outcome.results.length + c.pending}" failures="${c.failed}" errors="${c.error}" skipped="${c.pending}" time="${secs(total)}">`,
|
|
116
124
|
...cases,
|
|
117
125
|
"</testsuite>",
|
|
118
126
|
"</testsuites>",
|
|
@@ -127,6 +135,8 @@ export function runJson(outcome, project, appUrl) {
|
|
|
127
135
|
passed: outcome.exitCode === 0,
|
|
128
136
|
exitCode: outcome.exitCode,
|
|
129
137
|
timedOut: outcome.timedOut,
|
|
138
|
+
environment: targetOf(outcome)?.environment ?? "production",
|
|
139
|
+
baseUrl: targetOf(outcome)?.baseUrl ?? null,
|
|
130
140
|
counts: counts(outcome),
|
|
131
141
|
results: outcome.results.map((r) => ({
|
|
132
142
|
id: r.id,
|
package/dist/run.js
CHANGED
|
@@ -25,7 +25,8 @@ export function exitCodeFor(results, timedOut) {
|
|
|
25
25
|
async function start(deps, opts, tests) {
|
|
26
26
|
for (let attempt = 0;; attempt++) {
|
|
27
27
|
try {
|
|
28
|
-
|
|
28
|
+
const target = opts.environment ? { environment: opts.environment } : opts.baseUrl ? { baseUrl: opts.baseUrl } : {};
|
|
29
|
+
return await deps.client.startRun(opts.project, tests, opts.region, target);
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
31
32
|
if (!(e instanceof ApiError) || e.status !== 429 || attempt >= MAX_START_RETRIES)
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Kept equal to package.json's version by test/node-deps.test.ts. */
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.3.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluswithai/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Run Pluswithai tests from CI and the terminal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@types/node": "^20.19.43",
|
|
45
45
|
"@vitest/coverage-v8": "^4.1.11",
|
|
46
46
|
"typescript": "^5.9.3",
|
|
47
|
-
"vitest": "^4.1.11"
|
|
47
|
+
"vitest": "^4.1.11",
|
|
48
|
+
"yaml": "^2.9.1"
|
|
48
49
|
}
|
|
49
50
|
}
|