business-diagnosis-smoke-test.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. const assert = require('assert');
  3. const { diagnoseSnapshot } = require('../mcp/src/dashboard/business-diagnosis-service');
  4. const snapshot = {
  5. accountKey: 'test-account',
  6. date: '2026-07-22',
  7. summary: {
  8. customers: { total: 10, todayNew: 2 },
  9. portraits: { total: 4, coverage: 40, recent7d: 3 },
  10. tags: { total: 6 },
  11. operations: { recent7d: 8 }
  12. },
  13. groupOverview: {
  14. metrics: {
  15. groups: 3,
  16. dueItems: 6,
  17. completedItems: 2,
  18. pendingReview: 2,
  19. openFindings: 2,
  20. highRisk: 1,
  21. openTasks: 1,
  22. executionRate: 33,
  23. averageHealthScore: 68,
  24. averageHealthCoverage: 80
  25. }
  26. },
  27. conversations: [
  28. { pendingReply: { id: 'draft-1' }, customerIntelligence: { summary: { openTasks: 2, highAlerts: 1 } } },
  29. { pendingReply: null, customerIntelligence: { summary: { openTasks: 0, highAlerts: 0 } } }
  30. ]
  31. };
  32. const commerce = diagnoseSnapshot('最近为什么复购下降?', snapshot);
  33. assert.equal(commerce.type, 'commerce');
  34. assert(commerce.dataGaps.some(item => item.code === 'NO_TRANSACTION_DATA'));
  35. assert.match(commerce.title, /不足以直接判断/);
  36. const group = diagnoseSnapshot('哪些群存在投诉风险?', snapshot);
  37. assert.equal(group.type, 'group-operations');
  38. assert.equal(group.tone, 'danger');
  39. assert.equal(group.metrics.groupHighRisk, 1);
  40. assert.equal(group.actions[0].route, '#group-ops');
  41. const customer = diagnoseSnapshot('哪些客户今天必须跟进?', snapshot);
  42. assert.equal(customer.type, 'customer-operations');
  43. assert.equal(customer.metrics.openCustomerTasks, 2);
  44. assert.match(customer.summary, /6 位客户缺少完整画像/);
  45. assert.equal(customer.actions[0].route, '#customer-ops');
  46. const general = diagnoseSnapshot('今天先做什么?', snapshot);
  47. assert.equal(general.type, 'general');
  48. assert.equal(general.tone, 'warning');
  49. assert.equal(general.metrics.pendingReplies, 1);
  50. assert.equal(general.evidenceDetails.length, 3);
  51. assert.throws(() => diagnoseSnapshot('', snapshot), /缺少经营诊断问题/);
  52. process.stdout.write(`${JSON.stringify({ status: 'ok', checks: 15, types: ['commerce', 'group-operations', 'customer-operations', 'general'] }, null, 2)}\n`);