fix(qmd): treat a missing global npm prefix as not installed
On a machine where no global npm package was ever installed, the global prefix directory does not exist and `npm list --global --json` reports ENOENT without a dependency list. QMD setup treated that as an unreliable listing and failed the install/update. It now means the package is not installed; other unreliable listings still fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b6fd4dde7d
commit
a89be2604b
2 files changed
+10
No files matched your search
@@ -101,6 +101,11 @@ class Setup:
|
||||
listing = json.loads(output)
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError('npm list did not return JSON.')
|
||||
# Before the first global install the global prefix directory does not exist; npm then
|
||||
# reports ENOENT without a dependency list, which means nothing is installed yet.
|
||||
error = listing.get('error') if isinstance(listing, dict) else None
|
||||
if isinstance(error, dict) and error.get('code') == 'ENOENT' and 'dependencies' not in listing:
|
||||
return False
|
||||
if not isinstance(listing, dict) or not isinstance(listing.get('dependencies'), dict):
|
||||
raise ValueError('npm list did not report the global packages.')
|
||||
return PACKAGE in listing['dependencies']
|
||||
|
||||
@@ -220,6 +220,11 @@ 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_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\'"}}'
|
||||
self.assertFalse(self.setup(FakeRunner(list_output=output)).package_installed())
|
||||
|
||||
def test_non_mapping_previous_models_are_restored_verbatim(self):
|
||||
runner = FakeRunner(previous='custom.gguf')
|
||||
setup = self.setup(runner)
|
||||
|
||||
Reference in new issue
Block a user