import { renderToStaticMarkup } from 'react-dom/server' import { describe, expect, it, vi } from 'vitest' import { ProductionBindingsView } from './ProductionBindingsSection' import type { ProductionBindings } from './productionBindings' const bindings = (overrides: Partial = {}): ProductionBindings => ({ internal_kb_id: '0b217e8a-2a65-40a3-ab8f-34ac5c7a6f05', external_kb_id: '9a1e5c11-0000-4000-8000-000000000002', internal_kb_name: '对内知识库-wiki', external_kb_name: '对外知识库-wiki', updated_by: 'yaozhanghao', production_base_url: 'https://weknora-test.dobot.cn', production_connected: true, production_message: '', legacy_scope: '文档级发布(单篇文档写生产)· 旧路径', whole_target: { configured: true, source: '部署环境 LIBRARY_PRODUCTION_*', tenant_id: 10000, internal_kb_id: 'a8e9c8ad-411c-4c53-8421-599d29e9b179', external_kb_id: '2e980686-2233-4c4e-b5a6-8b0069477b8e', database: 'pgm-wz9ohr9gk919pr1q.pg.rds.aliyuncs.com:5432/weknora_test', elastic_index: 'weknora_test_chunks', object_bucket: 'dobot-weknora-test', missing_reason: '', }, ...overrides, }) const view = (value: ProductionBindings | null, admin = true) => renderToStaticMarkup( ) describe('ProductionBindingsView', () => { it('把实际整库目标(完整 ID + 端点)显示出来,而不是只显示可编辑的文档级绑定', () => { const html = view(bindings()) expect(html).toContain('整库发布目标(实际写入,只读)') // 完整 ID 必须可读:截断会让操作者核对不了 a8e9c8ad 与 0b217e8a 的区别。 expect(html).toContain('a8e9c8ad-411c-4c53-8421-599d29e9b179') expect(html).toContain('2e980686-2233-4c4e-b5a6-8b0069477b8e') expect(html).toContain('pgm-wz9ohr9gk919pr1q.pg.rds.aliyuncs.com:5432/weknora_test') expect(html).toContain('weknora_test_chunks') expect(html).toContain('dobot-weknora-test') expect(html).toContain('部署环境 LIBRARY_PRODUCTION_*') }) it('旧文档级绑定标成旧路径,不再声称"发布写入此库"', () => { const html = view(bindings()) expect(html).toContain('文档级发布(单篇文档写生产)· 旧路径') expect(html).toContain('仅文档级发布读取这组绑定;整库发布(封存/同步/恢复)不读它。') expect(html).toContain('对内文档级目标') expect(html).not.toContain('发布写入此库') }) it('整库目标缺配置:点名缺哪个环境变量,且不拿文档级绑定顶上去', () => { const html = view( bindings({ whole_target: { configured: false, source: '部署环境 LIBRARY_PRODUCTION_*', tenant_id: 0, internal_kb_id: '', external_kb_id: '', database: '(未配置)', elastic_index: '', object_bucket: '', missing_reason: '未配置:LIBRARY_PRODUCTION_DATABASE_URL、LIBRARY_PRODUCTION_KB_INTERNAL', }, }) ) expect(html).toContain('LIBRARY_PRODUCTION_DATABASE_URL') expect(html).toContain('整库目标配置不全') // 文档级绑定仍然显示,但必须仍是"文档级"身份,不能冒充整库目标。 expect(html).toContain('对内文档级目标') }) it('非管理员看得到目标,但没有保存入口', () => { const html = view(bindings(), false) expect(html).toContain('a8e9c8ad-411c-4c53-8421-599d29e9b179') expect(html).not.toContain('保存文档级目标') expect(html).toContain('仅管理员可修改文档级发布目标') }) })