From a89be2604b41e4794a83cb02ac6a90469cc714b4 Mon Sep 17 00:00:00 2001 From: Julian Lechner Date: Thu, 5 Nov 2026 11:08:51 +0100 Subject: [PATCH] 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 --- scripts/lib/qmd.py | 5 +++++ scripts/tests/test-qmd-setup.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/scripts/lib/qmd.py b/scripts/lib/qmd.py index f7d9aff..7d6a4f1 100644 --- a/scripts/lib/qmd.py +++ b/scripts/lib/qmd.py @@ -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'] diff --git a/scripts/tests/test-qmd-setup.py b/scripts/tests/test-qmd-setup.py index 4f7eae6..fa911f5 100644 --- a/scripts/tests/test-qmd-setup.py +++ b/scripts/tests/test-qmd-setup.py @@ -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)