Merge pull request #2856 from infinito-nexus/fix/svc-ai-lmstudio/async-model-fetch

feat(svc-ai-lmstudio): fetch every lacking model at once as async jobs
This commit is contained in:
kevinveenbirkenbach authored and GitHub committed 2026-11-26 00:25:26 +01:00
commit b49cd467ac
18 files changed
+1642 -267

No files matched your search

@@ -80,6 +80,53 @@ class TestGetUrlRetryActionPlugin(unittest.TestCase):
self.assertEqual(sleep_mock.call_count, 2)
sleep_mock.assert_called_with(1)
def test_run_takes_its_retry_count_from_its_own_argument(self):
task = _FakeTask(
args={"url": "http://example.invalid", "dest": "/tmp/file", "retries": "1"},
ds={"delay": 1},
delay=1,
)
action = _make_action(task)
with (
patch(
"plugins.action.get_url_retry.ActionModule._execute_module",
side_effect=[
{"failed": True, "msg": "attempt-1"},
{"failed": True, "msg": "attempt-2"},
{"failed": False, "dest": "/tmp/file"},
],
) as module_mock,
patch("plugins.action.get_url_retry.time.sleep") as sleep_mock,
):
result = action.run(task_vars={})
self.assertTrue(result.get("failed"))
self.assertEqual(result.get("attempts"), 2)
self.assertEqual(module_mock.call_count, 2)
sleep_mock.assert_called_once_with(1)
for call in module_mock.call_args_list:
self.assertEqual(
call.kwargs["module_args"],
{"url": "http://example.invalid", "dest": "/tmp/file"},
)
def test_own_retry_argument_never_reaches_an_async_get_url(self):
task = _FakeTask(
args={"url": "http://example.invalid", "dest": "/tmp/file", "retries": 3},
async_val=30,
)
action = _make_action(task)
with patch(
"plugins.action.get_url_retry.ActionModule._execute_module",
return_value={"failed": False, "dest": "/tmp/file"},
) as module_mock:
action.run(task_vars={})
self.assertEqual(module_mock.call_count, 1)
self.assertNotIn("retries", module_mock.call_args.kwargs["module_args"])
def test_run_delegates_to_native_when_until_is_set(self):
task = _FakeTask(
args={"url": "http://example.invalid", "dest": "/tmp/file"},
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,86 @@
from __future__ import annotations
import importlib.util
import sys
import unittest
from utils import PROJECT_ROOT
def _load_module(rel_path: str, name: str):
path = PROJECT_ROOT / rel_path
spec = importlib.util.spec_from_file_location(name, str(path))
mod = importlib.util.module_from_spec(spec)
assert spec and spec.loader
sys.modules[name] = mod
spec.loader.exec_module(mod)
return mod
declared_mod = _load_module(
"roles/svc-ai-lmstudio/filter_plugins/lmstudio_declared_models.py",
"lmstudio_declared_models",
)
lmstudio_declared_models = declared_mod.lmstudio_declared_models
def _model(file, url, mirrors=None):
model = {"repo": "org/Probe-GGUF", "file": file, "url": url}
if mirrors is not None:
model["mirrors"] = mirrors
return model
class LmstudioDeclaredModelsTests(unittest.TestCase):
def test_a_single_declaration_keeps_its_url_and_mirrors(self):
models = [_model("probe.gguf", "https://a/probe", ["https://m1/probe"])]
self.assertEqual(
lmstudio_declared_models(models),
[{**models[0], "mirrors": ["https://m1/probe"]}],
)
def test_a_declaration_without_mirrors_gets_an_empty_list(self):
models = [_model("probe.gguf", "https://a/probe")]
self.assertEqual(lmstudio_declared_models(models)[0]["mirrors"], [])
def test_a_repeated_path_merges_the_sources_of_every_declaration_once(self):
models = [
_model("probe.gguf", "https://a/probe", ["https://m1/probe"]),
_model(
"probe.gguf", "https://b/probe", ["https://m1/probe", "https://a/probe"]
),
]
merged = lmstudio_declared_models(models)
self.assertEqual(len(merged), 1)
self.assertEqual(merged[0]["url"], "https://a/probe")
self.assertEqual(merged[0]["mirrors"], ["https://m1/probe", "https://b/probe"])
def test_paths_that_differ_only_in_case_stay_two_models_in_order(self):
models = [
_model("Probe.gguf", "https://a/upper"),
_model("probe.gguf", "https://a/lower"),
]
self.assertEqual(
[model["file"] for model in lmstudio_declared_models(models)],
["Probe.gguf", "probe.gguf"],
)
def test_the_declarations_are_left_untouched(self):
models = [
_model("probe.gguf", "https://a/probe"),
_model("probe.gguf", "https://b/probe"),
]
lmstudio_declared_models(models)
self.assertNotIn("mirrors", models[0])
self.assertNotIn("mirrors", models[1])
if __name__ == "__main__":
unittest.main()