@pluswithai/cli 0.2.1 → 0.4.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 CHANGED
@@ -9,7 +9,7 @@ It starts the runs, waits for them and exits non-zero when one fails.
9
9
 
10
10
  ## Quick start
11
11
 
12
- 1. In the app, open **API keys** in the sidebar, choose **Create key**, then pick **CI**.
12
+ 1. In the app, open **API keys** in the sidebar, choose **Create key**, then pick **CI / CLI**.
13
13
  2. Export the key, then run your project's tests:
14
14
 
15
15
  ```sh
@@ -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: actions/setup-node@v4
41
+ - uses: pluswithai/cli@v0
42
42
  with:
43
- node-version: 22
44
- - run: npx -y @pluswithai/cli run --project shop --junit reports/pluswithai.xml
45
- env:
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`);
@@ -55,7 +75,9 @@ Inside GitHub Actions, the CLI also:
55
75
 
56
76
  | Command | What it does |
57
77
  |---|---|
58
- | `pluswithai run --project <name>` | Start runs, wait for them, exit with their verdict |
78
+ | `pluswithai run --project <name>` | Start runs in the cloud, wait for them, exit with their verdict |
79
+ | `pluswithai local --project <name>` | Run the project's tests on this machine, e.g. against `localhost` |
80
+ | `pluswithai pull --project <name>` | Download the project's files to run them yourself |
59
81
  | `pluswithai projects` | List your projects |
60
82
  | `pluswithai tests --project <name>` | List a project's test files |
61
83
  | `pluswithai runs --project <name>` | Show recent runs (`--limit`, 1–100) |
@@ -64,6 +86,23 @@ Inside GitHub Actions, the CLI also:
64
86
 
65
87
  Every command takes `--help`, and every command except `mcp` takes `--json`.
66
88
 
89
+ ## Run tests on your machine
90
+
91
+ `pluswithai local` downloads the project's tests, installs Playwright the first
92
+ time and runs them here — useful against a local server before you deploy:
93
+
94
+ ```bash
95
+ pluswithai local --project shop --base-url http://localhost:3000
96
+ pluswithai local --project shop -t tests/checkout.spec.ts --headed
97
+ ```
98
+
99
+ The files go to `pluswithai/<project>` (`--dir` to change it): plain Playwright
100
+ plus the project's config and fixture, so `npx playwright test` works there on
101
+ its own too (`pluswithai pull` only downloads). The site's HTTP auth and extra
102
+ headers stay on Pluswithai: set `PLUSWITHAI_HTTP_USERNAME`,
103
+ `PLUSWITHAI_HTTP_PASSWORD` and `PLUSWITHAI_EXTRA_HEADERS` (a JSON object) when
104
+ the site needs them. Needs Node.js 18+.
105
+
67
106
  ## AI agents (MCP)
68
107
 
69
108
  Pluswithai is also an MCP server. With it, an agent like Claude Code, Cursor or Codex can run your tests, read the failures, push new tests and schedule them.
@@ -91,6 +130,8 @@ Use a key with **Agent** access to get every tool. Logs go to stderr; stdout car
91
130
  | `-p, --project <name>` | — | Required |
92
131
  | `-t, --test <file>` | every test file | Repeat it to run several files |
93
132
  | `--region <id>` | the project's region | Where the browser runs |
133
+ | `-e, --env <name>` | production | An environment from the project's Settings, e.g. `staging` |
134
+ | `--base-url <url>` | — | A preview deploy to test; its host must match a declared preview host |
94
135
  | `--timeout <seconds>` | 1800 | Stop waiting after this long, counted from when the runs start |
95
136
  | `--interval <seconds>` | 5 | Time between status checks |
96
137
  | `--junit <path>` | — | Also write a JUnit XML report |
package/dist/args.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * node:util parseArgs so the CLI keeps zero runtime dependencies.
4
4
  */
5
5
  import { parseArgs } from "node:util";
6
- const COMMANDS = ["run", "projects", "tests", "runs", "whoami", "mcp"];
6
+ const COMMANDS = ["run", "local", "pull", "projects", "tests", "runs", "whoami", "mcp"];
7
7
  export class UsageError extends Error {
8
8
  topic;
9
9
  constructor(message, topic) {
@@ -25,11 +25,23 @@ 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" },
31
33
  "no-summary": { type: "boolean" },
32
34
  },
35
+ local: {
36
+ ...GLOBAL,
37
+ ...PROJECT,
38
+ dir: { type: "string" },
39
+ test: { type: "string", short: "t", multiple: true },
40
+ "base-url": { type: "string" },
41
+ headed: { type: "boolean" },
42
+ "no-pull": { type: "boolean" },
43
+ },
44
+ pull: { ...GLOBAL, ...PROJECT, dir: { type: "string" } },
33
45
  projects: GLOBAL,
34
46
  tests: { ...GLOBAL, ...PROJECT },
35
47
  runs: { ...GLOBAL, ...PROJECT, limit: { type: "string" } },
@@ -87,18 +99,36 @@ export function parseCommand(argv) {
87
99
  };
88
100
  switch (topic) {
89
101
  case "run":
102
+ if (values.env !== undefined && values["base-url"] !== undefined) {
103
+ throw new UsageError("Pass either --env or --base-url, not both.", topic);
104
+ }
90
105
  return {
91
106
  kind: "run",
92
107
  global,
93
108
  project: needProject(),
94
109
  tests: values.test ?? [],
95
110
  region: values.region,
111
+ environment: values.env,
112
+ baseUrl: values["base-url"],
96
113
  timeoutSec: seconds(values.timeout, 1800, "--timeout", topic),
97
114
  intervalSec: seconds(values.interval, 5, "--interval", topic),
98
115
  junit: values.junit,
99
116
  json,
100
117
  summary: values["no-summary"] !== true,
101
118
  };
119
+ case "local":
120
+ return {
121
+ kind: "local",
122
+ global,
123
+ project: needProject(),
124
+ dir: values.dir,
125
+ tests: values.test ?? [],
126
+ baseUrl: values["base-url"],
127
+ headed: values.headed === true,
128
+ pull: values["no-pull"] !== true,
129
+ };
130
+ case "pull":
131
+ return { kind: "pull", global, project: needProject(), dir: values.dir, json };
102
132
  case "projects":
103
133
  return { kind: "projects", global, json };
104
134
  case "tests":
@@ -131,6 +161,9 @@ Options:
131
161
  -p, --project <name> Project to run (required)
132
162
  -t, --test <file> Test file to run; repeat for several (default: every test file)
133
163
  --region <id> Run region (default: the project's)
164
+ -e, --env <name> Environment from the project's Settings, e.g. staging (default: production)
165
+ --base-url <url> Preview deploy to test, e.g. a pull request's Vercel URL (its host must
166
+ match a preview host declared in the project's Settings)
134
167
  --timeout <seconds> Give up waiting after this long (default 1800)
135
168
  --interval <seconds> Time between status checks (default 5)
136
169
  --junit <path> Also write a JUnit XML report
@@ -142,6 +175,40 @@ Exit codes:
142
175
  0 every run passed 1 a run failed
143
176
  2 usage or configuration 3 Pluswithai or network error
144
177
  4 timed out waiting`,
178
+ local: `Usage: pluswithai local --project <name> [options]
179
+
180
+ Run a project's tests on this machine: pull its files, install Playwright the
181
+ first time, run "npx playwright test". Needs Node.js 18+.
182
+
183
+ Options:
184
+ -p, --project <name> Project (required)
185
+ --dir <path> Where the project's files go (default pluswithai/<project>)
186
+ -t, --test <file> Test file to run; repeat for several (default: every test)
187
+ --base-url <url> Test another address, e.g. http://localhost:3000
188
+ (sets PLUSWITHAI_BASE_URL, which the config reads)
189
+ --headed Show the browser
190
+ --no-pull Run what is already in --dir
191
+
192
+ Secrets the project's Settings hold (HTTP auth, extra headers) are not
193
+ downloaded: set PLUSWITHAI_HTTP_USERNAME, PLUSWITHAI_HTTP_PASSWORD and
194
+ PLUSWITHAI_EXTRA_HEADERS (a JSON object) when the site needs them.
195
+
196
+ ${GLOBAL_HELP}
197
+
198
+ Exit codes:
199
+ 0 Playwright passed 1 a test failed
200
+ 2 usage, configuration or local setup (npm, npx) 3 Pluswithai or network error`,
201
+ pull: `Usage: pluswithai pull --project <name> [--dir <path>] [--json]
202
+
203
+ Download a project's files (tests, Playwright config, fixtures) to run them
204
+ yourself: "npm install && npx playwright install chromium && npx playwright test".
205
+ Files the project no longer has are removed from the folder.
206
+
207
+ Options:
208
+ -p, --project <name> Project (required)
209
+ --dir <path> Destination (default pluswithai/<project>)
210
+
211
+ ${GLOBAL_HELP}`,
145
212
  projects: `Usage: pluswithai projects [--json]
146
213
 
147
214
  List the projects of the account.
@@ -188,7 +255,9 @@ export function helpText(topic) {
188
255
  Run Pluswithai tests from CI and the terminal.
189
256
 
190
257
  Commands:
191
- run Start runs, wait for the results, exit non-zero on failure
258
+ run Start runs in the cloud, wait for the results, exit non-zero on failure
259
+ local Run a project's tests on this machine (e.g. against localhost)
260
+ pull Download a project's files to run them yourself
192
261
  projects List your projects
193
262
  tests List a project's test files
194
263
  runs Show a project's recent runs
package/dist/client.js CHANGED
@@ -34,6 +34,10 @@ export class Client {
34
34
  async projects() {
35
35
  return (await this.request("GET", "/projects")).projects;
36
36
  }
37
+ /** The files HEAD tracks, portable (no container paths, no secrets). Pro: 402 otherwise. */
38
+ exportFiles(project) {
39
+ return this.request("GET", `/projects/${encodeURIComponent(project)}/export`);
40
+ }
37
41
  async testFiles(project) {
38
42
  return (await this.request("GET", `/projects/${encodeURIComponent(project)}/test-files`)).files;
39
43
  }
@@ -44,8 +48,13 @@ export class Client {
44
48
  const path = `/projects/${encodeURIComponent(project)}/runs/${encodeURIComponent(id)}`;
45
49
  return (await this.request("GET", path)).run;
46
50
  }
47
- async startRun(project, tests, region) {
48
- const body = region ? { tests, region } : { tests };
51
+ async startRun(project, tests, region, target = {}) {
52
+ const body = {
53
+ tests,
54
+ ...(region ? { region } : {}),
55
+ ...(target.environment ? { environment: target.environment } : {}),
56
+ ...(target.baseUrl ? { baseUrl: target.baseUrl } : {}),
57
+ };
49
58
  return (await this.request("POST", `/projects/${encodeURIComponent(project)}/run-tests`, body)).results;
50
59
  }
51
60
  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
- apiUrl: httpUrl(flags.apiUrl ?? env.PLUSWITHAI_API_URL ?? DEFAULT_API_URL, "--api-url"),
32
- appUrl: httpUrl(flags.appUrl ?? env.PLUSWITHAI_APP_URL ?? DEFAULT_APP_URL, "--app-url"),
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/local.js ADDED
@@ -0,0 +1,103 @@
1
+ /** Something on this machine is missing or failed to set up: exit code 2. */
2
+ export class LocalSetupError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "LocalSetupError";
6
+ }
7
+ }
8
+ /** Where the pulled file list is kept, so the next pull removes what the project dropped. */
9
+ export const MANIFEST = ".pluswithai/pulled.json";
10
+ export const defaultDir = (project) => `pluswithai/${project.replace(/[^\w.-]+/g, "-")}`;
11
+ const join = (dir, rel) => `${dir.replace(/\/+$/, "")}/${rel}`;
12
+ /** A path the API sent, as a safe path under the folder — or null (absolute, `..`, odd characters). */
13
+ export function safeRelativePath(path) {
14
+ const p = path.replace(/^\/+/, "");
15
+ if (!p || p.includes("\\") || p.includes("\0"))
16
+ return null;
17
+ const segments = p.split("/");
18
+ if (segments.some((s) => s === "" || s === "." || s === ".."))
19
+ return null;
20
+ return p;
21
+ }
22
+ function decodeBase64(b64) {
23
+ const binary = atob(b64);
24
+ const bytes = new Uint8Array(binary.length);
25
+ for (let i = 0; i < binary.length; i++)
26
+ bytes[i] = binary.charCodeAt(i);
27
+ return bytes;
28
+ }
29
+ async function readManifest(deps, dir) {
30
+ const text = await deps.readText(join(dir, MANIFEST));
31
+ if (!text)
32
+ return [];
33
+ try {
34
+ const list = JSON.parse(text);
35
+ return Array.isArray(list) ? list.filter((p) => typeof p === "string" && safeRelativePath(p) === p) : [];
36
+ }
37
+ catch {
38
+ return [];
39
+ }
40
+ }
41
+ export async function pullProject(deps, client, project, dir) {
42
+ const exported = await client.exportFiles(project);
43
+ const previous = await readManifest(deps, dir);
44
+ const written = [];
45
+ const skipped = [];
46
+ for (const f of exported.files) {
47
+ const rel = safeRelativePath(f.path);
48
+ if (!rel || rel === MANIFEST) {
49
+ skipped.push(f.path);
50
+ continue;
51
+ }
52
+ await deps.writeBytes(join(dir, rel), decodeBase64(f.base64));
53
+ written.push(rel);
54
+ }
55
+ const keep = new Set(written);
56
+ const stale = previous.filter((p) => !keep.has(p));
57
+ for (const p of stale)
58
+ await deps.remove(join(dir, p));
59
+ await deps.writeBytes(join(dir, MANIFEST), new TextEncoder().encode(JSON.stringify(written.sort(), null, 2) + "\n"));
60
+ return { dir, written: written.length, removed: stale.length, skipped, headOid: exported.headOid };
61
+ }
62
+ export function playwrightArgs(tests, headed) {
63
+ return ["playwright", "test", ...tests, ...(headed ? ["--headed"] : [])];
64
+ }
65
+ async function step(deps, label, command, args, cwd, env) {
66
+ deps.log(label);
67
+ let code;
68
+ try {
69
+ code = await deps.spawn(command, args, { cwd, env });
70
+ }
71
+ catch (e) {
72
+ throw new LocalSetupError(`Could not start ${command}: ${e instanceof Error ? e.message : String(e)}. Install Node.js 18 or later (it brings npm and npx).`);
73
+ }
74
+ if (code !== 0)
75
+ throw new LocalSetupError(`${command} ${args.join(" ")} exited with ${code}.`);
76
+ }
77
+ /**
78
+ * Pull (unless told not to), install once (npm install + Chromium), run
79
+ * `npx playwright test` with PLUSWITHAI_BASE_URL when a base URL is given.
80
+ * Resolves 0 when Playwright passes, 1 when it fails.
81
+ */
82
+ export async function testLocally(deps, client, opts) {
83
+ if (opts.pull) {
84
+ const pulled = await pullProject(deps, client, opts.project, opts.dir);
85
+ deps.log(`Pulled ${pulled.written} files into ${pulled.dir}${pulled.removed ? ` (removed ${pulled.removed})` : ""}.`);
86
+ }
87
+ else if (!(await deps.exists(join(opts.dir, "playwright.config.ts")))) {
88
+ throw new LocalSetupError(`${opts.dir} has no project yet. Run without --no-pull, or run "pluswithai pull" first.`);
89
+ }
90
+ if (!(await deps.exists(join(opts.dir, "node_modules")))) {
91
+ await step(deps, "Installing dependencies (first run)…", "npm", ["install", "--no-audit", "--no-fund"], opts.dir, opts.env);
92
+ await step(deps, "Installing Chromium for Playwright…", "npx", ["playwright", "install", "chromium"], opts.dir, opts.env);
93
+ }
94
+ const env = { ...opts.env, ...(opts.baseUrl ? { PLUSWITHAI_BASE_URL: opts.baseUrl } : {}) };
95
+ let code;
96
+ try {
97
+ code = await deps.spawn("npx", playwrightArgs(opts.tests, opts.headed), { cwd: opts.dir, env });
98
+ }
99
+ catch (e) {
100
+ throw new LocalSetupError(`Could not start npx: ${e instanceof Error ? e.message : String(e)}. Install Node.js 18 or later.`);
101
+ }
102
+ return code === 0 ? 0 : 1;
103
+ }
package/dist/main.js CHANGED
@@ -9,6 +9,7 @@ import { redact, resolveConfig } from "./config.js";
9
9
  import { annotations, junitXml, markdownSummary, progressLine, projectsText, runJson, runsText, startedLine, summaryText, testsText, whoamiText, } from "./report.js";
10
10
  import { executeRun, NoTestsError } from "./run.js";
11
11
  import { runMcpProxy } from "./mcp-proxy.js";
12
+ import { defaultDir, LocalSetupError, pullProject, testLocally } from "./local.js";
12
13
  import { VERSION } from "./version.js";
13
14
  export const EXIT = { ok: 0, failed: 1, usage: 2, api: 3, timeout: 4 };
14
15
  const line = (text) => `${text}\n`;
@@ -66,6 +67,25 @@ export async function main(deps) {
66
67
  }
67
68
  case "run":
68
69
  return await runCommand(deps, config, client, command);
70
+ case "pull": {
71
+ const dir = command.dir ?? defaultDir(command.project);
72
+ const pulled = await pullProject(deps, client, command.project, dir);
73
+ print(command.json, pulled, `Pulled ${pulled.written} files into ${pulled.dir}${pulled.removed ? ` (removed ${pulled.removed} the project no longer has)` : ""}.\n` +
74
+ `Run them: cd ${pulled.dir} && npm install && npx playwright install chromium && npx playwright test`);
75
+ if (pulled.skipped.length)
76
+ deps.stderr(line(`warning: skipped ${pulled.skipped.length} file(s) with unsafe paths: ${pulled.skipped.join(", ")}`));
77
+ return EXIT.ok;
78
+ }
79
+ case "local":
80
+ return await testLocally({ ...deps, log: (t) => deps.stderr(line(t)) }, client, {
81
+ project: command.project,
82
+ dir: command.dir ?? defaultDir(command.project),
83
+ tests: command.tests,
84
+ baseUrl: command.baseUrl,
85
+ headed: command.headed,
86
+ pull: command.pull,
87
+ env: deps.env,
88
+ });
69
89
  case "mcp":
70
90
  deps.stderr(line(`Pluswithai MCP proxy → ${config.apiUrl}/mcp`));
71
91
  return await runMcpProxy({
@@ -79,6 +99,10 @@ export async function main(deps) {
79
99
  }
80
100
  }
81
101
  catch (e) {
102
+ if (e instanceof LocalSetupError) {
103
+ deps.stderr(line(`error: ${e.message}`));
104
+ return EXIT.usage;
105
+ }
82
106
  if (e instanceof NoTestsError) {
83
107
  deps.stderr(line(`error: ${e.message}`));
84
108
  return EXIT.usage;
@@ -98,7 +122,9 @@ function hintFor(e, command) {
98
122
  if (e.status === 401)
99
123
  return "Check PLUSWITHAI_API_KEY (create one on the app's API keys page).";
100
124
  if (e.status === 403 && command.kind === "run")
101
- return "Starting runs needs a key with CI (read + run) access.";
125
+ return "Starting runs needs a key with CI / CLI (read + run) access.";
126
+ if (e.status === 402 && (command.kind === "pull" || command.kind === "local"))
127
+ return "Your plan cannot download this project's files.";
102
128
  if (e.status === 404 && "project" in command)
103
129
  return `Check the project name "${command.project}" (pluswithai projects lists them).`;
104
130
  return null;
@@ -115,6 +141,8 @@ async function runCommand(deps, config, client, command) {
115
141
  project: command.project,
116
142
  tests: command.tests,
117
143
  region: command.region,
144
+ environment: command.environment,
145
+ baseUrl: command.baseUrl,
118
146
  timeoutMs: command.timeoutSec * 1000,
119
147
  intervalMs: command.intervalSec * 1000,
120
148
  });
package/dist/node-deps.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /** The real process behind MainDeps: Node's fetch, streams, clock and files. */
2
- import { appendFile, mkdir, writeFile } from "node:fs/promises";
2
+ import { spawn } from "node:child_process";
3
+ import { access, appendFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
4
  import { dirname } from "node:path";
4
5
  import { createInterface } from "node:readline";
5
6
  export function nodeDeps(proc) {
@@ -21,5 +22,19 @@ export function nodeDeps(proc) {
21
22
  await mkdir(dirname(path), { recursive: true });
22
23
  await appendFile(path, data, "utf8");
23
24
  },
25
+ readText: (path) => readFile(path, "utf8").catch(() => null),
26
+ writeBytes: async (path, bytes) => {
27
+ await mkdir(dirname(path), { recursive: true });
28
+ await writeFile(path, bytes);
29
+ },
30
+ remove: (path) => rm(path, { force: true }),
31
+ exists: (path) => access(path).then(() => true, () => false),
32
+ spawn: (command, args, opts) => new Promise((resolve, reject) => {
33
+ // npm and npx are .cmd scripts on Windows: they need a shell there.
34
+ const child = spawn(command, args, { cwd: opts.cwd, env: opts.env, stdio: "inherit", shell: process.platform === "win32" });
35
+ child.once("error", reject);
36
+ // No code means a signal ended it: a failure.
37
+ child.once("exit", (code) => resolve(code ?? 1));
38
+ }),
24
39
  };
25
40
  }
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 lines = [`Pluswithai · ${project}: ${countsLine(outcome)}`];
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
- return await deps.client.startRun(opts.project, tests, opts.region);
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.1";
2
+ export const VERSION = "0.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluswithai/cli",
3
- "version": "0.2.1",
3
+ "version": "0.4.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
  }