fix(qmd): run global npm CLIs without relying on PATH
CI / CI configuration security checks (push) Successful in 2s
CI / Capabilities and shell quality (push) Successful in 12s
CI / Python tests and compilation (push) Successful in 25s
CI / QMD unit tests (push) Successful in 5s
CI / Build and inspect generated packages (push) Successful in 15s
CI / PowerShell tests on Ubuntu (push) Successful in 1m5s
CI / Installed client configuration smoke tests (push) Successful in 40s
CI / Bash integration and installation guards (push) Successful in 1m10s
CI / CI configuration security checks (push) Successful in 2s
CI / Capabilities and shell quality (push) Successful in 12s
CI / Python tests and compilation (push) Successful in 25s
CI / QMD unit tests (push) Successful in 5s
CI / Build and inspect generated packages (push) Successful in 15s
CI / PowerShell tests on Ubuntu (push) Successful in 1m5s
CI / Installed client configuration smoke tests (push) Successful in 40s
CI / Bash integration and installation guards (push) Successful in 1m10s
npm's global bin directory is often missing from PATH on Windows, so the installer failed at `qmd pull` right after installing the package. Run the QMD CLI through node from `npm root --global`, as the QMD scripts already do, and look up other globally installed CLIs such as mcporter in `npm prefix --global` when they are not on PATH. Doctor now warns when npm's global bin directory is missing from PATH, since agents call mcporter directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a89be2604b
commit
6fad45105f
7 files changed
+101
-7
No files matched your search
@@ -336,6 +336,31 @@ class CommandTests(unittest.TestCase):
|
||||
result = extensions.run_command([str(executable), 'plugin', 'list', '--json'], True, home)
|
||||
self.assertEqual([str(home / '.codex'), str(home / '.claude')], result.splitlines())
|
||||
|
||||
def test_global_npm_cli_is_found_when_its_directory_is_not_on_path(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
prefix = Path(temporary)
|
||||
bin_dir = prefix if os.name == 'nt' else prefix / 'bin'
|
||||
bin_dir.mkdir(exist_ok=True)
|
||||
tool = bin_dir / ('mcporter.cmd' if os.name == 'nt' else 'mcporter')
|
||||
tool.write_text('@echo off\n' if os.name == 'nt' else '#!/bin/sh\n')
|
||||
tool.chmod(0o700)
|
||||
real_which = shutil.which
|
||||
|
||||
def which(name, mode=os.F_OK | os.X_OK, path=None):
|
||||
if path is None:
|
||||
return '/usr/bin/npm' if name == 'npm' else None
|
||||
return real_which(name, mode, path)
|
||||
|
||||
prefix_result = subprocess.CompletedProcess(['npm'], 0, stdout=f'{prefix}\n', stderr='')
|
||||
with patch.object(extensions.shutil, 'which', side_effect=which), \
|
||||
patch.object(extensions.subprocess, 'run', return_value=prefix_result):
|
||||
found = extensions.find_executable('mcporter')
|
||||
self.assertEqual(Path(found).resolve(), tool.resolve())
|
||||
|
||||
def test_missing_cli_stays_missing_without_npm(self):
|
||||
with patch.object(extensions.shutil, 'which', return_value=None):
|
||||
self.assertIsNone(extensions.find_executable('mcporter'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -34,7 +34,7 @@ class FakeRunner:
|
||||
return self.node
|
||||
if arguments[-1:] == ['set-models']:
|
||||
return json.dumps({'previous': self.previous}) + chr(10)
|
||||
if self.fail_pull and arguments[:2] == ['qmd', 'pull']:
|
||||
if self.fail_pull and arguments[0] == 'node' and arguments[-1:] == ['pull']:
|
||||
raise ValueError('pull failed')
|
||||
if 'npm list' in joined and self.list_output is not None:
|
||||
return self.list_output
|
||||
@@ -115,7 +115,8 @@ class SetupTest(unittest.TestCase):
|
||||
(self.home / '.my-ai-configuration/qmd/collections.json').write_text(json.dumps(['repo-abcdefabcdef']))
|
||||
setup.disable(['claude'])
|
||||
self.assertFalse(model.exists())
|
||||
self.assertIn(['qmd', 'collection', 'remove', 'repo-abcdefabcdef'], runner.calls)
|
||||
self.assertTrue(any(call[0] == 'node' and call[1].endswith('qmd.js') and call[2:] == ['collection', 'remove', 'repo-abcdefabcdef']
|
||||
for call in runner.calls), runner.calls)
|
||||
self.assertIn(['npm', 'uninstall', '--global', '@tobilu/qmd'], runner.calls)
|
||||
|
||||
def test_benchmark_unsuitable_cleans_up(self):
|
||||
@@ -220,6 +221,24 @@ class SetupTest(unittest.TestCase):
|
||||
self.assertTrue(self.setup(FakeRunner(list_output='{"dependencies": {"@tobilu/qmd": {}}, "error": {}}')).package_installed())
|
||||
self.assertFalse(self.setup(FakeRunner(list_output='{"dependencies": {}}')).package_installed())
|
||||
|
||||
def test_qmd_cli_runs_through_node_without_relying_on_path(self):
|
||||
# npm's global bin directory is often missing from PATH on Windows right after install.
|
||||
runner = FakeRunner()
|
||||
runner_root = str(self.home / 'npm-root')
|
||||
original = runner.__call__
|
||||
|
||||
def call(arguments, env=None, timeout=None, check=True):
|
||||
if arguments == ['npm', 'root', '--global']:
|
||||
runner.calls.append(list(arguments))
|
||||
return runner_root + '\n'
|
||||
return original(arguments, env=env, timeout=timeout, check=check)
|
||||
|
||||
setup = self.setup(call)
|
||||
setup.qmd_cli('pull')
|
||||
expected = str(Path(runner_root) / '@tobilu' / 'qmd' / 'dist' / 'cli' / 'qmd.js')
|
||||
self.assertIn(['node', expected, 'pull'], runner.calls)
|
||||
self.assertFalse(any(call[0] == 'qmd' for call in runner.calls))
|
||||
|
||||
def test_package_installed_treats_missing_global_prefix_as_not_installed(self):
|
||||
# npm reports ENOENT for the global prefix before anything was ever installed globally.
|
||||
output = '{"error": {"code": "ENOENT", "summary": "ENOENT: no such file or directory, lstat \'C:\\\\Users\\\\me\\\\AppData\\\\Roaming\\\\npm\'"}}'
|
||||
|
||||
Reference in new issue
Block a user