Files
memind/chat-task-intent-config.test.mjs
T

57 lines
2.1 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict';
import test from 'node:test';
import {
isChatSessionDeferEnabledForUser,
isDirectEscalationContextEnabledForUser,
resolveChatSessionDeferPolicy,
resolveDirectEscalationContextPolicy,
shouldDeferChatSessionRoutingToLlm,
} from './chat-task-intent-config.mjs';
test('resolveDirectEscalationContextPolicy defaults to disabled', () => {
const policy = resolveDirectEscalationContextPolicy({});
assert.equal(policy.enabled, false);
assert.equal(policy.canaryUserIds.size, 0);
});
test('isDirectEscalationContextEnabledForUser respects canary list', () => {
const policy = {
enabled: true,
canaryUserIds: new Set(['user-a']),
};
assert.equal(isDirectEscalationContextEnabledForUser('user-a', policy), true);
assert.equal(isDirectEscalationContextEnabledForUser('user-b', policy), false);
});
test('shouldDeferChatSessionRoutingToLlm skips explicit direct chat text', () => {
assert.equal(shouldDeferChatSessionRoutingToLlm({
enabled: true,
text: '你好',
isExplicitDirectChatOnlyText: (value) => value === '你好',
}), false);
assert.equal(shouldDeferChatSessionRoutingToLlm({
enabled: true,
text: '帮我研究一下车载冰箱的参数和选购建议',
minTextLength: 12,
isExplicitDirectChatOnlyText: () => false,
}), true);
assert.equal(shouldDeferChatSessionRoutingToLlm({
enabled: false,
text: '帮我研究一下车载冰箱的参数和选购建议',
isExplicitDirectChatOnlyText: () => false,
}), false);
});
test('resolveChatSessionDeferPolicy parses min text length', () => {
const policy = resolveChatSessionDeferPolicy({
MEMIND_CHAT_ROUTER_CHAT_SESSION_DEFER_ENABLED: '1',
MEMIND_CHAT_ROUTER_CHAT_SESSION_DEFER_MIN_TEXT_LENGTH: '20',
MEMIND_CHAT_ROUTER_CHAT_SESSION_DEFER_CANARY_USER_IDS: 'john',
});
assert.equal(policy.enabled, true);
assert.equal(policy.minTextLength, 20);
assert.deepEqual([...policy.canaryUserIds], ['john']);
assert.equal(isChatSessionDeferEnabledForUser('john', policy), true);
assert.equal(isChatSessionDeferEnabledForUser('other', policy), false);
});