Test: models found offline keep their name across scans

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DemonGatanjieu
2026-10-11 02:04:23 +08:00
co-authored by Claude Opus 5.5
parent 5b19d85a5a
commit b60756c06c
+13 -1
View File
@@ -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: