@@ -40,7 +40,7 @@ describe("getModeSelection with empty promptComponent", () => {
4040 expect ( result . baseInstructions ) . toBe ( "Custom instructions" )
4141 } )
4242
43- it ( "should use promptComponent when it has partial content" , ( ) => {
43+ it ( "should merge promptComponent with built-in mode when it has partial content" , ( ) => {
4444 const architectMode = modes . find ( ( m ) => m . slug === "architect" ) !
4545
4646 // Test with promptComponent that only has customInstructions
@@ -49,8 +49,49 @@ describe("getModeSelection with empty promptComponent", () => {
4949 }
5050 const result = getModeSelection ( "architect" , partialPromptComponent , [ ] )
5151
52- // Should use promptComponent since it has some content
53- expect ( result . roleDefinition ) . toBe ( "" ) // No roleDefinition in promptComponent
54- expect ( result . baseInstructions ) . toBe ( "Only custom instructions" )
52+ // Should merge: use promptComponent's customInstructions but fall back to built-in roleDefinition
53+ expect ( result . roleDefinition ) . toBe ( architectMode . roleDefinition ) // Falls back to built-in
54+ expect ( result . baseInstructions ) . toBe ( "Only custom instructions" ) // Uses promptComponent
55+ } )
56+
57+ it ( "should merge promptComponent with built-in mode when it only has roleDefinition" , ( ) => {
58+ const debugMode = modes . find ( ( m ) => m . slug === "debug" ) !
59+
60+ // Test with promptComponent that only has roleDefinition
61+ const partialPromptComponent : PromptComponent = {
62+ roleDefinition : "Custom debug role" ,
63+ }
64+ const result = getModeSelection ( "debug" , partialPromptComponent , [ ] )
65+
66+ // Should merge: use promptComponent's roleDefinition but fall back to built-in customInstructions
67+ expect ( result . roleDefinition ) . toBe ( "Custom debug role" ) // Uses promptComponent
68+ expect ( result . baseInstructions ) . toBe ( debugMode . customInstructions ) // Falls back to built-in
69+ } )
70+
71+ it ( "should handle promptComponent with both roleDefinition and customInstructions" , ( ) => {
72+ // Test with promptComponent that has both properties
73+ const fullPromptComponent : PromptComponent = {
74+ roleDefinition : "Full custom role" ,
75+ customInstructions : "Full custom instructions" ,
76+ }
77+ const result = getModeSelection ( "architect" , fullPromptComponent , [ ] )
78+
79+ // Should use promptComponent values for both
80+ expect ( result . roleDefinition ) . toBe ( "Full custom role" )
81+ expect ( result . baseInstructions ) . toBe ( "Full custom instructions" )
82+ } )
83+
84+ it ( "should fall back to default mode when built-in mode is not found" , ( ) => {
85+ const defaultMode = modes [ 0 ] // First mode is the default
86+
87+ // Test with non-existent mode
88+ const partialPromptComponent : PromptComponent = {
89+ customInstructions : "Custom instructions for unknown mode" ,
90+ }
91+ const result = getModeSelection ( "non-existent-mode" , partialPromptComponent , [ ] )
92+
93+ // Should merge with default mode
94+ expect ( result . roleDefinition ) . toBe ( defaultMode . roleDefinition ) // Falls back to default mode
95+ expect ( result . baseInstructions ) . toBe ( "Custom instructions for unknown mode" ) // Uses promptComponent
5596 } )
5697} )
0 commit comments