fix(wechat): guard bare page-continuation follow-ups from session loss and memory drift
Memind CI / Test, build, and release guards (push) Failing after 3s
Memind CI / Test, build, and release guards (push) Failing after 3s
Prevent chat-to-page flows like writing a poem then saying "做成页面吧" from opening a fresh session without carried content, failing with a vague error, or letting Memory page-template preferences replace the immediate topic. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import {
|
||||
extractLastSubstantiveAssistantFromConversation,
|
||||
extractSubstantiveAssistantText,
|
||||
filterMemoryForImmediatePageContext,
|
||||
hasExplicitPageSourceReference,
|
||||
isBareImmediatePageCreateRequest,
|
||||
isWechatPageContinuationRepairableError,
|
||||
resolveWechatPageContinuationSource,
|
||||
shouldFailFastWechatPageContinuation,
|
||||
} from './intent/page-continuation-context.mjs';
|
||||
|
||||
test('detects bare vs explicit page continuation phrasing', () => {
|
||||
assert.equal(hasExplicitPageSourceReference('帮我把这首词做成页面'), true);
|
||||
assert.equal(hasExplicitPageSourceReference('帮我吧以上内容做成页面'), true);
|
||||
assert.equal(isBareImmediatePageCreateRequest('帮我做成页面吧'), true);
|
||||
assert.equal(isBareImmediatePageCreateRequest('帮我把这首词做成页面'), false);
|
||||
assert.equal(isBareImmediatePageCreateRequest('帮我做个页面'), false);
|
||||
});
|
||||
|
||||
test('resolveWechatPageContinuationSource prefers carried session content', () => {
|
||||
const poem = '《临江仙·秋思》'.padEnd(60, '词');
|
||||
const resolved = resolveWechatPageContinuationSource({
|
||||
userText: '帮我做成页面吧',
|
||||
carriedSessionContent: poem,
|
||||
});
|
||||
assert.equal(resolved.ok, true);
|
||||
assert.equal(resolved.source, 'carried_session');
|
||||
});
|
||||
|
||||
test('shouldFailFastWechatPageContinuation blocks bare follow-up without source', () => {
|
||||
assert.equal(
|
||||
shouldFailFastWechatPageContinuation({
|
||||
sessionPageContinuation: true,
|
||||
userText: '帮我做成页面吧',
|
||||
}),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
shouldFailFastWechatPageContinuation({
|
||||
sessionPageContinuation: true,
|
||||
userText: '帮我做成页面吧',
|
||||
sessionAssistantContent: '《临江仙·秋思》'.padEnd(60, '。'),
|
||||
}),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('filterMemoryForImmediatePageContext removes page template preferences', () => {
|
||||
const filtered = filterMemoryForImmediatePageContext([
|
||||
{ label: 'preference', text: '用户要求每日新闻页面固定格式' },
|
||||
{ label: 'fact', text: '用户名字是唐' },
|
||||
]);
|
||||
assert.equal(filtered.length, 1);
|
||||
assert.match(filtered[0].text, /唐/);
|
||||
});
|
||||
|
||||
test('extractLastSubstantiveAssistantFromConversation skips short acknowledgements', () => {
|
||||
const text = extractLastSubstantiveAssistantFromConversation([
|
||||
{ role: 'user', content: [{ type: 'text', text: '写首词' }] },
|
||||
{ role: 'assistant', content: [{ type: 'text', text: '好的,我来写。' }] },
|
||||
{
|
||||
role: 'assistant',
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: `《临江仙·秋思》${'昨夜西风凋碧树,独上高楼,望尽天涯路。'.repeat(3)}`,
|
||||
}],
|
||||
},
|
||||
]);
|
||||
assert.match(text, /临江仙/);
|
||||
});
|
||||
|
||||
test('isWechatPageContinuationRepairableError covers fake delivery markers', () => {
|
||||
assert.equal(isWechatPageContinuationRepairableError('stale_session_poisoned_completion'), true);
|
||||
assert.equal(isWechatPageContinuationRepairableError('unknown variant `image_url`'), false);
|
||||
});
|
||||
Reference in New Issue
Block a user