import test from 'node:test' import assert from 'node:assert/strict' import { createRequire } from 'node:module' const require = createRequire(import.meta.url) const { normalizeConfig, selectMediaBatchItems, parseDigestSummary, buildDigestHtml } = require('../lib/digest-builder.js') test('normalizeConfig 默认关闭自动发微信并收敛数值边界', () => { const cfg = normalizeConfig({ windowHours: 999, renderWidth: 100, groupIds: ['g1@chatroom', 'g1@chatroom'] }) assert.equal(cfg.autoSendWechat, false) assert.equal(cfg.windowHours, 168) assert.equal(cfg.renderWidth, 320) assert.deepEqual(cfg.groupIds, ['g1@chatroom']) }) test('selectMediaBatchItems 按权限筛选图片 OCR/视觉与语音转写批次', () => { const messages = [ { type: 'text', messageRef: 'ref-1', text: '早安' }, { type: 'image', messageRef: 'ref-img' }, { type: 'voice', messageRef: 'ref-voice' } ] const items = selectMediaBatchItems( messages, normalizeConfig({ enableImageOcr: true, enableVoiceTranscribe: true, maxMediaPerGroup: 5 }), ['media.ocr', 'media.transcribe'] ) assert.equal(items.length, 2) assert.equal(items[0].op, 'transcribeVoice') assert.equal(items[1].op, 'ocrImage') }) test('buildDigestHtml 转义 HTML 特殊字符且不包含脚本或外链', () => { const summary = parseDigestSummary( JSON.stringify({ headline: '今日焦点', highlights: ['项目评审通过'], actionItems: ['张三跟进上线'], groupBriefs: [{ groupName: '产品测试群', summary: '讨论了发布排期' }] }) ) const html = buildDigestHtml({ dateLabel: '2026-12-01', ...summary, totalMessages: 42, totalMediaResolved: 3, groupCount: 1 }) assert.equal(/