From 186521392d357f842c576832e0dc55c7374ae10b Mon Sep 17 00:00:00 2001 From: hajimi Date: Sat, 13 Jun 2026 00:33:38 +0800 Subject: [PATCH] deploy: auto commit repo-root changes 2026-06-13 00:33:38 --- docker/crawler/ai_comment_dispatch.py | 10 ++-- .../crawler/tests/test_ai_comment_dispatch.py | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/docker/crawler/ai_comment_dispatch.py b/docker/crawler/ai_comment_dispatch.py index 2301bd2..2b5fc96 100644 --- a/docker/crawler/ai_comment_dispatch.py +++ b/docker/crawler/ai_comment_dispatch.py @@ -625,15 +625,10 @@ class AiCommentRepository: for index in range(1, target_count + 1): persona = self._persona_for_index(index) account = f"{BOT_ACCOUNT_PREFIX}{index:04d}" - nickname = self._build_bot_nickname(index) row = indexed.get(index) if row: - if row["nickname"] != nickname: - cursor.execute( - f"UPDATE `{self.prefix}user` SET nickname=%s, update_time=%s WHERE id=%s", - (nickname, now, row["id"]), - ) continue + nickname = self._build_bot_nickname(index) password = self._create_password(self._random_password(), salt) sn = self._create_user_sn(cursor) cursor.execute( @@ -651,7 +646,8 @@ class AiCommentRepository: for row in rows: index = self._parse_account_index(row["account"]) persona = self._persona_for_index(index) - users.append(VirtualUser(int(row["id"]), row["account"], self._build_bot_nickname(index), persona["key"])) + nickname = str(row.get("nickname") or "").strip() or self._build_bot_nickname(index) + users.append(VirtualUser(int(row["id"]), row["account"], nickname, persona["key"])) self._virtual_users_cache = list(users) return users[:target_count] diff --git a/docker/crawler/tests/test_ai_comment_dispatch.py b/docker/crawler/tests/test_ai_comment_dispatch.py index 33e19fc..8798224 100644 --- a/docker/crawler/tests/test_ai_comment_dispatch.py +++ b/docker/crawler/tests/test_ai_comment_dispatch.py @@ -80,6 +80,32 @@ class FakeClient: ) +class RecordingCursor: + def __init__(self): + self.executed = [] + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc, tb): + return False + + def execute(self, sql, params=None): + self.executed.append((sql, params)) + + +class RecordingConnection: + def __init__(self): + self.cursor_obj = RecordingCursor() + self.commits = 0 + + def cursor(self): + return self.cursor_obj + + def commit(self): + self.commits += 1 + + class AiCommentDispatchTest(unittest.TestCase): def test_merge_candidates_merges_selection_sources_by_target(self): merged = merge_candidates( @@ -217,6 +243,29 @@ class AiCommentDispatchTest(unittest.TestCase): self.assertNotIn("·", nickname) self.assertGreaterEqual(len(nickname), 3) + def test_existing_virtual_user_nickname_comes_from_user_table(self): + repo = AiCommentRepository.__new__(AiCommentRepository) + repo.prefix = "la_" + repo.conn = RecordingConnection() + repo._virtual_users_cache = None + repo._settings_cache = None + existing_rows = [ + { + "id": 83, + "account": "ai_comment_0001", + "nickname": "赛点阿泽已手动改名", + "avatar": "/avatar.png", + } + ] + repo._load_virtual_users = lambda limit=None: list(existing_rows) + repo._load_site_config = lambda group, name: "" + + users = repo.ensure_virtual_users(1) + + self.assertEqual(users[0].nickname, "赛点阿泽已手动改名") + executed_sql = "\n".join(sql for sql, _ in repo.conn.cursor_obj.executed) + self.assertNotIn("UPDATE `la_user` SET nickname", executed_sql) + if __name__ == "__main__": unittest.main()