'use strict'; const assert = require('assert'); const { diagnoseSnapshot } = require('../mcp/src/dashboard/business-diagnosis-service'); const snapshot = { accountKey: 'test-account', date: '2026-07-22', summary: { customers: { total: 10, todayNew: 2 }, portraits: { total: 4, coverage: 40, recent7d: 3 }, tags: { total: 6 }, operations: { recent7d: 8 } }, groupOverview: { metrics: { groups: 3, dueItems: 6, completedItems: 2, pendingReview: 2, openFindings: 2, highRisk: 1, openTasks: 1, executionRate: 33, averageHealthScore: 68, averageHealthCoverage: 80 } }, conversations: [ { pendingReply: { id: 'draft-1' }, customerIntelligence: { summary: { openTasks: 2, highAlerts: 1 } } }, { pendingReply: null, customerIntelligence: { summary: { openTasks: 0, highAlerts: 0 } } } ] }; const commerce = diagnoseSnapshot('最近为什么复购下降?', snapshot); assert.equal(commerce.type, 'commerce'); assert(commerce.dataGaps.some(item => item.code === 'NO_TRANSACTION_DATA')); assert.match(commerce.title, /不足以直接判断/); const group = diagnoseSnapshot('哪些群存在投诉风险?', snapshot); assert.equal(group.type, 'group-operations'); assert.equal(group.tone, 'danger'); assert.equal(group.metrics.groupHighRisk, 1); assert.equal(group.actions[0].route, '#group-ops'); const customer = diagnoseSnapshot('哪些客户今天必须跟进?', snapshot); assert.equal(customer.type, 'customer-operations'); assert.equal(customer.metrics.openCustomerTasks, 2); assert.match(customer.summary, /6 位客户缺少完整画像/); assert.equal(customer.actions[0].route, '#customer-ops'); const general = diagnoseSnapshot('今天先做什么?', snapshot); assert.equal(general.type, 'general'); assert.equal(general.tone, 'warning'); assert.equal(general.metrics.pendingReplies, 1); assert.equal(general.evidenceDetails.length, 3); assert.throws(() => diagnoseSnapshot('', snapshot), /缺少经营诊断问题/); process.stdout.write(`${JSON.stringify({ status: 'ok', checks: 15, types: ['commerce', 'group-operations', 'customer-operations', 'general'] }, null, 2)}\n`);