Peach: Local-first video metadata scraper and media manager.
fix(avatar): 优先清晰档案照并合并重复头像候选
longmeidaoc2ee8001f9b9
diff --git a/docs/REUSE.md b/docs/REUSE.mdindex 4a6c5303d..d3ff27c1f 100644--- a/docs/REUSE.md+++ b/docs/REUSE.md@@ -308,8 +308,8 @@ A 盘垃圾隔离使用短名称 `peach-purge-<32 位 UUID>.peach-quarantine`,- 番号取封面(`POST /api/avatar-code-cover` → `avatar_picker.code_cover`)不要求番号在馆藏:本机封面目录优先,没有才走 `jav_cover_fetch.best_cover`,按番号只存对象、不写证据,之后的 `cover:<番号>` 只读本机。- 默认框围着 `avatar_picker.cover_focus` 取景:有脸取 `avatar_cover_face.face_square`(要边车里有脸宽与 `px`,缺的 `detect_cover_faces.py --redo`),没脸取 `jav_poster_crop` 的正封,前端不另抄判据。- 整张作品封面不装成头像:单人作品关联不证明画面里是谁,`cover_fallback` 标身份未核实,采集脚本的安装闸门拒收。图库给不出唯一人像时,补头像后继(`peach.avatar_followup`)从单人作品封面截脸周围一块方图(`peach.avatar_cover_face`,YuNet 脸框放大 2.4 倍),按脸宽像素挑封面、最差是缩略图,其余检得出脸的封面各截一张进候选缓存(至多 8 张)。面具、眼罩照样算脸,检不出的不降门槛去捞(低分框多落在手和身体上)。来源记 `cover-face` 与 `identity_verified: false`。- - 图库同名多张时先按脸认人(`peach.face_match`,互证与小图作证见 ADR-0056、0057、0062、0066),认不出才截封面;封面也截不出时装认得准的那张小图,标 `gallery_small`,之后可换。- - 整张封面装的头像和截过的脸遇到更宽的脸自动替换,图库装的与人挑的不碰;头像选择器的作品组按封面像素面积排序。+ - 图库同名多张时先按脸认人(`peach.face_match`,互证与小图作证见 ADR-0056、0057、0062、0066);短边至少 300 像素的档案小图优先于封面裁片(ADR-0102),更小的图在封面落空时兜底。身份判据复用 `match_gallery`,来源标 `gallery_small`,可升级至标准图库人像。+ - 自动封面头像可换为合格档案人像或更清晰封面,人挑的不碰;候选列表按本机内容及默认裁切哈希去重,保留在用状态、具体来源与作品全部底图。展示去重不参与身份判断,不联网取图,不删除历史缓存。- 外部来源 genre 只在 `peach.genre_taxonomy` 投影:JavDB `類別` 与日英来源词共用词表,非内容分类排除,未收录原文回传登记;查表只有 `resolve_genre` 一处,抓取与复核折叠共用。r18dev 取 `categories[].name_ja`,日文取不到才用英文。有码标签的来源选择复用 `metadata_policy.preferred_tag_source(code)`,排序、采集与复核一致;替换走 `metadata_auto_apply` 的来源归属与人工判断保护(ADR-0100),不另写直写流程。- 一件事只留一个标签名:`catalog_rules.RETIRED_TAGS` 存「不该再用的写法 → 规范名」,唯一写入口是 `scripts/rename_retired_tags.py --apply --backup`,实体按 `entities.merge_entity` 并、旧名留作别名;`pixiv_tag` 是作者原话,不参与。规范名取馆藏通行写法(`合集` 来自文件名,`混合集` 全来自已关停的 Stash 导入,ADR-0021)。- 手动添加标签复用 `current_tags`,API 返回规范名,详情缓存、最近使用与撤销沿用该名称。`core/tags.ts` 保留 `OL制服`、`JK制服` 完整名称,制服归外观,`秘书OL` 归角色;词表审查见 [标签词表审查](reference-snapshots/tag-vocabulary-audit.md)。diff --git a/docs/STATUS.md b/docs/STATUS.mdindex e8f006de7..b224e4dde 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -11,12 +11,12 @@- 核查:`peach-data/review/creator-boundary-delivery.md`;StraplessDildo 归厂牌。- 关注作者 25 位、来源 111 条、身份关联 71 条、别名 30 条(ADR-0096)。- 身份合并 18 组;版本核查:`peach-data/review/version-evidence-review.md`。-- JAV 头像 816 张,38 张水印待复核;17 位档案、253 张头像候选、2 张官方封面。+- JAV 头像 816,水印待复核 38;档案 17、候选 253、官方封面 2;[选图规则](adr/0102-profile-avatar-priority.md)。- 「整理」(ADR-0039)支持预览、执行、回滚;英文视频名分词 169 条。- 产地是独立维度、JAV 是其投影:`region` 空时按厂牌、创作者、番号逐层推断,不落库;韩国 MIB 不算 JAV。- Windows 托盘自动恢复,重启用 `restart_windows_tray.py --source`;代码与数据在内置盘,媒体在外置盘。- 托盘须普通权限启动:提权令牌看不到 CloudDrive 的 `A:`/`B:`,误报脱盘。-- Windows:80 跳 HTTPS,LAN:443;`peach-win`、`0.38.0`。10-10 重启,CA、健康、前端产物通过。+- Windows:80→HTTPS、LAN:443;`peach-win`、`0.38.0`。CA、健康通过。- 主界面 `peach-app.js/css`,登录、配置页 `peach-pages.js/css`。- `/healthz` 报 `configurable=true`;配置与选目录共用连接判据,托盘管理 HTTPS 地址、端口及重载。- 首启、配置页列缺失依赖(CloudDrive、挂载驱动、FFmpeg/ffprobe、OpenSSL);Windows 识别 CloudDrive、WinFsp。diff --git a/docs/adr/0102-profile-avatar-priority.md b/docs/adr/0102-profile-avatar-priority.mdnew file mode 100644index 000000000..3a6e5349c--- /dev/null+++ b/docs/adr/0102-profile-avatar-priority.md@@ -0,0 +1,28 @@+# ADR-0102:清晰档案小图优先于封面裁片++- 状态:Accepted+- 日期:2026-10-11+- 修订:ADR-0066 的小图安装次序与替换规则++## 依据++用户确认 `深美みりあ` 的 Minnano 350×350 档案照可以接受,并要求优先于 204×204 的作品封面裁片。用户还指出同一图以“图库/来源”和“封面人脸/作品”各占一格的重复现象。本机核对见数据根 `review/fukami-avatar-audit.json`。++## 决策++自动选择依次尝试标准图库人像、短边至少 300 像素的档案小图、单人作品封面截脸与馆外互证封面,最后才是更小的图库兜底。300 像素复用标准头像的短边下限;不降低标准图库的长边门槛。++身份判据保持一致:唯一合格名字命中沿用名字核对,多张同名候选仍须封面或图库互证。小图选择复用 `match_gallery`,小图证人不受安装尺寸限制。手选头像和标准图库头像保留,自动封面裁片可以被合格档案小图替换;合格档案小图保留到有标准图库人像可用。`gallery_small` 继续记录来源类型,`MATCH_RULE=7` 让既有自动兜底记录按新判据复核。++候选列表仅按本机字节哈希和既有裁切函数的输出哈希去重:整图框选产生的重编副本、封面默认裁片与其历史项共用一格;不同裁切仍各占一格。在用状态保留,优先显示具体图库来源或作品番号;作品的封面、九宫格及历史裁片保留为框选底图。原图、历史缓存和人工选择不删除。++展示去重不参与自动身份判定,避免把同名的多来源记录压成“唯一候选”。列表不为去重请求外部图片,不引入感知哈希或新的识别模型。++## 影响面与验收++- 数据与契约:无 schema、ledger 真相字段或 API 字段修改;只调整头像后继与候选列表。+- 页面:共用换头像弹层接收去重列表,既有框选底图承载历史;无布局或样式修改。+- 反向状态:人工选择保留,历史图可重新框选;清晰小图可升级至标准图库人像。+- 回归:覆盖 350×350 优先、自动裁片替换、同名核验、手选保护、尺寸边界、整图重编去重、局部裁切保留及作品底图完整性。+- 运行核验、桌面与 390×844 视口证据保存在数据根 `review/avatar-profile-priority-verification/`。+- 复用:沿用 Pillow 裁切、尺寸校验、Gfriends 名字链与既有 SFace 身份核验,无新增依赖。身份与来源优先级属于 Peach 领域规则。diff --git a/src/peach/avatar_followup.py b/src/peach/avatar_followup.pyindex e246b09fa..28643095f 100644--- a/src/peach/avatar_followup.py+++ b/src/peach/avatar_followup.py@@ -20,9 +20,10 @@* 馆里一张单人作品封面都截不出脸时(只有合集的那些人),按她的 avwikidb 编号读站上的单人作品,从馆外那几部的 DMM 封面上截脸,两部不同作品的脸互相过线才装(ADR-0074,`avatar_offsite_cover_face`)。装上的和馆藏封面截的同一档。-* 两档都落空、图库里只有没过尺寸门槛的小图时,装认得准的那张小图(ADR-0066):只有一张+* 图库里认得准、短边至少 300 像素的小图优先于封面截脸(ADR-0102);只有一张就装它,+ 多张仍按同一套互证判据挑。更小的图在图库与封面都落空时兜底(ADR-0066):只有一张就装它,好几张照同一套互证判据挑,认定的几张里挑像素最大的。小图同样可以在上面几档里- 作证,只是不当那张被装上的图。这一档装的图之后有了过门槛的图或封面人脸就换掉。+ 作证;清晰小图可升级至标准图库人像,更小的兜底可替换为封面人脸。* **个人博主**(过 `work_portrait_predicate` 的发布账号)不查图库,只从自己独占作品的画面上截脸(`avatar_cover_face.sheet_faces`,接触印相九格加有封面的那张):两部不同作品截出的脸互相过线才装,判据与馆外单人作品封面同一条(ADR-0074、ADR-0099)。情侣号、@@ -72,6 +73,8 @@ MAX_MATCH_CANDIDATES = 24NEAR_DUPLICATE = 0.9#: 小图兜底那一档装上的图,头像边车里记的 `source_kind`。SMALL_SOURCE_KIND = "gallery_small"+#: 可优先于封面裁片的档案小图,沿用标准图库头像的短边下限。+PROFILE_MIN_SIDE = MIN_SHORT_SIDE#: 派出之后账号分类被改、不再过 `work_portrait_predicate` 时的结论。它取决于分类而不是作品,#: 不记进 `Attempts`:分类改回来时照常再派。NO_IDENTITY = "账号没有本人身份依据"@@ -179,8 +182,9 @@ _OFFSITE_COUNT = ("(SELECT count(*) FROM entity_external_ref x WHERE x.entity_id#: 认人判据的版本,进指纹。改了判据就加一:存量里缺图的女优按新判据各重比一次。#: 2 是 ADR-0057 的图库互证,3 是 ADR-0062 没有封面参照时的图库自证,4 是 ADR-0066 的-#: 小图作证与兜底,5 是 ADR-0070 的小脸裁切放大再比,6 是 ADR-0074 的馆外单人作品封面。-MATCH_RULE = 6+#: 小图作证与兜底,5 是 ADR-0070 的小脸裁切放大再比,6 是 ADR-0074 的馆外单人作品封面,+#: 7 是 ADR-0102 的清晰档案小图优先。+MATCH_RULE = 7def _fingerprint(works, aliases, offsite) -> str:@@ -278,7 +282,7 @@ def _run(contract, key: str, handle) -> dict:entity_id, name, cropped_px)# 图库索引只读本地缓存,这一步不联网;联网只发生在要量、要比、要装那几张的时候。listing = avatar_picker.choices(connection, providers_root, avatar_root,- kind, entity_id)+ kind, entity_id, deduplicate=False)found = [choice for choice in listing["choices"]if choice["source"] == "gfriends"]handle.progress(label=f"{TASK_LABEL}:{name}", throttle=0)@@ -291,17 +295,10 @@ def _run(contract, key: str, handle) -> dict:probe = FaceProbe()covers = avatar_cover_face.faces(connection, contract.cover_root, entity_id, probe)- extra: dict = {}- if len(found) > 1:- matched = _install_matched(contract, connection, providers_root, avatar_root,- kind, entity_id, name, found, covers)- if matched["outcome"] == "已装上":- return matched- gallery = matched["outcome"]- extra = {key: value for key, value in matched.items()- if key == "face_match_unavailable"}- else:- gallery = "图库里没有这个名字" if not found else "图库那张太小"+ preferred, gallery, extra = _preferred_gallery(+ contract, connection, providers_root, avatar_root, kind, entity_id, name, found, covers)+ if preferred is not None:+ return preferredfallen = {**_install_cover_face(contract, providers_root, avatar_root, kind,entity_id, name, gallery, len(found), cropped_px,covers, probe), **extra}@@ -316,6 +313,31 @@ def _run(contract, key: str, handle) -> dict:entity_id, found, covers, fallen)+def _preferred_gallery(contract, connection, providers_root, avatar_root, kind: str,+ entity_id: int, name: str, found: list[dict], covers: list+ ) -> tuple[dict | None, str, dict]:+ """多来源身份核验与清晰小图选择;返回安装结果或封面兜底所需的结论。"""+ extra: dict = {}+ if len(found) > 1:+ matched = _install_matched(contract, connection, providers_root, avatar_root,+ kind, entity_id, name, found, covers)+ if matched["outcome"] == "已装上":+ return matched, "", extra+ gallery = matched["outcome"]+ extra = {key: value for key, value in matched.items()+ if key == "face_match_unavailable"}+ else:+ gallery = "图库里没有这个名字" if not found else "图库那张太小"+ if found and not extra:+ profile = _install_small(contract, connection, providers_root, avatar_root, kind,+ entity_id, found, covers, {"name": name, "outcome": gallery},+ min_side=PROFILE_MIN_SIDE)+ if (profile["outcome"] in ("已装上", "已装着认得准的小图")+ or profile.get("face_match_unavailable")):+ return profile, gallery, extra+ return None, gallery, extra++@dataclass(frozen=True)class Candidate:"""一张取来、量过的图库候选。"""@@ -342,7 +364,7 @@ class GalleryMatch:def match_gallery(found: list[dict], covers: list, matcher,fetch: Callable[[dict], Candidate | None], *,- allow_small: bool = False) -> GalleryMatch:+ allow_small: bool = False, min_small_side: int = 0) -> GalleryMatch:"""图库里这几张候选,哪一张是她本人(ADR-0056)。只读:取图交给 `fetch`,不写任何东西。参照是她单人作品封面上截到的脸,按脸宽取前 `MATCH_COVERS` 张;候选要和其中@@ -390,8 +412,9 @@ def match_gallery(found: list[dict], covers: list, matcher,}def eligible(candidate: Candidate) -> bool:- return allow_small or acceptable_avatar(candidate.inspected, MIN_LONG_SIDE,- MIN_SHORT_SIDE)+ return (acceptable_avatar(candidate.inspected, min_small_side, min_small_side)+ if allow_small else acceptable_avatar(candidate.inspected, MIN_LONG_SIDE,+ MIN_SHORT_SIDE))for choice in found[:MAX_MATCH_CANDIDATES]:candidate = fetch(choice)@@ -564,8 +587,9 @@ def _install(contract, connection, providers_root, avatar_root, kind: str,def _install_small(contract, connection, providers_root, avatar_root, kind: str,- entity_id: int, found: list[dict], covers: list, fallen: dict) -> dict:- """图库和封面都给不出过门槛的那一张时,装认得准的那张小图(ADR-0066)。+ entity_id: int, found: list[dict], covers: list, fallen: dict, *,+ min_side: int = 0) -> dict:+ """装认得准且满足本档尺寸下限的小图(ADR-0066、0102)。`柊木なな` 两部作品都是多人封面,图库里只有 199×299 与 470×470 两张,余弦 0.42:两张认得同一个人,装 470×470 那张,比首字母占位强。`fallen` 是上一档的摘要,这一档@@ -580,7 +604,7 @@ def _install_small(contract, connection, providers_root, avatar_root, kind: str,winner, evidence = fetch(found[0]), {}else:result = match_gallery(found, covers, face_match.FaceMatcher(), fetch,- allow_small=True)+ allow_small=True, min_small_side=min_side)if result.unavailable:return {**fallen, "face_match_unavailable": True}winner, evidence = result.winner, result.evidence@@ -588,7 +612,7 @@ def _install_small(contract, connection, providers_root, avatar_root, kind: str,close = getattr(transport, "close", None)if close:close()- if winner is None:+ if winner is None or not acceptable_avatar(winner.inspected, min_side, min_side):return fallensize = f"{winner.inspected.width}×{winner.inspected.height}"if winner.inspected.sha256 == avatar_picker.installed_digest(avatar_root, kind, entity_id):diff --git a/src/peach/avatar_picker.py b/src/peach/avatar_picker.pyindex 4d6296970..ed0fff574 100644--- a/src/peach/avatar_picker.py+++ b/src/peach/avatar_picker.py@@ -23,7 +23,7 @@ import jsonimport sqlite3import urllib.parsefrom collections.abc import Callable-from dataclasses import dataclass+from dataclasses import dataclass, replacefrom pathlib import Pathfrom . import gfriends, images, jav_poster_crop@@ -433,7 +433,7 @@ def typed_address(url: str, providers_root: Path, fetch: Callable[[str], bytes],def choices(connection: sqlite3.Connection, providers_root: Path,avatar_root: Path, kind: str, entity_id: int,- cover_root: Path | None = None) -> dict:+ cover_root: Path | None = None, *, deduplicate: bool = True) -> dict:"""页面要展示的一切:图库同名候选、取过的历史、当前装着的是哪一张。索引只读本地缓存。联网补索引是批处理的事——为一次点击同步拉 6 MB,页面会卡在@@ -477,6 +477,8 @@ def choices(connection: sqlite3.Connection, providers_root: Path,listed = items[:MAX_CHOICES]if cover_root is not None:listed += asset_artwork(connection, cover_root, entity_id)+ if deduplicate:+ listed = _distinct_choices(listed, providers_root, cover_root)age = gfriends.index_age(index_dir)return {"kind": kind, "entity_id": int(entity_id),@@ -487,6 +489,64 @@ def choices(connection: sqlite3.Connection, providers_root: Path,}+def _distinct_choices(items: list[Choice], providers_root: Path,+ cover_root: Path | None) -> list[Choice]:+ """同一张本机图片及其默认裁片共用一格,作品底图仍可进入框选。++ 只比缓存字节与同一裁切函数的输出哈希,不联网、不做相似人脸猜测。+ 图库的整图框选会重编 JPEG,所以它与来源原图的字节哈希可以不同。+ """+ groups: list[tuple[Choice, set[str]]] = []+ rank = {"asset": 0, "gfriends": 1, "history": 2}+ for choice in items:+ body = None+ if choice.source == "gfriends":+ category, _, filename = choice.ref.partition(":")[2].partition("/")+ body = AvatarCandidateCache(providers_root / GFRIENDS_CACHE).lookup(+ gfriends.image_url(category, filename))+ elif choice.source == "history":+ body = _object_bytes(providers_root, choice.ref.partition(":")[2])+ elif choice.source == "asset" and cover_root is not None and choice.ref.endswith(":cover"):+ # 作品组已核对归属;文件名取列表中真实番号,不从客户端 ref 推断路径。+ key = artwork_key(int(choice.ref.split(":")[1]), choice.label)+ path = Path(cover_root) / f"{key}.jpg"+ try:+ body = path.read_bytes()+ except OSError:+ pass+ keys = {f"ref:{choice.ref}"}+ if body is not None:+ upright = images.upright(body)+ box = choice.focus+ if box is None:+ keys.add(hashlib.sha256(body).hexdigest())+ size = images.measure_image_size(upright)+ box = (0, 0, *size) if size else None+ cut = images.crop_to_box(upright, box) if box else None+ if cut is not None:+ keys.add(hashlib.sha256(cut).hexdigest())+ overlapping = [index for index, (_, existing) in enumerate(groups) if keys & existing]+ if not overlapping:+ groups.append((choice, keys))+ continue+ first = overlapping[0]+ merged = [groups[index][0] for index in overlapping] + [choice]+ winner = min(merged, key=lambda item: rank.get(item.source, 3))+ bases = list(winner.bases)+ if winner.source == "asset":+ bases = list(dict.fromkeys([*bases, *(item.ref for item in merged)]))+ details = list(dict.fromkeys(text for item in merged for text in (item.detail, item.label)+ if text and text != winner.label))+ winner = replace(winner, current=any(item.current for item in merged),+ bases=tuple(bases), detail=" · ".join(details))+ for index in overlapping:+ keys.update(groups[index][1])+ groups[first] = (winner, keys)+ for index in reversed(overlapping[1:]):+ groups.pop(index)+ return sorted((choice for choice, _ in groups), key=lambda choice: not choice.current)++def _object_bytes(providers_root: Path, digest: str) -> bytes | None:"""按内容哈希在各来源目录里找那张图的字节;找不到或读不出就是 None。diff --git a/tests/test_avatar_picker.py b/tests/test_avatar_picker.pyindex 1280dd225..04835ff10 100644--- a/tests/test_avatar_picker.py+++ b/tests/test_avatar_picker.py@@ -330,6 +330,30 @@ class ChoiceTests(PickerFixture):self.assertTrue(stale["index_stale"])self.assertEqual(stale["index_age_hours"], round(old / 3600, 1))+ def test_a_full_frame_library_crop_has_one_choice_and_keeps_current(self):+ body = picture(350, 350, "purple")+ url = gfriends.image_url("7-S1", "葵つかさ.jpg")+ self.remember(body, provider="gfriends", url=url)+ cut, origin = avatar_picker.crop(body, {"x0": 0, "y0": 0, "x1": 350, "y1": 350})+ avatar_picker.install(self.providers, self.avatars, "performer", 7792, cut,+ {**origin, "provider": "gfriends", "upstream_url": url})+ listed = self.listed()["choices"]+ self.assertEqual([one["ref"] for one in listed if one["current"]], [LIBRARY_REF])+ self.assertEqual(listed[0]["label"], "S1")+ self.assertEqual(len(listed), 3)++ def test_a_partial_library_crop_remains_a_distinct_composition(self):+ body = picture(350, 350, "purple")+ url = gfriends.image_url("7-S1", "葵つかさ.jpg")+ self.remember(body, provider="gfriends", url=url)+ cut, origin = avatar_picker.crop(body, {"x0": 50, "y0": 50, "x1": 300, "y1": 300})+ avatar_picker.install(self.providers, self.avatars, "performer", 7792, cut,+ {**origin, "provider": "gfriends", "upstream_url": url})+ listed = self.listed()["choices"]+ self.assertEqual(len(listed), 4)+ self.assertEqual(listed[0]["ref"], f"sha256:{inspect_avatar(cut).sha256}")+ self.assertIn(LIBRARY_REF, [one["ref"] for one in listed])+class AssetArtworkTests(PickerFixture):"""从本人作品的画面里框头像:列哪些作品、谁递得进来、切出来是什么。"""@@ -572,6 +596,27 @@ class CoverFocusTests(AssetArtworkTests):"performer", 7792, cover_root=self.covers)return next(one for one in listed["choices"] if one["source"] == "asset")["focus"]+ def test_a_cover_crop_and_its_work_share_a_choice_with_all_bases(self):+ self.add_asset(11, "ABW-232")+ image = Image.open(io.BytesIO(self.cover.read_bytes()))+ ImageDraw.Draw(image).rectangle((315, 60, 330, 90), fill="red")+ image.save(self.cover, format="JPEG")+ record = face_record(400, 260)+ sidecar_path(self.cover).write_text(json.dumps(record), "utf-8")+ box = avatar_picker.cover_focus("ABW-232", self.cover, record, 400, 260)+ from peach.images import crop_to_box+ body = crop_to_box(self.cover.read_bytes(), box)+ avatar_picker.install(self.providers, self.avatars, "performer", 7792, body,+ {"provider": "cover-face", "source_kind": "cover_face_crop",+ "upstream_url": "peach:cover-face/ABW-232"})+ listed = avatar_picker.choices(self.connection, self.providers, self.avatars,+ "performer", 7792, cover_root=self.covers)["choices"]+ current = [one for one in listed if one["current"]]+ self.assertEqual([one["ref"] for one in current], ["asset:11:cover"])+ self.assertIn("asset:11:cell4", current[0]["bases"])+ self.assertIn(f"sha256:{inspect_avatar(body).sha256}", current[0]["bases"])+ self.assertEqual(len(listed), 4)+def test_a_detected_face_frames_the_same_square_the_batch_would_cut(self):self.add_asset(11, "ABW-232")sidecar_path(self.cover).write_text(json.dumps(face_record(400, 260)), "utf-8")@@ -643,13 +688,18 @@ class CoverFocusTests(AssetArtworkTests):self.assertEqual(next(one for one in listed["choices"]if one["source"] == "asset")["cast"], 1)- def test_a_whole_shared_cover_kept_by_the_batch_skips_the_face_too(self):+ def test_a_whole_shared_cover_shares_the_work_and_skips_the_face(self):self.add_asset(11, "ABW-232")self.co_star(11)sidecar_path(self.cover).write_text(json.dumps(face_record(400, 260)), "utf-8")- choice = self.whole_cover_history()+ self.remember(picture(400, 260, "green"), provider="cover-fallback",+ external_id="ABW-232")+ listed = avatar_picker.choices(self.connection, self.providers, self.avatars,+ "performer", 7792, cover_root=self.covers)+ choice = next(one for one in listed["choices"] if one["source"] == "asset")self.assertEqual((choice["cast"], choice["focus"]),(2, {"x0": 217, "y0": 0, "x1": 400, "y1": 260}))+ self.assertFalse(any(one["source"] == "history" for one in listed["choices"]))class CodeCoverTests(PickerFixture):diff --git a/tests/test_followups.py b/tests/test_followups.pyindex 95a65581c..adac42269 100644--- a/tests/test_followups.py+++ b/tests/test_followups.py@@ -837,7 +837,7 @@ class FaceMatchFollowupTests(FaceStubCase):limit=10)]with self.database.read_connection() as connection:- self.assertEqual(fingerprint(connection, self.person), "1:0:0:r6")+ self.assertEqual(fingerprint(connection, self.person), "1:0:0:r7")self.run_followup()self.assertEqual(planned(), [])with self.database.write_transaction(notify=False) as connection:@@ -845,7 +845,7 @@ class FaceMatchFollowupTests(FaceStubCase):"INSERT INTO entity_alias(entity_id,alias,normalized_alias,source)"" VALUES(?,?,?,'test')", (self.person, "りな", "りな"))with self.database.read_connection() as connection:- self.assertEqual(fingerprint(connection, self.person), "1:1:0:r6")+ self.assertEqual(fingerprint(connection, self.person), "1:1:0:r7")self.assertEqual(planned(), [followup_key("performer", self.person)])def test_a_small_picture_vouches_for_a_big_one_without_a_cover(self):@@ -876,6 +876,44 @@ class FaceMatchFollowupTests(FaceStubCase):self.run_followup()self.assertFalse((self.avatars / f"performer-{self.person}.img").exists())+ def test_a_350_pixel_profile_is_preferred_to_a_cover_face(self):+ ref = self.candidate("y-Minnano", (350, 350), self.HER)+ self.work(1, "IPX-001", self.HER)+ self.assertEqual(self.run_followup()["size"], "350×350")+ self.assertEqual(f"gfriends:{self.provenance()['external_id']}", ref)+ self.assertEqual(self.run_followup()["outcome"], "已装着认得准的小图")++ def test_a_profile_can_replace_an_automatic_cover_crop(self):+ self.work(1, "IPX-001", self.HER)+ self.run_followup()+ self.assertEqual(self.provenance()["provider"], "cover-face")+ self.candidate("y-Minnano", (350, 350), self.HER)+ self.run_followup()+ self.assertEqual(self.provenance()["provider"], "gfriends")++ def test_profile_priority_requires_identity_matching_for_shared_names(self):+ ref = self.candidate("y-AVDC", (350, 350), self.HER)+ self.candidate("y-Minnano", (450, 450), self.OTHER)+ self.work(1, "IPX-001", self.HER)+ self.run_followup()+ self.assertEqual(f"gfriends:{self.provenance()['external_id']}", ref)+ self.assertEqual(self.provenance()["name_source"], "face-match")++ def test_a_manual_crop_is_preserved_with_a_profile_candidate(self):+ from peach import avatar_picker+ body = self.picture((204, 204), self.HER_AGAIN)+ avatar_picker.install(self.providers, self.avatars, "performer", self.person, body,+ {"provider": "gfriends", "source_kind": "user_cropped"})+ self.candidate("y-Minnano", (350, 350), self.HER)+ self.assertEqual(self.run_followup()["outcome"], "已有头像")+ self.assertEqual((self.avatars / f"performer-{self.person}.img").read_bytes(), body)++ def test_a_profile_smaller_than_300_pixels_remains_a_cover_fallback(self):+ self.candidate("y-Minnano", (299, 350), self.HER)+ self.work(1, "IPX-001", self.HER)+ self.run_followup()+ self.assertEqual(self.provenance()["provider"], "cover-face")+def test_a_cover_face_replaces_a_small_picture_later(self):from peach.avatar_followup import stockfrom peach.followups import Attempts, attempts_root@@ -1062,11 +1100,11 @@ class OffsiteCoverFaceTests(FaceStubCase):self.compilation(1, "DVAJ-495")self.run_followup()with self.database.read_connection() as connection:- self.assertEqual(fingerprint(connection, self.person), "1:0:0:r6")+ self.assertEqual(fingerprint(connection, self.person), "1:0:0:r7")self.assertEqual(planned(), [])self.bind()with self.database.read_connection() as connection:- self.assertEqual(fingerprint(connection, self.person), "1:0:1:r6")+ self.assertEqual(fingerprint(connection, self.person), "1:0:1:r7")self.assertEqual(planned(), [key])