11import { describe , it , expect , vi } from "vitest" ;
22import { ToolRegistry } from "./tool_registry" ;
3- import type { ToolExecutor , ToolSource } from "./tool_registry" ;
3+ import type { ToolExecutor } from "./tool_registry" ;
44import type { ToolCall , ToolDefinition , ToolResultWithAttachments } from "./types" ;
55import type { AgentChatRepo } from "@App/app/repo/agent_chat" ;
66
@@ -439,13 +439,20 @@ describe("ToolRegistry", () => {
439439 describe ( "来源追踪 API(register / getSource / listBySource / unregisterBySource)" , ( ) => {
440440 it ( "register 注册工具后 getSource 应返回正确来源" , ( ) => {
441441 const registry = new ToolRegistry ( ) ;
442- registry . register ( "mcp" , weatherDef , createExecutor ( async ( ) => "ok" ) ) ;
442+ registry . register (
443+ "mcp" ,
444+ weatherDef ,
445+ createExecutor ( async ( ) => "ok" )
446+ ) ;
443447 expect ( registry . getSource ( "get_weather" ) ) . toBe ( "mcp" ) ;
444448 } ) ;
445449
446450 it ( "registerBuiltin 注册的工具来源应为 builtin" , ( ) => {
447451 const registry = new ToolRegistry ( ) ;
448- registry . registerBuiltin ( weatherDef , createExecutor ( async ( ) => "ok" ) ) ;
452+ registry . registerBuiltin (
453+ weatherDef ,
454+ createExecutor ( async ( ) => "ok" )
455+ ) ;
449456 expect ( registry . getSource ( "get_weather" ) ) . toBe ( "builtin" ) ;
450457 } ) ;
451458
@@ -456,9 +463,21 @@ describe("ToolRegistry", () => {
456463
457464 it ( "listBySource 应只返回指定来源的工具名" , ( ) => {
458465 const registry = new ToolRegistry ( ) ;
459- registry . register ( "builtin" , weatherDef , createExecutor ( async ( ) => "" ) ) ;
460- registry . register ( "mcp" , calcDef , createExecutor ( async ( ) => "" ) ) ;
461- registry . register ( "skill" , { name : "load_skill" , description : "加载 skill" , parameters : { type : "object" , properties : { } } } , createExecutor ( async ( ) => "" ) ) ;
466+ registry . register (
467+ "builtin" ,
468+ weatherDef ,
469+ createExecutor ( async ( ) => "" )
470+ ) ;
471+ registry . register (
472+ "mcp" ,
473+ calcDef ,
474+ createExecutor ( async ( ) => "" )
475+ ) ;
476+ registry . register (
477+ "skill" ,
478+ { name : "load_skill" , description : "加载 skill" , parameters : { type : "object" , properties : { } } } ,
479+ createExecutor ( async ( ) => "" )
480+ ) ;
462481
463482 expect ( registry . listBySource ( "builtin" ) ) . toEqual ( [ "get_weather" ] ) ;
464483 expect ( registry . listBySource ( "mcp" ) ) . toEqual ( [ "calc" ] ) ;
@@ -468,9 +487,21 @@ describe("ToolRegistry", () => {
468487
469488 it ( "unregisterBySource 应批量删除指定来源的工具并返回名称列表" , ( ) => {
470489 const registry = new ToolRegistry ( ) ;
471- registry . register ( "mcp" , weatherDef , createExecutor ( async ( ) => "" ) ) ;
472- registry . register ( "mcp" , calcDef , createExecutor ( async ( ) => "" ) ) ;
473- registry . register ( "builtin" , { name : "web_fetch" , description : "抓取" , parameters : { type : "object" , properties : { } } } , createExecutor ( async ( ) => "" ) ) ;
490+ registry . register (
491+ "mcp" ,
492+ weatherDef ,
493+ createExecutor ( async ( ) => "" )
494+ ) ;
495+ registry . register (
496+ "mcp" ,
497+ calcDef ,
498+ createExecutor ( async ( ) => "" )
499+ ) ;
500+ registry . register (
501+ "builtin" ,
502+ { name : "web_fetch" , description : "抓取" , parameters : { type : "object" , properties : { } } } ,
503+ createExecutor ( async ( ) => "" )
504+ ) ;
474505
475506 const removed = registry . unregisterBySource ( "mcp" ) ;
476507 expect ( removed ) . toHaveLength ( 2 ) ;
@@ -483,13 +514,21 @@ describe("ToolRegistry", () => {
483514
484515 it ( "unregisterBySource 无匹配工具时应返回空数组" , ( ) => {
485516 const registry = new ToolRegistry ( ) ;
486- registry . register ( "builtin" , weatherDef , createExecutor ( async ( ) => "" ) ) ;
517+ registry . register (
518+ "builtin" ,
519+ weatherDef ,
520+ createExecutor ( async ( ) => "" )
521+ ) ;
487522 expect ( registry . unregisterBySource ( "mcp" ) ) . toEqual ( [ ] ) ;
488523 } ) ;
489524
490525 it ( "unregister 应按名称删除工具" , ( ) => {
491526 const registry = new ToolRegistry ( ) ;
492- registry . register ( "mcp" , weatherDef , createExecutor ( async ( ) => "" ) ) ;
527+ registry . register (
528+ "mcp" ,
529+ weatherDef ,
530+ createExecutor ( async ( ) => "" )
531+ ) ;
493532 expect ( registry . unregister ( "get_weather" ) ) . toBe ( true ) ;
494533 expect ( registry . getDefinitions ( ) ) . toHaveLength ( 0 ) ;
495534 } ) ;
@@ -503,7 +542,11 @@ describe("ToolRegistry", () => {
503542 describe ( "withScopedTools" , ( ) => {
504543 it ( "fn 正常执行后应清理所有 scoped 工具" , async ( ) => {
505544 const registry = new ToolRegistry ( ) ;
506- registry . register ( "builtin" , weatherDef , createExecutor ( async ( ) => "" ) ) ;
545+ registry . register (
546+ "builtin" ,
547+ weatherDef ,
548+ createExecutor ( async ( ) => "" )
549+ ) ;
507550
508551 await registry . withScopedTools (
509552 "skill" ,
@@ -551,8 +594,16 @@ describe("ToolRegistry", () => {
551594
552595 it ( "多个 scoped 工具应全部被清理" , async ( ) => {
553596 const registry = new ToolRegistry ( ) ;
554- const toolA : ToolDefinition = { name : "tool_a" , description : "A" , parameters : { type : "object" , properties : { } } } ;
555- const toolB : ToolDefinition = { name : "tool_b" , description : "B" , parameters : { type : "object" , properties : { } } } ;
597+ const toolA : ToolDefinition = {
598+ name : "tool_a" ,
599+ description : "A" ,
600+ parameters : { type : "object" , properties : { } } ,
601+ } ;
602+ const toolB : ToolDefinition = {
603+ name : "tool_b" ,
604+ description : "B" ,
605+ parameters : { type : "object" , properties : { } } ,
606+ } ;
556607
557608 await registry . withScopedTools (
558609 "skill" ,
0 commit comments