Files
LWLT-AI/archive/handoff/2026-07-12/legacy-erp-handoff/tools/tests/hermes_weixin_source.test.js
2026-07-13 19:57:46 +08:00

47 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const source = require('../hermes_weixin_source');
test('parseInboundWeixinLine extracts sender and chat ids', () => {
const entry = source.parseInboundWeixinLine(
"2026-06-20 22:48:50,823 INFO gateway.run: inbound message: platform=weixin user=o9cq807rsTpn95TrggbxwaMWWg8Q@im.wechat chat=o9cq807rsTpn95TrggbxwaMWWg8Q@im.wechat msg='下单模式:散拼-拼单/录入子单;订单性质:测试' reply_to_id=None reply_to_text=''"
);
assert.equal(entry.senderId, 'o9cq807rsTpn95TrggbxwaMWWg8Q@im.wechat');
assert.equal(entry.chatId, 'o9cq807rsTpn95TrggbxwaMWWg8Q@im.wechat');
assert.match(entry.messageSnippet, /散拼/);
});
test('findLatestSource matches a recent order against Hermes agent log', () => {
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-weixin-source-'));
const logPath = path.join(tmp, 'agent.log');
const orderText = [
'下单模式:散拼-拼单/录入子单',
'订单性质:测试',
'母团号LW-260830A-A',
].join('\n');
fs.writeFileSync(
logPath,
[
"2026-06-20 22:40:00,000 INFO gateway.run: inbound message: platform=weixin user=old@im.wechat chat=old@im.wechat msg='下单模式:团队-批量下单 订单性质:测试' reply_to_id=None reply_to_text=''",
"2026-06-20 22:48:50,823 INFO gateway.run: inbound message: platform=weixin user=o9cq807rsTpn95TrggbxwaMWWg8Q@im.wechat chat=o9cq807rsTpn95TrggbxwaMWWg8Q@im.wechat msg='下单模式:散拼-拼单/录入子单 订单性质:测试 母团号LW-260830A-A' reply_to_id=None reply_to_text=''",
].join('\n'),
'utf8'
);
const result = source.findLatestSource({
orderText,
logPath,
maxAgeMinutes: 60,
nowMs: Date.parse('2026-06-20T23:00:00+08:00'),
});
assert.equal(result.ok, true);
assert.equal(result.senderId, 'o9cq807rsTpn95TrggbxwaMWWg8Q@im.wechat');
});