qa 0.18.0 → 0.19.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.
Files changed (3) hide show
  1. package/README.md +24 -4
  2. package/cli.cjs +147 -9
  3. package/package.json +9 -10
package/README.md CHANGED
@@ -40,9 +40,10 @@ Or run it without a global install:
40
40
  npx qa --help
41
41
  ```
42
42
 
43
- The npm package is `qa`. It installs a compiled `mo` binary for your system and
44
- exposes both `qa` and `mo` commands. Both commands show `qa` in help when
45
- installed through npm. The standalone installer uses `mo` in help.
43
+ The npm package is `qa`. It installs a compiled `qa` binary for your system and
44
+ exposes the `qa` command. The standalone installer
45
+ (`curl -fsSL https://cli.momentic.ai/qa | sh`) also installs `qa`. Releases
46
+ before 0.18 named the command `mo`.
46
47
 
47
48
  The npm launcher requires Node.js 22.12 or later in the 22.x series, or Node.js
48
49
  24 or later. Binaries are available for macOS ARM64/x64, Linux ARM64/x64 (glibc
@@ -73,5 +74,24 @@ npm install -g qa@latest
73
74
  For a project dependency, update `qa` with your project's package manager.
74
75
  `qa upgrade` prints these instructions without replacing npm-managed files.
75
76
 
77
+ ## Troubleshoot
78
+
79
+ Run `qa doctor` to print the install method, resolved binary path, every
80
+ `mo`/`qa`/`momentic` executable on your `PATH`, and the one that wins. Include
81
+ the output when reporting a CLI problem.
82
+
83
+ - `npm install -g qa` fails with `EEXIST` if a file named `qa` already exists in
84
+ npm's global bin directory. Check `ls -la $(npm prefix -g)/bin` and remove the
85
+ stale entry; do not pass `--force`.
86
+ - `qa` 0.17.x also installed a `mo` command. Updating removes it.
87
+ - A curl install from before the rename left `mo` at `$HOME/.local/bin/mo`.
88
+ `mo upgrade` still downloads new releases, but the file keeps the `mo` name.
89
+ Remove it and rerun the installer to switch to `qa`.
90
+ - If a standalone `mo` and the npm package coexist, the first on `PATH` runs. In
91
+ a shell that already ran the old command, run `hash -r` to clear the cached
92
+ path.
93
+ - `npx mo` is not Momentic; the `mo` package on npm is a different project. Use
94
+ `npx qa`.
95
+
76
96
  See the [Mo CLI reference](https://docs.momentic.ai/cli-reference/mo/overview)
77
- for commands and examples. The reference's `mo` commands also work with `qa`.
97
+ for commands and examples.
package/cli.cjs CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { spawn } = require("node:child_process");
3
+ const { execSync, spawn } = require("node:child_process");
4
+ const fs = require("node:fs");
5
+ const path = require("node:path");
4
6
 
5
7
  const os = process.platform === "win32" ? "windows" : process.platform;
6
8
  const report = os === "linux" ? process.report.getReport() : undefined;
@@ -14,19 +16,155 @@ const libc =
14
16
  ? "-musl"
15
17
  : "";
16
18
  const target = `${os}-${process.arch}${libc}`;
17
- const packageName = `@momentic/qa-${target}`;
18
- const executable = process.platform === "win32" ? "mo.exe" : "mo";
19
19
 
20
- let binary;
21
- try {
22
- binary = require.resolve(`${packageName}/bin/${executable}`);
23
- } catch {
20
+ const ALL_TARGETS = [
21
+ "darwin-arm64",
22
+ "darwin-x64",
23
+ "linux-arm64",
24
+ "linux-arm64-musl",
25
+ "linux-x64",
26
+ "linux-x64-musl",
27
+ "windows-x64",
28
+ ];
29
+ const DOCS_URL = "https://docs.momentic.ai/cli-reference/mo/overview";
30
+
31
+ const binaryEntry = (t) =>
32
+ `@momentic/qa-${t}/bin/${t.startsWith("windows") ? "qa.exe" : "qa"}`;
33
+
34
+ function tryResolve(entry) {
35
+ try {
36
+ return require.resolve(entry);
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ // Windows and macOS arm64 hosts can run the x64 build under emulation.
43
+ const emulatedTargets =
44
+ process.arch === "arm64" && (os === "darwin" || os === "windows")
45
+ ? [`${os}-x64`]
46
+ : [];
47
+
48
+ // The package manager that ran us identifies itself in npm_config_user_agent,
49
+ // e.g. "pnpm/9.1.0 npm/? node/v20.11.0 darwin arm64".
50
+ function detectPackageManager() {
51
+ const match = process.env.npm_config_user_agent?.match(/^(\S+)\/(\d+)/);
52
+ return match ? { name: match[1], major: Number(match[2]) } : null;
53
+ }
54
+
55
+ function repairCommand(pm) {
56
+ switch (pm?.name) {
57
+ case "pnpm":
58
+ return "pnpm install --force";
59
+ case "bun":
60
+ return "bun install --force";
61
+ case "yarn":
62
+ return pm.major === 1 ? "yarn install --check-files" : "yarn install";
63
+ default:
64
+ return null;
65
+ }
66
+ }
67
+
68
+ // Optional dependencies can be skipped (--omit=optional, broken lockfiles, or
69
+ // node_modules copied across platforms). Try a just-in-time install from the
70
+ // qa package directory before giving up.
71
+ function installMissingBinary() {
72
+ let qaDir;
73
+ try {
74
+ qaDir = path.dirname(require.resolve("qa/package"));
75
+ } catch {
76
+ return false;
77
+ }
78
+ console.warn(
79
+ `The qa binary for ${target} is missing; attempting to install it now.`,
80
+ );
81
+ try {
82
+ // Erase npm_config_global so a global `npm i -g qa` invocation does not
83
+ // deadlock on the global install lock when this runs nested.
84
+ execSync(
85
+ "npm install --loglevel=error --prefer-offline --no-audit --no-save --no-package-lock --progress=false",
86
+ {
87
+ cwd: qaDir,
88
+ stdio: "pipe",
89
+ env: { ...process.env, npm_config_global: undefined },
90
+ },
91
+ );
92
+ return true;
93
+ } catch {
94
+ return false;
95
+ }
96
+ }
97
+
98
+ function reportMissingBinary() {
99
+ console.error();
100
+ console.error(`Cannot find the qa binary for ${target}.`);
101
+ const otherPlatforms = ALL_TARGETS.filter(
102
+ (t) => t !== target && tryResolve(binaryEntry(t)),
103
+ );
104
+ if (otherPlatforms.length > 0) {
105
+ console.error(
106
+ `Found binaries for other platforms: ${otherPlatforms.join(", ")}.`,
107
+ );
108
+ console.error(
109
+ "This usually means node_modules was copied between different operating systems or architectures (for example into a Docker image or a shared volume). Reinstall dependencies in the environment where you run qa.",
110
+ );
111
+ } else {
112
+ console.error(
113
+ "No platform binaries are installed. This can happen when optional dependencies are skipped (npm install --omit=optional).",
114
+ );
115
+ }
116
+ const pm = detectPackageManager();
117
+ const repair = repairCommand(pm);
24
118
  console.error(
25
- `Cannot find the mo binary for ${target}. Reinstall qa with optional dependencies enabled (npm install --include=optional qa). See https://docs.momentic.ai/cli-reference/mo/overview for supported platforms.`,
119
+ `Reinstall qa with optional dependencies enabled: npm install --include=optional qa` +
120
+ (repair ? ` — with ${pm.name}, run \`${repair}\`.` : "."),
26
121
  );
122
+ console.error(`Supported platforms: ${ALL_TARGETS.join(", ")}.`);
123
+ console.error(`See ${DOCS_URL} for supported platforms and install options.`);
124
+ }
125
+
126
+ function resolveBinary() {
127
+ const override = process.env.MO_BINARY_PATH;
128
+ if (override) {
129
+ if (fs.existsSync(override)) {
130
+ return override;
131
+ }
132
+ console.error(`MO_BINARY_PATH points to a file that does not exist:`);
133
+ console.error(override);
134
+ process.exit(1);
135
+ }
136
+
137
+ let binary = tryResolve(binaryEntry(target));
138
+ if (binary) {
139
+ return binary;
140
+ }
141
+
142
+ if (installMissingBinary()) {
143
+ binary = tryResolve(binaryEntry(target));
144
+ if (binary) {
145
+ console.warn("Installation succeeded.");
146
+ return binary;
147
+ }
148
+ console.warn(
149
+ "npm reported success, but the binary is still missing. npm skips failed optional dependencies without reporting an error.",
150
+ );
151
+ }
152
+
153
+ for (const t of emulatedTargets) {
154
+ binary = tryResolve(binaryEntry(t));
155
+ if (binary) {
156
+ console.warn(
157
+ `No qa binary for ${target}; running the ${t} build under emulation.`,
158
+ );
159
+ return binary;
160
+ }
161
+ }
162
+
163
+ reportMissingBinary();
27
164
  process.exit(1);
28
165
  }
29
166
 
167
+ const binary = resolveBinary();
30
168
  const child = spawn(binary, process.argv.slice(2), {
31
169
  stdio: "inherit",
32
170
  env: { ...process.env, MOMENTIC_MO_INSTALL_METHOD: "npm" },
@@ -39,7 +177,7 @@ for (const signal of signals) {
39
177
  }
40
178
 
41
179
  child.on("error", (err) => {
42
- console.error(`Could not start mo: ${err.message}`);
180
+ console.error(`Could not start qa: ${err.message}`);
43
181
  process.exitCode = 1;
44
182
  });
45
183
  child.on("exit", (code, signal) => {
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "qa",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "The CLI for Mo, Momentic's autonomous QA agent.",
5
5
  "private": false,
6
6
  "bin": {
7
- "qa": "./cli.cjs",
8
- "mo": "./cli.cjs"
7
+ "qa": "./cli.cjs"
9
8
  },
10
9
  "files": [
11
10
  "cli.cjs"
@@ -37,12 +36,12 @@
37
36
  "node": "^22.12.0 || >=24.0.0"
38
37
  },
39
38
  "optionalDependencies": {
40
- "@momentic/qa-darwin-arm64": "0.18.0",
41
- "@momentic/qa-darwin-x64": "0.18.0",
42
- "@momentic/qa-linux-arm64": "0.18.0",
43
- "@momentic/qa-linux-arm64-musl": "0.18.0",
44
- "@momentic/qa-linux-x64": "0.18.0",
45
- "@momentic/qa-linux-x64-musl": "0.18.0",
46
- "@momentic/qa-windows-x64": "0.18.0"
39
+ "@momentic/qa-darwin-arm64": "0.19.0",
40
+ "@momentic/qa-darwin-x64": "0.19.0",
41
+ "@momentic/qa-linux-arm64": "0.19.0",
42
+ "@momentic/qa-linux-arm64-musl": "0.19.0",
43
+ "@momentic/qa-linux-x64": "0.19.0",
44
+ "@momentic/qa-linux-x64-musl": "0.19.0",
45
+ "@momentic/qa-windows-x64": "0.19.0"
47
46
  }
48
47
  }