94 lines
4.2 KiB
TypeScript
94 lines
4.2 KiB
TypeScript
/**
|
|
* shared/utils/agent-registry.utils.test.ts
|
|
*
|
|
* 用途:锁定 Agent Registry 前端读取契约,防止回退到名称白名单。
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
AGENT_CODE_SHIPPING_NOTICE,
|
|
agentHasIntentUiProfile,
|
|
agentHasProgress,
|
|
agentHasTaskProgress,
|
|
agentProgressRequiresScheduleTask,
|
|
agentUsesScheduleRunCounterProgress,
|
|
agentUsesWorkspaceStepperProgress,
|
|
canUseLeaveFeature,
|
|
isHrFocusedAgent,
|
|
isShippingNoticeAgent,
|
|
resolveAgentContentProfileKey,
|
|
resolveAgentCode,
|
|
resolveIntentRoutes,
|
|
resolveProgressContract,
|
|
} from './agent-registry.utils';
|
|
|
|
describe('agent-registry.utils', () => {
|
|
it('resolveAgentCode prefers column over name', () => {
|
|
expect(resolveAgentCode({ name: '货代发货通知 Agent', agent_code: AGENT_CODE_SHIPPING_NOTICE })).toBe(
|
|
AGENT_CODE_SHIPPING_NOTICE,
|
|
);
|
|
expect(resolveAgentCode({ name: '货代发货通知 Agent' })).toBe('generic');
|
|
});
|
|
|
|
it('isShippingNoticeAgent uses agent_code only', () => {
|
|
expect(isShippingNoticeAgent({ name: '智能发货通知Agent', agent_code: AGENT_CODE_SHIPPING_NOTICE })).toBe(true);
|
|
expect(isShippingNoticeAgent({ name: '货代发货通知 Agent' })).toBe(false);
|
|
});
|
|
|
|
it('agentHasTaskProgress requires strict true on capabilities column', () => {
|
|
expect(agentHasTaskProgress({ agent_code: 'file_check' })).toBe(false);
|
|
expect(agentHasTaskProgress({ capabilities: { task_progress: true } })).toBe(true);
|
|
expect(agentHasTaskProgress({ capabilities: { task_progress: false } })).toBe(false);
|
|
});
|
|
|
|
it('canUseLeaveFeature reads leave_feature_enabled from server', () => {
|
|
expect(canUseLeaveFeature({ leave_feature_enabled: true })).toBe(true);
|
|
expect(canUseLeaveFeature({ name: '人事规章' })).toBe(false);
|
|
});
|
|
|
|
it('isHrFocusedAgent reads hr_focused_avatar from server', () => {
|
|
expect(isHrFocusedAgent({ hr_focused_avatar: true })).toBe(true);
|
|
expect(isHrFocusedAgent({ hr_focused_avatar: false })).toBe(false);
|
|
});
|
|
|
|
it('resolveAgentContentProfileKey prefers content_profile_key from server', () => {
|
|
expect(resolveAgentContentProfileKey({ content_profile_key: 'generic_entrance' })).toBe('generic_entrance');
|
|
expect(resolveAgentContentProfileKey({ content_profile_key: 'hr_policy' })).toBe('hr_policy');
|
|
expect(resolveAgentContentProfileKey({
|
|
handler_config: { content_profile: 'hr_policy' },
|
|
})).toBe('hr_policy');
|
|
expect(resolveIntentRoutes({ handler_config: { intent_routes: ['text2sql'] } })).toEqual(new Set(['text2sql']));
|
|
});
|
|
|
|
it('agentHasIntentUiProfile checks intent_ui_profiles from server', () => {
|
|
expect(agentHasIntentUiProfile({ intent_ui_profiles: ['maintenance'] }, 'maintenance')).toBe(true);
|
|
expect(agentHasIntentUiProfile({ intent_ui_profiles: [] }, 'maintenance')).toBe(false);
|
|
});
|
|
|
|
it('resolveProgressContract and helpers distinguish file_check vs shipping_notice', () => {
|
|
const fileCheckContract = {
|
|
enabled: true,
|
|
data_source: { type: 'schedule_run' as const },
|
|
presentation: { layout: 'card' as const, visualization: 'counter' as const },
|
|
binding: { requires_schedule_task: true },
|
|
};
|
|
const shippingContract = {
|
|
enabled: true,
|
|
data_source: { type: 'domain_state' as const, domain: 'shipping_notice' },
|
|
presentation: { layout: 'workspace' as const, visualization: 'stepper' as const },
|
|
binding: { requires_schedule_task: false },
|
|
};
|
|
const fileCheckAgent = { capabilities: { task_progress: true }, progress_contract: fileCheckContract };
|
|
const shippingAgent = { capabilities: { task_progress: true }, progress_contract: shippingContract };
|
|
|
|
expect(resolveProgressContract(fileCheckAgent)).toEqual(fileCheckContract);
|
|
expect(agentHasProgress(fileCheckAgent)).toBe(true);
|
|
expect(agentProgressRequiresScheduleTask(fileCheckAgent)).toBe(true);
|
|
expect(agentUsesScheduleRunCounterProgress(fileCheckAgent)).toBe(true);
|
|
expect(agentUsesWorkspaceStepperProgress(fileCheckAgent)).toBe(false);
|
|
|
|
expect(agentProgressRequiresScheduleTask(shippingAgent)).toBe(false);
|
|
expect(agentUsesWorkspaceStepperProgress(shippingAgent)).toBe(true);
|
|
expect(agentUsesScheduleRunCounterProgress(shippingAgent)).toBe(false);
|
|
});
|
|
});
|