@@ -40,14 +40,51 @@ test("add registers live; remove unregisters live", () => {
4040 store . close ( ) ;
4141} ) ;
4242
43- test ( "handler returns the instruction as success text " , async ( ) => {
43+ test ( "handler submits the instruction to the agent and returns a receipt " , async ( ) => {
4444 const { store, manager, registered } = setup ( ) ;
4545 manager . add ( { name : "fmt" , description : "格式化" , instruction : "请按项目的 lint 规则格式化当前文件" } ) ;
4646 const def = registered . get ( "fmt" ) ;
4747 assert . ok ( def , "definition registered" ) ;
48- const result = await def . handler ( { agent : { } , rawInput : "" , signal : null } ) ;
48+ assert . equal ( def . input . hint , "可选:追加给模型的补充说明" ) ;
49+ const submitted = [ ] ;
50+ const agent = { followup : ( message ) => submitted . push ( message ) } ;
51+ const result = await def . handler ( { agent, rawInput : "" , signal : null } ) ;
4952 assert . equal ( result . kind , "success" ) ;
50- assert . equal ( result . text , "请按项目的 lint 规则格式化当前文件" ) ;
53+ assert . equal ( result . text , "已提交指令:fmt" ) ;
54+ assert . equal ( submitted . length , 1 ) ;
55+ assert . equal ( submitted [ 0 ] . role , "user" ) ;
56+ assert . deepEqual ( submitted [ 0 ] . content , [ { type : "text" , text : "请按项目的 lint 规则格式化当前文件" } ] ) ;
57+ assert . deepEqual ( submitted [ 0 ] . source , { kind : "user" } ) ;
58+ store . close ( ) ;
59+ } ) ;
60+
61+ test ( "rawInput suffix is appended for the model" , async ( ) => {
62+ const { store, manager, registered } = setup ( ) ;
63+ manager . add ( { name : "mneme" , instruction : "以「小墨」的口吻自我介绍" } ) ;
64+ const def = registered . get ( "mneme" ) ;
65+ const submitted = [ ] ;
66+ await def . handler ( { agent : { followup : ( m ) => submitted . push ( m ) } , rawInput : " 顺便列出归档数量 " } ) ;
67+ assert . equal ( submitted [ 0 ] . content [ 0 ] . text , "以「小墨」的口吻自我介绍\n\n顺便列出归档数量" ) ;
68+ store . close ( ) ;
69+ } ) ;
70+
71+ test ( "handler without a receiving agent falls back to surfacing the instruction" , ( ) => {
72+ const { store, manager, registered } = setup ( ) ;
73+ manager . add ( { name : "fmt" , instruction : "legacy text" } ) ;
74+ const def = registered . get ( "fmt" ) ;
75+ const result = def . handler ( { rawInput : "" } ) ;
76+ assert . equal ( result . kind , "success" ) ;
77+ assert . equal ( result . text , "legacy text" ) ;
78+ store . close ( ) ;
79+ } ) ;
80+
81+ test ( "handler returns an error result when the agent rejects the submission" , ( ) => {
82+ const { store, manager, registered } = setup ( ) ;
83+ manager . add ( { name : "boom" , instruction : "x" } ) ;
84+ const def = registered . get ( "boom" ) ;
85+ const result = def . handler ( { agent : { followup : ( ) => { throw new Error ( "nope" ) ; } } } ) ;
86+ assert . equal ( result . kind , "error" ) ;
87+ assert . match ( result . text , / b o o m / ) ;
5188 store . close ( ) ;
5289} ) ;
5390
0 commit comments