smoke-package.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env node
  2. const path = require('path');
  3. const { runXiaohongshuTrend } = require('../mcp/src/tools/xiaohongshu-trend-run');
  4. const { updateXiaohongshuPreference } = require('../mcp/src/tools/xiaohongshu-preference-update');
  5. const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
  6. const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');
  7. const ROOT = path.resolve(__dirname, '..');
  8. const OUTPUT_ROOT = path.resolve(ROOT, 'outputs', 'claude-code-package-smoke');
  9. const MEMORY_PATH = path.join(OUTPUT_ROOT, 'xiaohongshu-trend-memory.json');
  10. async function smokeMcpTools() {
  11. const client = new Client({
  12. name: 'voc-intelligence-package-smoke',
  13. version: '0.1.2'
  14. });
  15. const transport = new StdioClientTransport({
  16. command: process.execPath,
  17. args: ['mcp/src/server.js'],
  18. cwd: ROOT,
  19. stderr: 'pipe'
  20. });
  21. await client.connect(transport);
  22. try {
  23. const tools = await client.listTools();
  24. return tools.tools.map(tool => tool.name);
  25. } finally {
  26. await client.close();
  27. }
  28. }
  29. async function main() {
  30. const sample = await runXiaohongshuTrend({
  31. collectionMode: 'sample',
  32. profile: path.join(ROOT, 'memory-templates', 'xiaohongshu-trend-profile.json'),
  33. output: path.join(OUTPUT_ROOT, 'sample')
  34. });
  35. if (sample.status !== 'ok') {
  36. throw new Error(`sample failed: ${sample.status}`);
  37. }
  38. const preference = await updateXiaohongshuPreference({
  39. message: '保留奶油风和全屋定制翻车方向,不要纯风格美图,下一版更偏门店转化话术',
  40. memory: MEMORY_PATH
  41. });
  42. if (preference.status !== 'ok') {
  43. throw new Error(`preference failed: ${preference.status}`);
  44. }
  45. const withMemory = await runXiaohongshuTrend({
  46. collectionMode: 'sample',
  47. profile: path.join(ROOT, 'memory-templates', 'xiaohongshu-trend-profile.json'),
  48. memory: MEMORY_PATH,
  49. output: path.join(OUTPUT_ROOT, 'with-memory')
  50. });
  51. if (withMemory.status !== 'ok' || !withMemory.summary.preferenceMemoryApplied) {
  52. throw new Error('sample-with-memory did not apply preference memory');
  53. }
  54. const toolNames = await smokeMcpTools();
  55. const requiredTools = [
  56. 'voc_xiaohongshu_token_check',
  57. 'voc_xiaohongshu_trend_run',
  58. 'voc_xiaohongshu_preference_update'
  59. ];
  60. for (const tool of requiredTools) {
  61. if (!toolNames.includes(tool)) {
  62. throw new Error(`missing MCP tool: ${tool}`);
  63. }
  64. }
  65. console.log(JSON.stringify({
  66. status: 'ok',
  67. checks: [
  68. 'sample report',
  69. 'preference memory',
  70. 'sample report with memory',
  71. 'MCP tools'
  72. ],
  73. mcpTools: toolNames,
  74. reportPreview: String(withMemory.assistantMessage || '').split('\n').slice(0, 8).join('\n'),
  75. files: withMemory.files
  76. }, null, 2));
  77. }
  78. main().catch(error => {
  79. console.error(JSON.stringify({
  80. status: 'error',
  81. message: error.message
  82. }, null, 2));
  83. process.exit(1);
  84. });