@mindexec/cli 0.2.430 → 0.2.431

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindexec/cli",
3
- "version": "0.2.430",
3
+ "version": "0.2.431",
4
4
  "description": "MindExec local runtime and bridge CLI",
5
5
  "main": "server.js",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  "scripts": {
22
22
  "start": "node launch-bridge.cjs",
23
23
  "dev": "node launch-bridge.cjs --watch",
24
- "test:syntax": "node --check server.js && node --check remote-hub.js && node --check codex-runtime.js && node --check launch-bridge.cjs && node --check port-guard.cjs && node --check scripts/setup-tree-sitter-grammars.mjs && node --check scripts/auth-session-smoke.mjs && node --check scripts/remote-hub-smoke.mjs && node --check scripts/remote-hub-scale-smoke.mjs && node --check scripts/remote-fleet-render-smoke.mjs && node --check scripts/remote-http-smoke.mjs && node --check scripts/remote-frame-ws-smoke.mjs && node --check scripts/remote-input-ws-smoke.mjs && node --check scripts/remote-agent-ws-smoke.mjs && node --check scripts/remote-agent-managed-smoke.mjs && node --check scripts/remote-registry-follower-smoke.mjs && node --check scripts/remote-agent-package-smoke.mjs && node --check scripts/remote-fast-live-rate-smoke.mjs && node --check scripts/remote-fast-mdm-browser-smoke.mjs",
24
+ "test:syntax": "node --check server.js && node --check remote-hub.js && node --check codex-runtime.js && node --check launch-bridge.cjs && node --check port-guard.cjs && node --check scripts/setup-tree-sitter-grammars.mjs && node --check scripts/npm-fresh-install-smoke.mjs && node --check scripts/auth-session-smoke.mjs && node --check scripts/remote-hub-smoke.mjs && node --check scripts/remote-hub-scale-smoke.mjs && node --check scripts/remote-fleet-render-smoke.mjs && node --check scripts/remote-http-smoke.mjs && node --check scripts/remote-frame-ws-smoke.mjs && node --check scripts/remote-input-ws-smoke.mjs && node --check scripts/remote-agent-ws-smoke.mjs && node --check scripts/remote-agent-managed-smoke.mjs && node --check scripts/remote-registry-follower-smoke.mjs && node --check scripts/remote-agent-package-smoke.mjs && node --check scripts/remote-fast-live-rate-smoke.mjs && node --check scripts/remote-fast-mdm-browser-smoke.mjs",
25
25
  "test:auth": "node scripts/auth-session-smoke.mjs",
26
26
  "test:remote": "node scripts/remote-hub-smoke.mjs",
27
27
  "test:remote:scale": "node scripts/remote-hub-scale-smoke.mjs",
@@ -31,13 +31,13 @@
31
31
  "test:remote:input-ws": "node scripts/remote-input-ws-smoke.mjs",
32
32
  "test:remote:agent-ws": "node scripts/remote-agent-ws-smoke.mjs",
33
33
  "test:remote:managed": "node scripts/remote-agent-managed-smoke.mjs",
34
- "test:remote:registry": "node scripts/remote-registry-follower-smoke.mjs",
35
- "test:remote:package": "node scripts/remote-agent-package-smoke.mjs",
34
+ "test:remote:registry": "node scripts/remote-registry-follower-smoke.mjs",
35
+ "test:remote:package": "node scripts/remote-agent-package-smoke.mjs",
36
+ "test:package:fresh-install": "node scripts/npm-fresh-install-smoke.mjs",
36
37
  "test:remote:live-rate": "node scripts/remote-fast-live-rate-smoke.mjs",
37
38
  "test:remote:mdm-browser": "node scripts/remote-fast-mdm-browser-smoke.mjs",
38
- "pack:dry": "npm pack --dry-run",
39
- "setup:grammars": "node scripts/setup-tree-sitter-grammars.mjs",
40
- "postinstall": "npm run setup:grammars"
39
+ "pack:dry": "npm pack --dry-run",
40
+ "setup:grammars": "node scripts/setup-tree-sitter-grammars.mjs"
41
41
  },
42
42
  "keywords": [
43
43
  "mindexec",
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process';
4
+ import { existsSync } from 'node:fs';
5
+ import { mkdir, mkdtemp, readFile, readdir, rm } from 'node:fs/promises';
6
+ import { tmpdir } from 'node:os';
7
+ import path from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+
10
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
11
+ const bridgeRoot = path.resolve(scriptDir, '..');
12
+ const packageJsonPath = path.join(bridgeRoot, 'package.json');
13
+ const logPrefix = '[npm-fresh-install-smoke]';
14
+
15
+ function printableCommand(command, args) {
16
+ return [command, ...args].map(value => JSON.stringify(String(value))).join(' ');
17
+ }
18
+
19
+ function runCommand(command, args, options = {}) {
20
+ const cwd = options.cwd || bridgeRoot;
21
+ const label = options.label || 'command';
22
+ const result = spawnSync(command, args, {
23
+ cwd,
24
+ env: options.env || process.env,
25
+ encoding: 'utf8',
26
+ windowsHide: true,
27
+ shell: options.shell === true,
28
+ maxBuffer: 32 * 1024 * 1024
29
+ });
30
+ const stdout = String(result.stdout || '');
31
+ const stderr = String(result.stderr || '');
32
+
33
+ if (result.error || result.status !== 0) {
34
+ const details = [
35
+ `${logPrefix} ${label} failed.`,
36
+ `Command: ${printableCommand(command, args)}`,
37
+ `Working directory: ${cwd}`,
38
+ `Exit status: ${result.status ?? 'not started'}${result.signal ? ` (signal: ${result.signal})` : ''}`,
39
+ `stdout:\n${stdout.trimEnd() || '<empty>'}`,
40
+ `stderr:\n${stderr.trimEnd() || '<empty>'}`
41
+ ];
42
+
43
+ if (result.error) {
44
+ details.push(`Spawn error: ${result.error.stack || result.error.message}`);
45
+ }
46
+
47
+ throw new Error(details.join('\n'));
48
+ }
49
+
50
+ return { stdout, stderr };
51
+ }
52
+
53
+ function resolveNpmCommand() {
54
+ const npmExecPath = String(process.env.npm_execpath || '').trim();
55
+ if (npmExecPath && existsSync(npmExecPath)) {
56
+ return {
57
+ command: process.execPath,
58
+ argsPrefix: [npmExecPath],
59
+ shell: false
60
+ };
61
+ }
62
+
63
+ if (process.platform === 'win32') {
64
+ const nodeDir = path.dirname(process.execPath);
65
+ const npmPrefixScript = path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-prefix.js');
66
+ if (existsSync(npmPrefixScript)) {
67
+ const prefixResult = spawnSync(process.execPath, [npmPrefixScript], {
68
+ encoding: 'utf8',
69
+ windowsHide: true
70
+ });
71
+ const npmPrefix = prefixResult.status === 0 ? String(prefixResult.stdout || '').trim() : '';
72
+ const prefixNpmCliPath = npmPrefix
73
+ ? path.join(npmPrefix, 'node_modules', 'npm', 'bin', 'npm-cli.js')
74
+ : '';
75
+
76
+ if (prefixNpmCliPath && existsSync(prefixNpmCliPath)) {
77
+ return {
78
+ command: process.execPath,
79
+ argsPrefix: [prefixNpmCliPath],
80
+ shell: false
81
+ };
82
+ }
83
+ }
84
+
85
+ const bundledNpmCliPath = path.join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js');
86
+ if (existsSync(bundledNpmCliPath)) {
87
+ return {
88
+ command: process.execPath,
89
+ argsPrefix: [bundledNpmCliPath],
90
+ shell: false
91
+ };
92
+ }
93
+
94
+ return {
95
+ command: 'npm.cmd',
96
+ argsPrefix: [],
97
+ shell: true
98
+ };
99
+ }
100
+
101
+ return {
102
+ command: 'npm',
103
+ argsPrefix: [],
104
+ shell: false
105
+ };
106
+ }
107
+
108
+ function runNpm(npm, args, options = {}) {
109
+ return runCommand(npm.command, [...npm.argsPrefix, ...args], {
110
+ ...options,
111
+ shell: npm.shell,
112
+ env: {
113
+ ...process.env,
114
+ npm_config_ignore_scripts: 'false',
115
+ ...options.env
116
+ }
117
+ });
118
+ }
119
+
120
+ async function findPackedArchive(packDir) {
121
+ const entries = await readdir(packDir, { withFileTypes: true });
122
+ const archives = entries
123
+ .filter(entry => entry.isFile() && entry.name.endsWith('.tgz'))
124
+ .map(entry => path.join(packDir, entry.name));
125
+
126
+ if (archives.length !== 1) {
127
+ throw new Error(`${logPrefix} expected exactly one packed archive in ${packDir}, found ${archives.length}.`);
128
+ }
129
+
130
+ return archives[0];
131
+ }
132
+
133
+ function runInstalledBin(prefixDir) {
134
+ const binDir = path.join(prefixDir, 'node_modules', '.bin');
135
+ const binPath = path.join(binDir, process.platform === 'win32' ? 'mindexec.cmd' : 'mindexec');
136
+ if (!existsSync(binPath)) {
137
+ throw new Error(`${logPrefix} installed mindexec bin was not found: ${binPath}`);
138
+ }
139
+
140
+ if (process.platform === 'win32') {
141
+ return runCommand(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'mindexec.cmd --version'], {
142
+ cwd: binDir,
143
+ label: 'installed bin version check'
144
+ });
145
+ }
146
+
147
+ return runCommand(binPath, ['--version'], {
148
+ cwd: binDir,
149
+ label: 'installed bin version check'
150
+ });
151
+ }
152
+
153
+ async function runSmoke(tempRoot) {
154
+ const packageInfo = JSON.parse(await readFile(packageJsonPath, 'utf8'));
155
+ const expectedVersion = String(packageInfo.version || '').trim();
156
+ if (!expectedVersion) {
157
+ throw new Error(`${logPrefix} package.json does not contain a version.`);
158
+ }
159
+
160
+ const packDir = path.join(tempRoot, 'pack');
161
+ const prefixDir = path.join(tempRoot, 'install-prefix');
162
+ await Promise.all([
163
+ mkdir(packDir, { recursive: true }),
164
+ mkdir(prefixDir, { recursive: true })
165
+ ]);
166
+
167
+ const npm = resolveNpmCommand();
168
+ console.log(`${logPrefix} packing @mindexec/cli ${expectedVersion}`);
169
+ runNpm(npm, ['pack', '--pack-destination', packDir], {
170
+ cwd: bridgeRoot,
171
+ label: 'npm pack'
172
+ });
173
+
174
+ const archivePath = await findPackedArchive(packDir);
175
+ console.log(`${logPrefix} installing ${path.basename(archivePath)} into a clean prefix with lifecycle scripts enabled`);
176
+ runNpm(npm, ['install', archivePath, '--prefix', prefixDir, '--ignore-scripts=false'], {
177
+ cwd: tempRoot,
178
+ label: 'fresh npm install'
179
+ });
180
+
181
+ const { stdout } = runInstalledBin(prefixDir);
182
+ const actualVersion = stdout.trim();
183
+ if (actualVersion !== expectedVersion) {
184
+ throw new Error([
185
+ `${logPrefix} installed bin version mismatch.`,
186
+ `Expected: ${expectedVersion}`,
187
+ `Actual: ${actualVersion || '<empty>'}`
188
+ ].join('\n'));
189
+ }
190
+
191
+ console.log(`${logPrefix} OK: installed mindexec --version returned ${actualVersion}`);
192
+ }
193
+
194
+ let tempRoot = '';
195
+
196
+ try {
197
+ tempRoot = await mkdtemp(path.join(tmpdir(), 'mindexec-npm-fresh-install-'));
198
+ await runSmoke(tempRoot);
199
+ } catch (error) {
200
+ console.error(error?.stack || error);
201
+ process.exitCode = 1;
202
+ } finally {
203
+ if (tempRoot) {
204
+ try {
205
+ await rm(tempRoot, {
206
+ recursive: true,
207
+ force: true,
208
+ maxRetries: 5,
209
+ retryDelay: 200
210
+ });
211
+ } catch (error) {
212
+ console.error(`${logPrefix} failed to remove temporary directory ${tempRoot}:`, error);
213
+ process.exitCode = 1;
214
+ }
215
+ }
216
+ }