diff --git a/apps/api/src/modules/mail/__tests__/mail-store.it.test.ts b/apps/api/src/modules/mail/__tests__/mail-store.it.test.ts index 1114d97..1a17506 100644 --- a/apps/api/src/modules/mail/__tests__/mail-store.it.test.ts +++ b/apps/api/src/modules/mail/__tests__/mail-store.it.test.ts @@ -72,7 +72,13 @@ describe.skipIf(database === undefined)('mail store(真 PG)', () => { expect((await store.get('acc-a'))?.isDefault).toBe(false); expect((await store.get('acc-b'))?.isDefault).toBe(true); expect((await store.findByName('甲'))?.id).toBe('acc-a'); - expect((await store.list()).map((a) => a.id)).toEqual(['acc-a', 'acc-b']); + /* + * 排序键是 name(与 channel / llm 两个 store 同惯例:这份清单是运营面给人看的账号列表)。 + * 中文名的先后依 PG 的 collation 而定 —— 本机 en_US.utf8 与 alpine 的 C 都按码点把「乙」排在「甲」前, + * 而 ICU 的中文 collation 按拼音会反过来。所以这里断言**集合**,不断言序: + * 这条用例要验的是「两个账号都回来了」,不是「谁在前」。 + */ + expect((await store.list()).map((a) => a.id).sort()).toEqual(['acc-a', 'acc-b']); }); it('游标 jsonb 存取回来还是同一形;savePoll 只改给了的列', async () => { diff --git a/apps/api/src/modules/mail/internal/adapter/mail-store.ts b/apps/api/src/modules/mail/internal/adapter/mail-store.ts index ecaa63d..f7a3765 100644 --- a/apps/api/src/modules/mail/internal/adapter/mail-store.ts +++ b/apps/api/src/modules/mail/internal/adapter/mail-store.ts @@ -78,13 +78,7 @@ function accountValues(record: MailAccountRecord): typeof mailAccountTable.$infe export function createMailAccountStore(db: Db): MailAccountStore { return { async list() { - /* - * 按 id 排序,不按 name:name 是人填的中文,数据库默认 collation(en_US.utf8/C) - * 按码点比较,不是拼音 —— 「甲」(U+7532)反而排在「乙」(U+4E59)后面, - * 与直觉「甲比乙靠前」相反(实测钉住,brief 原按 name 排序在本机会导致 - * 账号:save/get/findByName/list 那条用例的 list() 顺序断言失败)。id 排序稳定、不受地域字符集影响。 - */ - const rows = await db.select().from(mailAccountTable).orderBy(mailAccountTable.id); + const rows = await db.select().from(mailAccountTable).orderBy(mailAccountTable.name); return rows.map(toAccount); }, async get(id) {