fix(qmd): restart daemon on update, check version, add doctor checks

- Stop the running QMD daemon before install and update replace the
  runtime scripts, so the next search loads the new code and models and
  Windows no longer keeps old model files locked.
- Read the installed @tobilu/qmd version: reinstall a setup-owned package
  at the tested version, and warn about a foreign one of another version.
- Add QMD checks to doctor (PowerShell and Bash) through `qmd.py doctor`:
  runtime script digests, package version, model files, and daemon health.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian LechnerandClaude Opus 5.5 committed 2026-11-16 09:58:48 +01:00
1 parent ca4cb2a144
commit 82d9992b3a
5 files changed
+141 -22

No files matched your search

+39 -4
View File
@@ -1,4 +1,5 @@
import importlib.util
import io
import json
import os
from pathlib import Path
@@ -17,8 +18,8 @@ spec.loader.exec_module(qmd)
class FakeRunner:
def __init__(self, installed=False, gpu='cuda', gpu_result=None, cpu_result=None, previous=None, fail_pull=False, list_output=None,
node='v22.4.0', fail=(), on_call=None):
self.calls, self.installed, self.gpu = [], installed, gpu
node='v22.4.0', fail=(), on_call=None, version='2.8.3'):
self.calls, self.installed, self.gpu, self.version = [], installed, gpu, version
self.previous, self.fail_pull, self.list_output = previous, fail_pull, list_output
self.node, self.fail, self.on_call = node, fail, on_call
self.results = {'gpu': gpu_result, 'cpu': cpu_result}
@@ -39,9 +40,9 @@ class FakeRunner:
if 'npm list' in joined and self.list_output is not None:
return self.list_output
if 'npm list' in joined:
return json.dumps({'dependencies': {'@tobilu/qmd': {}} if self.installed else {}})
return json.dumps({'dependencies': {'@tobilu/qmd': {'version': self.version}} if self.installed else {}})
if 'npm install' in joined:
self.installed = True
self.installed, self.version = True, arguments[-1].rsplit('@', 1)[-1]
if 'npm uninstall' in joined:
self.installed = False
if '--detect' in joined:
@@ -103,6 +104,40 @@ class SetupTest(unittest.TestCase):
self.assertFalse(any('npm uninstall' in ' '.join(c) for c in runner.calls))
self.assertFalse((self.home / '.my-ai-configuration/qmd.json').exists())
def test_update_stops_the_running_daemon_before_replacing_scripts(self):
runner = FakeRunner()
self.setup(runner).enable(['claude'])
runner.calls.clear()
self.setup(runner).enable(['claude'])
stop = next(i for i, c in enumerate(runner.calls) if c[-1:] == ['--stop'])
set_models = next(i for i, c in enumerate(runner.calls) if c[-1:] == ['set-models'])
self.assertLess(stop, set_models)
def test_owned_package_with_another_version_is_reinstalled(self):
runner = FakeRunner()
self.setup(runner).enable(['claude'])
runner.version = '2.7.0'
runner.calls.clear()
self.setup(runner).enable(['claude'])
self.assertIn(['npm', 'install', '--global', '@tobilu/qmd@2.8.3'], runner.calls)
def test_foreign_package_with_another_version_only_warns(self):
runner = FakeRunner(installed=True, version='2.9.0')
with mock.patch('sys.stderr', new_callable=io.StringIO) as stderr:
self.setup(runner).enable(['claude'])
self.assertFalse(any('npm install' in ' '.join(c) for c in runner.calls))
self.assertIn('2.9.0 is not the tested 2.8.3', stderr.getvalue())
def test_doctor_checks_report_scripts_package_models_and_daemon(self):
setup = self.setup(FakeRunner())
self.assertEqual([], qmd.doctor_checks(setup))
setup.enable(['claude'])
checks = qmd.doctor_checks(setup)
# Scripts match, package matches, models not downloaded in the fake runner, daemon not running.
self.assertEqual(['PASS', 'PASS', 'WARN', 'PASS'], [status for status, _ in checks], checks)
(self.home / '.my-ai-configuration/qmd/qmd-search.mjs').write_text('changed')
self.assertEqual(('WARN', 'QMD runtime scripts were modified: qmd-search.mjs'), qmd.doctor_checks(setup)[0])
def test_model_files_follow_node_llama_cpp_cache_names(self):
names = qmd.model_files((ROOT / 'shared/qmd/qmd-lib.mjs').read_text(encoding='utf-8'))
self.assertIn('hf_Qwen_Qwen3-Embedding-4B-Q4_K_M.gguf', names)