Add page data delivery and publication guards
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { filterMemoriesByQuery } from './memory-legacy-fallback.mjs';
|
||||
import { isMemoryRecallQuestion } from './chat-intent-router.mjs';
|
||||
|
||||
test('filterMemoriesByQuery matches query tokens in memory text', () => {
|
||||
const memories = [
|
||||
{ text: '用户的测试别名是蓝鲸42' },
|
||||
{ text: 'TKMind H5 聊天助手默认回复' },
|
||||
{ text: '无关记忆条目' },
|
||||
];
|
||||
const matched = filterMemoriesByQuery(memories, '我之前让你记住的测试别名是什么');
|
||||
assert.equal(matched.length, 1);
|
||||
assert.match(matched[0].text, /蓝鲸42/);
|
||||
});
|
||||
|
||||
test('isMemoryRecallQuestion matches remember-alias recall prompts', () => {
|
||||
assert.equal(isMemoryRecallQuestion('我之前让你记住的测试别名是什么'), true);
|
||||
assert.equal(isMemoryRecallQuestion('记住的测试别名是什么'), true);
|
||||
});
|
||||
|
||||
test('resolveMemoriesWithLegacyFallback prefers legacy on recall questions', async () => {
|
||||
const { resolveMemoriesWithLegacyFallback } = await import('./memory-legacy-fallback.mjs');
|
||||
const memories = await resolveMemoriesWithLegacyFallback({
|
||||
memoryV2: {
|
||||
async resolve() {
|
||||
return { memories: [{ text: '用户当前登录称呼为John' }] };
|
||||
},
|
||||
},
|
||||
conversationMemoryService: {
|
||||
async listMemories() {
|
||||
return [{ text: '用户的测试别名是蓝鲸42' }];
|
||||
},
|
||||
},
|
||||
userId: 'user-1',
|
||||
query: '我之前让你记住的测试别名是什么?',
|
||||
limit: 5,
|
||||
recallQuestion: true,
|
||||
});
|
||||
assert.match(memories[0].text, /蓝鲸42/);
|
||||
});
|
||||
Reference in New Issue
Block a user