5c3f8ebd70
The headline bug: aliases created from the modal NEVER resolved. Create
sent the normalized display name ('Sword', 'Uchiha Sasuke') while
resolution keys on the raw booru model key ('sword', 'uchiha_sasuke',
case-sensitive) — so the mapping was stored under a key nothing looks up,
and the prediction kept reappearing unaliased. The raw key wasn't even in
the /suggestions response, so the modal couldn't send it.
- Suggestion now carries raw_name (the model key an alias must use) and
via_alias (surfaced via an operator alias); both serialized by the API.
- Modal alias-create sends raw_name, not display_name (the fix). Aliased
suggestions show an 'alias' badge and a 'Remove alias' action; 'Treat as
alias for…' is hidden for centroid hits (no model key) and already-aliased
rows.
- Tag-side management: TagCard ⋮ → 'Aliases…' opens a dialog listing the
model keys that fold into a tag, with remove (GET /api/tags/<id>/aliases +
AliasService.list_for_tag). Creation stays in the modal suggestion flow.
Tests: full API round-trip locking the raw-key contract (raw_name exposed →
alias authored with it → resolves + via_alias on a later image);
list_for_tag (service + API); via_alias/raw_name on the existing service
suggestion tests. No migration.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
import pytest
|
|
|
|
from backend.app.models import TagKind
|
|
from backend.app.services.tag_service import TagService
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_list_delete(client, db):
|
|
tag = await TagService(db).find_or_create("Canon", TagKind.character)
|
|
await db.commit()
|
|
|
|
resp = await client.post(
|
|
"/api/aliases",
|
|
json={
|
|
"alias_string": "model_name",
|
|
"alias_category": "character",
|
|
"canonical_tag_id": tag.id,
|
|
},
|
|
)
|
|
assert resp.status_code == 201
|
|
|
|
resp = await client.get("/api/aliases")
|
|
body = await resp.get_json()
|
|
assert any(
|
|
a["alias_string"] == "model_name"
|
|
and a["canonical_tag_name"] == "Canon"
|
|
for a in body
|
|
)
|
|
|
|
resp = await client.delete("/api/aliases/model_name/character")
|
|
assert resp.status_code == 204
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_requires_fields(client):
|
|
resp = await client.post("/api/aliases", json={"alias_string": "x"})
|
|
assert resp.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_for_tag_endpoint(client, db):
|
|
tag = await TagService(db).find_or_create("TagSide", TagKind.character)
|
|
await db.commit()
|
|
await client.post(
|
|
"/api/aliases",
|
|
json={
|
|
"alias_string": "ts_key",
|
|
"alias_category": "character",
|
|
"canonical_tag_id": tag.id,
|
|
},
|
|
)
|
|
|
|
resp = await client.get(f"/api/tags/{tag.id}/aliases")
|
|
assert resp.status_code == 200
|
|
body = await resp.get_json()
|
|
assert body == [{"alias_string": "ts_key", "alias_category": "character"}]
|
|
|
|
assert (await client.get("/api/tags/99999999/aliases")).status_code == 404
|