| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 'use strict';
- const assert = require('node:assert/strict');
- const fs = require('fs');
- const os = require('os');
- const path = require('path');
- const { buildLegacySkillPlans } = require('../mcp/src/features/voc-cost/skill-planner-adapter');
- const {
- compareEstimateToActual,
- appendCalibrationSample,
- readHistory,
- summarizeCalibration
- } = require('../mcp/src/features/voc-cost/cost-calibration');
- function main() {
- const root = path.resolve(__dirname, '..', '..', '..');
- const xhsConfig = path.join(root, 'openclaw-skills', 'xiaohongshu', 'xiaohongshu-mini-voc', 'api-config.json');
- const plans = buildLegacySkillPlans({
- skillConfigPath: xhsConfig,
- keywords: ['甲', '乙', '丙'],
- notesPerKeyword: 2,
- maxCommentPages: 2,
- includeUserInfo: true
- });
- assert.equal(plans.length, 3);
- assert.equal(plans[0].operations.find(operation => operation.path.includes('search-notes')).count, 3);
- assert.equal(plans[1].operations.find(operation => operation.path.includes('note-detail')).count, 6);
- assert.equal(plans[1].operations.find(operation => operation.path.includes('note-comments')).count, 12);
- assert.equal(plans[0].operations.some(operation => operation.path.includes('user-info')), false);
- assert.equal(plans[1].operations.some(operation => operation.path.includes('user-info')), true);
- const ecomPlans = buildLegacySkillPlans({
- skillConfig: {
- name: 'legacy-ecom-fixture',
- category: 'ecommerce',
- pipeline: [{ step: 1, name: '商品详情', forEach: 'products', api: { channel: 'ecommerce', endpoint: 'product.detail', method: 'GET' } }]
- },
- productCount: 2,
- mode: 'standard'
- });
- assert.equal(ecomPlans[0].operations[0].model, 'voc-ecom');
- const estimate = {
- workflowType: 'legacy_skill:xiaohongshu-mini-voc',
- selectedMode: 'standard',
- plans: [{
- mode: 'standard',
- expectedCny: 10,
- operations: [{ path: 'xhs.search', costCny: 4 }, { path: 'xhs.detail', costCny: 6 }]
- }]
- };
- const actual = {
- workflowType: estimate.workflowType,
- totals: { costCny: 12 },
- rows: [{ path: 'xhs.search', costCny: 4 }, { path: 'xhs.detail', costCny: 8 }]
- };
- const sample = compareEstimateToActual(estimate, actual);
- assert.equal(sample.status, 'calibrated');
- assert.equal(sample.deltaCny, 2);
- assert.equal(sample.deltaPct, 20);
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'voc-cost-calibration-'));
- const historyPath = path.join(tmp, 'calibration.json');
- appendCalibrationSample(historyPath, sample);
- const summary = summarizeCalibration(readHistory(historyPath));
- assert.equal(summary.sampleCount, 1);
- assert.equal(summary.actualCny, 12);
- console.log('legacy skill planner and cost calibration smoke passed');
- }
- try {
- main();
- } catch (error) {
- console.error(error.stack || error);
- process.exitCode = 1;
- }
|