1- import { validateCustomMode } from "../CustomModesSchema"
2- import { ModeConfig } from "../../../shared/modes"
31import { ZodError } from "zod"
2+ import { CustomModeSchema , validateCustomMode } from "../CustomModesSchema"
3+ import { ModeConfig } from "../../../shared/modes"
44
5- describe ( "CustomModesSchema " , ( ) => {
5+ describe ( "CustomModeSchema " , ( ) => {
66 describe ( "validateCustomMode" , ( ) => {
77 test ( "accepts valid mode configuration" , ( ) => {
88 const validMode = {
9- slug : "123e4567-e89b-12d3-a456-426614174000 " ,
9+ slug : "test " ,
1010 name : "Test Mode" ,
1111 roleDefinition : "Test role definition" ,
1212 groups : [ "read" ] as const ,
@@ -17,7 +17,7 @@ describe("CustomModesSchema", () => {
1717
1818 test ( "accepts mode with multiple groups" , ( ) => {
1919 const validMode = {
20- slug : "123e4567-e89b-12d3-a456-426614174000 " ,
20+ slug : "test " ,
2121 name : "Test Mode" ,
2222 roleDefinition : "Test role definition" ,
2323 groups : [ "read" , "edit" , "browser" ] as const ,
@@ -28,7 +28,7 @@ describe("CustomModesSchema", () => {
2828
2929 test ( "accepts mode with optional customInstructions" , ( ) => {
3030 const validMode = {
31- slug : "123e4567-e89b-12d3-a456-426614174000 " ,
31+ slug : "test " ,
3232 name : "Test Mode" ,
3333 roleDefinition : "Test role definition" ,
3434 customInstructions : "Custom instructions" ,
@@ -119,4 +119,76 @@ describe("CustomModesSchema", () => {
119119 } )
120120 } )
121121 } )
122+
123+ describe ( "fileRegex" , ( ) => {
124+ it ( "validates a mode with file restrictions and descriptions" , ( ) => {
125+ const modeWithJustRegex = {
126+ slug : "markdown-editor" ,
127+ name : "Markdown Editor" ,
128+ roleDefinition : "Markdown editing mode" ,
129+ groups : [ "read" , [ "edit" , { fileRegex : "\\.md$" } ] , "browser" ] ,
130+ }
131+
132+ const modeWithDescription = {
133+ slug : "docs-editor" ,
134+ name : "Documentation Editor" ,
135+ roleDefinition : "Documentation editing mode" ,
136+ groups : [
137+ "read" ,
138+ [ "edit" , { fileRegex : "\\.(md|txt)$" , description : "Documentation files only" } ] ,
139+ "browser" ,
140+ ] ,
141+ }
142+
143+ expect ( ( ) => CustomModeSchema . parse ( modeWithJustRegex ) ) . not . toThrow ( )
144+ expect ( ( ) => CustomModeSchema . parse ( modeWithDescription ) ) . not . toThrow ( )
145+ } )
146+
147+ it ( "validates file regex patterns" , ( ) => {
148+ const validPatterns = [ "\\.md$" , ".*\\.txt$" , "[a-z]+\\.js$" ]
149+ const invalidPatterns = [ "[" , "(unclosed" , "\\" ]
150+
151+ validPatterns . forEach ( ( pattern ) => {
152+ const mode = {
153+ slug : "test" ,
154+ name : "Test" ,
155+ roleDefinition : "Test" ,
156+ groups : [ "read" , [ "edit" , { fileRegex : pattern } ] ] ,
157+ }
158+ expect ( ( ) => CustomModeSchema . parse ( mode ) ) . not . toThrow ( )
159+ } )
160+
161+ invalidPatterns . forEach ( ( pattern ) => {
162+ const mode = {
163+ slug : "test" ,
164+ name : "Test" ,
165+ roleDefinition : "Test" ,
166+ groups : [ "read" , [ "edit" , { fileRegex : pattern } ] ] ,
167+ }
168+ expect ( ( ) => CustomModeSchema . parse ( mode ) ) . toThrow ( )
169+ } )
170+ } )
171+
172+ it ( "prevents duplicate groups" , ( ) => {
173+ const modeWithDuplicates = {
174+ slug : "test" ,
175+ name : "Test" ,
176+ roleDefinition : "Test" ,
177+ groups : [ "read" , "read" , [ "edit" , { fileRegex : "\\.md$" } ] , [ "edit" , { fileRegex : "\\.txt$" } ] ] ,
178+ }
179+
180+ expect ( ( ) => CustomModeSchema . parse ( modeWithDuplicates ) ) . toThrow ( / D u p l i c a t e g r o u p s / )
181+ } )
182+
183+ it ( "requires at least one group" , ( ) => {
184+ const modeWithNoGroups = {
185+ slug : "test" ,
186+ name : "Test" ,
187+ roleDefinition : "Test" ,
188+ groups : [ ] ,
189+ }
190+
191+ expect ( ( ) => CustomModeSchema . parse ( modeWithNoGroups ) ) . toThrow ( / A t l e a s t o n e t o o l g r o u p i s r e q u i r e d / )
192+ } )
193+ } )
122194} )
0 commit comments