@pluswithai/cli 0.3.0 → 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 +21 -2
- package/dist/args.js +61 -2
- package/dist/client.js +4 -0
- package/dist/local.js +103 -0
- package/dist/main.js +27 -1
- package/dist/node-deps.js +16 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
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
|
|
@@ -75,7 +75,9 @@ Inside GitHub Actions, the CLI also:
|
|
|
75
75
|
|
|
76
76
|
| Command | What it does |
|
|
77
77
|
|---|---|
|
|
78
|
-
| `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 |
|
|
79
81
|
| `pluswithai projects` | List your projects |
|
|
80
82
|
| `pluswithai tests --project <name>` | List a project's test files |
|
|
81
83
|
| `pluswithai runs --project <name>` | Show recent runs (`--limit`, 1–100) |
|
|
@@ -84,6 +86,23 @@ Inside GitHub Actions, the CLI also:
|
|
|
84
86
|
|
|
85
87
|
Every command takes `--help`, and every command except `mcp` takes `--json`.
|
|
86
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
|
+
|
|
87
106
|
## AI agents (MCP)
|
|
88
107
|
|
|
89
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.
|
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) {
|
|
@@ -32,6 +32,16 @@ const OPTIONS = {
|
|
|
32
32
|
junit: { type: "string" },
|
|
33
33
|
"no-summary": { type: "boolean" },
|
|
34
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" } },
|
|
35
45
|
projects: GLOBAL,
|
|
36
46
|
tests: { ...GLOBAL, ...PROJECT },
|
|
37
47
|
runs: { ...GLOBAL, ...PROJECT, limit: { type: "string" } },
|
|
@@ -106,6 +116,19 @@ export function parseCommand(argv) {
|
|
|
106
116
|
json,
|
|
107
117
|
summary: values["no-summary"] !== true,
|
|
108
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 };
|
|
109
132
|
case "projects":
|
|
110
133
|
return { kind: "projects", global, json };
|
|
111
134
|
case "tests":
|
|
@@ -152,6 +175,40 @@ Exit codes:
|
|
|
152
175
|
0 every run passed 1 a run failed
|
|
153
176
|
2 usage or configuration 3 Pluswithai or network error
|
|
154
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}`,
|
|
155
212
|
projects: `Usage: pluswithai projects [--json]
|
|
156
213
|
|
|
157
214
|
List the projects of the account.
|
|
@@ -198,7 +255,9 @@ export function helpText(topic) {
|
|
|
198
255
|
Run Pluswithai tests from CI and the terminal.
|
|
199
256
|
|
|
200
257
|
Commands:
|
|
201
|
-
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
|
|
202
261
|
projects List your projects
|
|
203
262
|
tests List a project's test files
|
|
204
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
|
}
|
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;
|
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 {
|
|
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/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.4.0";
|