From b60756c06cda2087579946f0e497cc0aa89464d2 Mon Sep 17 00:00:00 2001 From: DemonGatanjieu <207458273+DemonGatanjieu@users.noreply.github.com> Date: Sun, 11 Oct 2026 02:04:23 +0800 Subject: [PATCH] Test: models found offline keep their name across scans Co-Authored-By: Claude Opus 5.5 --- tests/test_scan_retry.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_scan_retry.py b/tests/test_scan_retry.py index 8c8f21d..eb3c828 100644 --- a/tests/test_scan_retry.py +++ b/tests/test_scan_retry.py @@ -11,7 +11,7 @@ sys.path.insert(0, str(PLUGIN_DIR.parents[1])) sys.path.insert(0, str(PLUGIN_DIR)) import scraper -from api import scan_summary, scanner +from api import metadata, scan_summary, scanner from model_identity import computed_file_identity DIGEST = "a" * 64 @@ -61,6 +61,18 @@ class ScanRetryTests(unittest.TestCase): self.assertEqual(json.loads(Path(str(self.matched)[:-12] + ".info").read_text(encoding="utf-8"))["id"], 5) self.assertFalse(Path(str(self.new)[:-12] + ".info").exists()) + def test_models_found_offline_keep_their_name(self): + # Named after the file as model and version: renaming doubled the name on every scan. + for flags in (["--offline-only"], ["--force-overwrite"]): + with mock.patch.object(sys, "argv", ["scraper.py", self.temp.name, "--physical-rename", "--virtual-rename", *flags]), \ + mock.patch.object(scraper, "fetch_civitai_info", return_value=None), \ + mock.patch.object(scraper, "calculate_sha256", return_value=DIGEST): + scraper.main() + self.assertTrue(self.new.exists()) + info = json.loads(Path(str(self.new)[:-12] + ".info").read_text(encoding="utf-8")) + self.assertNotIn("anomalous_custom_name", info) + self.assertEqual(metadata._read_metadata(str(self.new))["name"], "new") + def test_changed_file_is_hashed_again(self): self.unmatched.write_bytes(b"other bytes, other size") with mock.patch.object(scraper, "write_report") as report: