mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-10-10 03:22:12 -03:00
fix(civitai): anchor model-page URL parsing and improve missing-model diagnostics (#1140)
This commit is contained in:
@@ -352,6 +352,12 @@ describe('civitaiUtils', () => {
|
||||
});
|
||||
|
||||
describe('extractCivitaiModelUrlParts', () => {
|
||||
it.each(['civitai.com', 'civitai.red'])('rejects download and API URLs on %s', (host) => {
|
||||
for (const path of ['/api/download/models/3390681', '/api/v1/models/3390681', '/models/3390681invalid']) {
|
||||
expect(extractCivitaiModelUrlParts(`https://${host}${path}?modelVersionId=3390681`))
|
||||
.toEqual({ modelId: null, modelVersionId: null });
|
||||
}
|
||||
});
|
||||
it('extracts model and version ids from civitai.red model URLs', () => {
|
||||
expect(
|
||||
extractCivitaiModelUrlParts('https://civitai.red/models/65423/name?modelVersionId=98765')
|
||||
@@ -376,6 +382,12 @@ describe('civitaiUtils', () => {
|
||||
});
|
||||
|
||||
describe('classifyModelRelinkUrl', () => {
|
||||
it.each(['civitai.com', 'civitai.red', 'civarchive.com'])('rejects non-model pages on %s', (host) => {
|
||||
for (const path of ['/api/download/models/3390681', '/api/v1/models/3390681', '/models/3390681invalid']) {
|
||||
expect(classifyModelRelinkUrl(`https://${host}${path}`))
|
||||
.toEqual({ source: null, modelId: null, modelVersionId: null });
|
||||
}
|
||||
});
|
||||
it('classifies civitai.com model URLs', () => {
|
||||
expect(
|
||||
classifyModelRelinkUrl('https://civitai.com/models/649516/name?modelVersionId=726676')
|
||||
|
||||
@@ -199,6 +199,26 @@ async def test_get_model_versions_raises_on_not_found(monkeypatch, downloader):
|
||||
await client.get_model_versions("missing")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("payload", ["Resource not found", {"error": "No model with id 3390681"}])
|
||||
async def test_get_model_versions_not_found_explains_id_and_access(payload, downloader, caplog):
|
||||
downloader.make_request = AsyncMock(return_value=(False, payload))
|
||||
client = await CivitaiClient.get_instance()
|
||||
|
||||
with caplog.at_level("INFO"), pytest.raises(ResourceNotFoundError) as exc_info:
|
||||
await client.get_model_versions("3390681")
|
||||
|
||||
message = str(exc_info.value)
|
||||
assert "3390681" in message
|
||||
assert "/models/<id>" in message
|
||||
assert "modelVersionId" in message
|
||||
assert "/api/download/models/<id>" in message
|
||||
assert "API key" in message
|
||||
assert "no longer available" not in caplog.text
|
||||
downloader.make_request.assert_awaited_once_with(
|
||||
"GET", f"{client.base_url}/models/3390681", use_auth=True
|
||||
)
|
||||
|
||||
|
||||
async def test_get_model_versions_raises_on_nested_not_found(monkeypatch, downloader):
|
||||
async def fake_make_request(method, url, use_auth=True, **kwargs):
|
||||
return False, {"error": {"message": "Resource not found"}}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from py.utils.civitai_utils import (
|
||||
build_license_flags,
|
||||
extract_civitai_image_id,
|
||||
@@ -8,6 +10,13 @@ from py.utils.civitai_utils import (
|
||||
resolve_license_payload,
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize("host", ["civitai.com", "civitai.red"])
|
||||
@pytest.mark.parametrize("path", ["/api/download/models/3390681", "/api/v1/models/3390681", "/models/3390681invalid"])
|
||||
def test_extract_civitai_model_url_parts_rejects_non_model_pages(host, path):
|
||||
assert extract_civitai_model_url_parts(
|
||||
f"https://{host}{path}?modelVersionId=3390681"
|
||||
) == (None, None)
|
||||
|
||||
|
||||
def test_resolve_license_payload_defaults():
|
||||
payload, flags = resolve_license_info({})
|
||||
|
||||
Reference in New Issue
Block a user