8f91c52c67
Introduce help escalation persistence, cursor help worker processing, optional OpenAI-compatible chat bridge, and page delivery remediation. Co-authored-by: Cursor <cursoragent@cursor.com>
97 lines
3.5 KiB
JavaScript
97 lines
3.5 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
HELP_ESCALATION_ACK_TEXT,
|
|
HELP_ESCALATION_DETAILS_PROMPT,
|
|
HELP_ESCALATION_STATUS,
|
|
buildHelpEscalationPrompt,
|
|
extractHelpEscalationProblemText,
|
|
extractHelpEscalationPagePath,
|
|
extractHelpEscalationText,
|
|
hasHelpEscalationProblemDescription,
|
|
isHelpEscalationIntent,
|
|
normalizeHelpEscalationCommandText,
|
|
parseHelpEscalationAgentResult,
|
|
} from './help-escalation.mjs';
|
|
|
|
test('isHelpEscalationIntent matches help commands', () => {
|
|
assert.equal(isHelpEscalationIntent('help 我的页面打不开'), true);
|
|
assert.equal(isHelpEscalationIntent('/help'), true);
|
|
assert.equal(isHelpEscalationIntent('帮助 定时任务没推送'), true);
|
|
assert.equal(isHelpEscalationIntent('help,页面打不开'), true);
|
|
assert.equal(isHelpEscalationIntent('please help me build a page'), false);
|
|
assert.equal(isHelpEscalationIntent('hello'), false);
|
|
});
|
|
|
|
test('hasHelpEscalationProblemDescription requires concrete problem text', () => {
|
|
assert.equal(hasHelpEscalationProblemDescription('help'), false);
|
|
assert.equal(hasHelpEscalationProblemDescription('/help'), false);
|
|
assert.equal(hasHelpEscalationProblemDescription('帮助'), false);
|
|
assert.equal(hasHelpEscalationProblemDescription('help 页面 409'), true);
|
|
assert.equal(extractHelpEscalationProblemText('help,页面打不开'), '页面打不开');
|
|
assert.match(HELP_ESCALATION_DETAILS_PROMPT, /补充具体问题/);
|
|
});
|
|
|
|
test('isHelpEscalationIntent matches help after H5 identity prefix', () => {
|
|
const prefixed = [
|
|
'[用户身份]',
|
|
'- 当前登录用户称呼:John',
|
|
'',
|
|
'help 这个链接无法打开 http://127.0.0.1:5173/foo.html',
|
|
].join('\n');
|
|
assert.equal(isHelpEscalationIntent(prefixed), true);
|
|
assert.equal(
|
|
normalizeHelpEscalationCommandText(prefixed),
|
|
'help 这个链接无法打开 http://127.0.0.1:5173/foo.html',
|
|
);
|
|
});
|
|
|
|
test('extractHelpEscalationText reads goose message content', () => {
|
|
assert.equal(
|
|
extractHelpEscalationText({
|
|
content: [{ type: 'text', text: 'help 页面 409' }],
|
|
}),
|
|
'help 页面 409',
|
|
);
|
|
});
|
|
|
|
test('buildHelpEscalationPrompt includes ticket context', () => {
|
|
const prompt = buildHelpEscalationPrompt({
|
|
id: 'esc-1',
|
|
userId: 'user-1',
|
|
channel: 'wechat_mp',
|
|
userText: 'help 页面打不开',
|
|
context: { agentSessionId: 'sess-1', openid: 'wx-1' },
|
|
}, { memindRoot: '/tmp/Memind' });
|
|
assert.match(prompt, /esc-1/);
|
|
assert.match(prompt, /help 页面打不开/);
|
|
assert.match(prompt, /sess-1/);
|
|
});
|
|
|
|
test('parseHelpEscalationAgentResult reads trailing json', () => {
|
|
const parsed = parseHelpEscalationAgentResult([
|
|
'已修复 delivery 契约并补发链接。',
|
|
'{"status":"succeeded","userMessage":"你的新闻页已恢复,请重新打开链接。"}',
|
|
].join('\n'));
|
|
assert.equal(parsed.status, HELP_ESCALATION_STATUS.SUCCEEDED);
|
|
assert.match(parsed.userMessage, /已恢复/);
|
|
});
|
|
|
|
test('parseHelpEscalationAgentResult falls back to stdout text', () => {
|
|
const parsed = parseHelpEscalationAgentResult('已重启 goosed 并恢复 Portal。');
|
|
assert.equal(parsed.status, HELP_ESCALATION_STATUS.SUCCEEDED);
|
|
assert.match(parsed.userMessage, /重启 goosed/);
|
|
});
|
|
|
|
test('extractHelpEscalationPagePath reads public html path', () => {
|
|
assert.equal(
|
|
extractHelpEscalationPagePath('help 链接失败 public/spring-poem.html', {}),
|
|
'public/spring-poem.html',
|
|
);
|
|
assert.equal(
|
|
extractHelpEscalationPagePath('help', { relativePath: 'public/tang-dynasty.html' }),
|
|
'public/tang-dynasty.html',
|
|
);
|
|
});
|