import { readFileSync } from 'fs'; import { describe, expect, it } from 'vitest'; const bindingsMigration = readFileSync( new URL('../../migrations/20261031_main_supplier_bindings.sql', import.meta.url), 'utf8' ); const fixMigration = readFileSync( new URL('../../migrations/20261041_main_supplier_bindings_backfill_source.sql', import.meta.url), 'utf8' ); const svc = readFileSync(new URL('../src/services/branchAccessCode.ts', import.meta.url), 'utf8'); const page = readFileSync( new URL('../../src/pages/system/BranchManagement.tsx', import.meta.url), 'utf8' ); const zhSystem = readFileSync(new URL('../../src/i18n/locales/zh-CN/system.ts', import.meta.url), 'utf8'); const enSystem = readFileSync(new URL('../../src/i18n/locales/en/system.ts', import.meta.url), 'utf8'); const idSystem = readFileSync(new URL('../../src/i18n/locales/id/system.ts', import.meta.url), 'utf8'); /** * 缺陷 D1/D2 —— 见 docs/design/20261013-主系统订单被本地拉取机制与绑定缺陷.md。 * D1:迁移回填的绑定行 `source` 必须与"超管手工登记"可区分(设计 V10)⇒ 用 `backfill`。 * D2:绑定弹层时间必须按本地时区显示(此前直接切 UTC 字符串 ⇒ 差 8 小时)。 */ describe('迁移回填绑定的 source 标注(D1)与绑定弹层时间(D2)', () => { it('20261031 回填行标为 backfill,不再写 manual;服务层类型允许 backfill', () => { expect(bindingsMigration).toContain("'backfill'"); expect(bindingsMigration).not.toMatch(/'active',\s*'manual'/); expect(bindingsMigration).toContain( 'backfill=迁移回填(存量兼容' ); expect(svc).toContain("'main_push' | 'main_pull' | 'manual' | 'backfill'"); }); it('新增迁移把存量回填行回标(幂等、按 note 精确识别、不误伤手工行)', () => { expect(fixMigration).toContain("SET source = 'backfill'"); expect(fixMigration).toContain("WHERE source = 'manual'"); expect(fixMigration).toContain("note LIKE '迁移回填%'"); // 只改 source 一列:不该出现删改其它列的语句 expect(fixMigration).not.toMatch(/DELETE\s+FROM\s+public\.main_supplier_bindings/i); }); it('绑定弹层时间改按本地时区(不再 slice(0,19) 切 UTC)', () => { expect(page).not.toContain(".slice(0, 19).replace('T', ' ')"); expect(page).toContain('toLocaleString(UI_LOCALE_BCP47[locale])'); }); }); /** * G1 可见性(2026-10-13):绑定弹层加「来源」列,让运营一眼看出这条绑定是谁加的 * (主系统同步 / 迁移回填 / 超管手工登记)——邮件到本次排查的痛点(看不出绑定从哪来)。 */ describe('绑定弹层「来源」列(G1 可见性)', () => { it('页面按 source 标注来源,并给通配行一句说明', () => { expect(page).toContain("t('system.branches.bindings.col.source')"); expect(page).toContain('bindingSourceLabel'); expect(page).toContain("s === 'main_push' || s === 'main_pull'"); expect(page).toContain("t('system.branches.bindings.wildcardHint')"); }); it('三语都有来源列与三类来源的文案', () => { for (const [name, src] of [ ['zh-CN', zhSystem], ['en', enSystem], ['id', idSystem], ] as const) { for (const key of [ 'branches.bindings.col.source', 'branches.bindings.source.mainSync', 'branches.bindings.source.backfill', 'branches.bindings.source.manual', 'branches.bindings.wildcardHint', ]) { expect(src, `${name} 缺 ${key}`).toContain(key); } } }); });