From 6cfcd564c0684c52618235e6366f4a81c02b9a5b Mon Sep 17 00:00:00 2001 From: historia Date: Tue, 1 Sep 2026 14:32:05 -0400 Subject: slop refactor/dedup --- app/tests/test_backends_audiocpp.py | 74 ++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 10 deletions(-) (limited to 'app/tests/test_backends_audiocpp.py') diff --git a/app/tests/test_backends_audiocpp.py b/app/tests/test_backends_audiocpp.py index 18c38c4..9392ba1 100644 --- a/app/tests/test_backends_audiocpp.py +++ b/app/tests/test_backends_audiocpp.py @@ -410,6 +410,56 @@ class LoadModelCatalogTests(unittest.TestCase): self.assertIn("mystery_tts", [entry["family"] for entry in catalog]) + def test_non_object_spec_json_is_skipped_not_fatal(self): + # Valid JSON that is not an object (the "crash on bad model_specs" + # fix class): skipped like an unparsable spec, never an + # AttributeError out of the wizard. + for payload in ('["a list"]', '"a string"', "42", "null"): + (self.checkout / "model_specs" / "broken.json") \ + .write_text(payload, encoding="utf-8") + catalog = make_server.catalog.load_model_catalog(self.checkout) + self.assertNotIn("broken", + [entry["family"] for entry in catalog]) + + def test_non_dict_package_entries_are_skipped(self): + (self.checkout / "model_specs" / "weird_pkg.json").write_text( + json.dumps({"family": "weird_pkg", "tasks": ["tts"], + "packages": ["not-a-dict", + {"id": "wp", "format": "gguf", + "files": ["m.gguf"], + "target_directory": "weird_pkg"}]}), + encoding="utf-8") + catalog = make_server.catalog.load_model_catalog(self.checkout) + entry = next(e for e in catalog if e["family"] == "weird_pkg") + self.assertEqual(entry["install_id"], "wp") + + def test_download_path_materializes_the_catalog_repair(self): + # Regression for the shadowed-sanitizer bug: the download path's + # staged specs copy must apply the catalog sanitizer's SECOND bug + # class (missing strip_prefix on $gguf-rooted single-GGUF packages + # nested under a repo directory — glm_tts/outetts), which the old + # dot-only models.py repair did not. + (self.checkout / "model_specs" / "glm_like.json").write_text( + json.dumps({"family": "glm_like", "tasks": ["tts"], + "sources": [{"format": "gguf", + "roots": {"tokenizer": "$gguf"}}], + "packages": [{"id": "glm_q8", "format": "gguf", + "files": ["Text to audio (TTS)/" + "GLM-TTS_Q8.gguf"]}, + {"id": "glm_other", "format": "safetensors", + "files": ["tokenizer_merges"], + "default": True}]}), + encoding="utf-8") + staging = make_server.models._prepare_specs_dir(self.checkout) + self.assertIsNotNone(staging, "nested-GGUF repair was not staged") + try: + repaired = json.loads( + (staging / "glm_like.json").read_text(encoding="utf-8")) + finally: + shutil.rmtree(staging, ignore_errors=True) + self.assertEqual(repaired["packages"][0]["strip_prefix"], + "Text to audio (TTS)") + def test_families_sorted_alphabetically_by_display_name(self): catalog = make_server.catalog.load_model_catalog(self.checkout) names = [entry["display_name"].lower() for entry in catalog] @@ -1095,48 +1145,53 @@ class InstallModelsTests(unittest.TestCase): class SanitizeModelSpecTests(unittest.TestCase): - """The dot strip_prefix repair and the --specs-dir staging copy.""" + """The strip_prefix repairs (both upstream bug classes) and staging.""" def test_dot_prefix_dropped_when_file_is_bare(self): spec = {"packages": [{"files": ["model.gguf"], "strip_prefix": "."}]} - self.assertTrue(make_server.models._sanitize_model_spec(spec)) + self.assertTrue(make_server.catalog.sanitize_model_spec(spec)) self.assertEqual(spec["packages"][0]["strip_prefix"], "") def test_slash_dot_prefix_normalized_like_dot(self): spec = {"packages": [{"files": ["model.gguf"], "strip_prefix": "./"}]} - self.assertTrue(make_server.models._sanitize_model_spec(spec)) + self.assertTrue(make_server.catalog.sanitize_model_spec(spec)) self.assertEqual(spec["packages"][0]["strip_prefix"], "") def test_dot_prefix_kept_when_files_carry_it(self): spec = {"packages": [{"files": ["./model.gguf"], "strip_prefix": "."}]} - self.assertFalse(make_server.models._sanitize_model_spec(spec)) + self.assertFalse(make_server.catalog.sanitize_model_spec(spec)) self.assertEqual(spec["packages"][0]["strip_prefix"], ".") def test_real_directory_prefix_untouched(self): spec = {"packages": [{"files": ["model.gguf"], "strip_prefix": "Kroko-ASR-GGUF"}]} - self.assertFalse(make_server.models._sanitize_model_spec(spec)) + self.assertFalse(make_server.catalog.sanitize_model_spec(spec)) self.assertEqual(spec["packages"][0]["strip_prefix"], "Kroko-ASR-GGUF") def test_valid_prefix_untouched(self): spec = {"packages": [{"files": ["Kroko-ASR-GGUF/model.gguf"], "strip_prefix": "Kroko-ASR-GGUF"}]} - self.assertFalse(make_server.models._sanitize_model_spec(spec)) + self.assertFalse(make_server.catalog.sanitize_model_spec(spec)) - def test_missing_or_empty_files_untouched(self): + def test_malformed_files_package_repaired_too(self): + # The catalog sanitizer also drops a dot prefix when the package's + # files list is missing, empty, or malformed — nothing can match a + # dot prefix, so the repair is safe there as well (a dot prefix + # with files that all carry it is kept, see above). spec = {"packages": [{"strip_prefix": "."}, {"files": [], "strip_prefix": "."}, {"files": "model.gguf", "strip_prefix": "."}]} - self.assertFalse(make_server.models._sanitize_model_spec(spec)) + self.assertTrue(make_server.catalog.sanitize_model_spec(spec)) + self.assertEqual({p["strip_prefix"] for p in spec["packages"]}, {""}) def test_only_broken_packages_repaired(self): spec = {"packages": [ {"files": ["model.gguf"], "strip_prefix": "."}, {"files": ["./model.gguf"], "strip_prefix": "."}, ]} - self.assertTrue(make_server.models._sanitize_model_spec(spec)) + self.assertTrue(make_server.catalog.sanitize_model_spec(spec)) self.assertEqual([p["strip_prefix"] for p in spec["packages"]], ["", "."]) @@ -3368,7 +3423,6 @@ class ExecuteLanesTests(unittest.TestCase): "include_clone": False, "wav_dir": None, "plan": None, - "sync_port": None, "delete_unused": False, "unused_entries": [], "model_entries": [], -- cgit v1.2.3