@@ -20,7 +20,7 @@ This is a test rule.`;
20
20
21
21
const result = markdownToRule ( content , mockId ) ;
22
22
expect ( result . rule ) . toBe ( "# Test Rule\n\nThis is a test rule." ) ;
23
- expect ( result . globs ) . toBe ( "**/test/**/*.kt" ) ;
23
+ expect ( result . globs ) . toBe ( "/path/to/ **/test/**/*.kt" ) ;
24
24
expect ( result . name ) . toBe ( "Custom Name" ) ;
25
25
} ) ;
26
26
@@ -34,7 +34,7 @@ globs: "**/test/**/*.kt"
34
34
This is a test rule.` ;
35
35
36
36
const result = markdownToRule ( content , mockId ) ;
37
- expect ( result . globs ) . toBe ( "**/test/**/*.kt" ) ;
37
+ expect ( result . globs ) . toBe ( "/path/to/ **/test/**/*.kt" ) ;
38
38
expect ( result . rule ) . toBe ( "# Test Rule\n\nThis is a test rule." ) ;
39
39
expect ( result . name ) . toBe ( "to/file" ) ; // Should use last two path segments
40
40
} ) ;
@@ -45,7 +45,7 @@ This is a test rule.`;
45
45
This is a test rule without frontmatter.` ;
46
46
47
47
const result = markdownToRule ( content , mockId ) ;
48
- expect ( result . globs ) . toBeUndefined ( ) ;
48
+ expect ( result . globs ) . toBe ( "/path/to/**/*" ) ;
49
49
expect ( result . rule ) . toBe ( content ) ;
50
50
expect ( result . name ) . toBe ( "to/file" ) ; // Should use last two path segments
51
51
} ) ;
@@ -59,13 +59,104 @@ This is a test rule without frontmatter.`;
59
59
This is a test rule with empty frontmatter.` ;
60
60
61
61
const result = markdownToRule ( content , mockId ) ;
62
- expect ( result . globs ) . toBeUndefined ( ) ;
62
+ expect ( result . globs ) . toBe ( "/path/to/**/*" ) ;
63
63
expect ( result . rule ) . toBe (
64
64
"# Test Rule\n\nThis is a test rule with empty frontmatter." ,
65
65
) ;
66
66
expect ( result . name ) . toBe ( "to/file" ) ; // Should use last two path segments
67
67
} ) ;
68
68
69
+ describe ( "glob patterns" , ( ) => {
70
+ // we want to ensure the following glob changes happen
71
+ // *.ts -> path/to/**/*.ts
72
+ // **/subdir/** -> path/to/**/**/subdir/** OR path/to/**/subdir/**
73
+ // myfile -> path/to/**/myfile (any depth including 0)
74
+ // mydir/ -> path/to/**/mydir/**
75
+ // **abc** -> path/to/**abc**
76
+ // *xyz* -> path/to/**/*xyz*
77
+
78
+ it ( "should match glob pattern for file extensions" , ( ) => {
79
+ const content = `---
80
+ globs: "*.ts"
81
+ name: glob pattern testing
82
+ ---
83
+
84
+ # Test Rule
85
+
86
+ This is a test rule.` ;
87
+
88
+ const result = markdownToRule ( content , mockId ) ;
89
+ expect ( result . globs ) . toBe ( "/path/to/**/*.ts" ) ;
90
+ } ) ;
91
+
92
+ it ( "should match glob pattern for dotfiles" , ( ) => {
93
+ const content = `---
94
+ globs: ".gitignore"
95
+ name: glob pattern testing
96
+ ---
97
+
98
+ # Test Rule
99
+
100
+ This is a test rule.` ;
101
+
102
+ const result = markdownToRule ( content , mockId ) ;
103
+ expect ( result . globs ) . toBe ( "/path/to/**/.gitignore" ) ;
104
+ } ) ;
105
+
106
+ it ( "should also work in root as base directory" , ( ) => {
107
+ const content = `---
108
+ globs: "src/**/Dockerfile"
109
+ name: glob pattern testing
110
+ ---
111
+
112
+ # Test Rule
113
+
114
+ This is a test rule.` ;
115
+
116
+ const result = markdownToRule ( content , {
117
+ uriType : "file" ,
118
+ filePath : "/" ,
119
+ } ) ;
120
+ expect ( result . globs ) . toBe ( "/**/src/**/Dockerfile" ) ;
121
+ } ) ;
122
+
123
+ it ( "should match for multiple globs" , ( ) => {
124
+ const content = `---
125
+ globs: ["**/nested/**/deeper/**/*.rs", ".zshrc1", "**abc**", "*xyz*"]
126
+ name: glob pattern testing
127
+ ---
128
+
129
+ # Test Rule
130
+
131
+ This is a test rule.` ;
132
+
133
+ const result = markdownToRule ( content , mockId ) ;
134
+ expect ( result . globs ) . toEqual ( [
135
+ "/path/to/**/nested/**/deeper/**/*.rs" ,
136
+ "/path/to/**/.zshrc1" ,
137
+ "/path/to/**abc**" ,
138
+ "/path/to/**/*xyz*" ,
139
+ ] ) ;
140
+ } ) ;
141
+
142
+ it ( "should not prepend when inside .continue" , ( ) => {
143
+ const content = `---
144
+ globs: ".git"
145
+ name: glob pattern testing
146
+ ---
147
+
148
+ # Test Rule
149
+
150
+ This is a test rule.` ;
151
+
152
+ const result = markdownToRule ( content , {
153
+ uriType : "file" ,
154
+ filePath : "/Documents/myproject/.continue/rules/rule1.md" ,
155
+ } ) ;
156
+ expect ( result . globs ) . toBe ( ".git" ) ;
157
+ } ) ;
158
+ } ) ;
159
+
69
160
it ( "should handle frontmatter with whitespace" , ( ) => {
70
161
const content = `---
71
162
globs: "**/test/**/*.kt"
@@ -76,7 +167,7 @@ globs: "**/test/**/*.kt"
76
167
This is a test rule.` ;
77
168
78
169
const result = markdownToRule ( content , mockId ) ;
79
- expect ( result . globs ) . toBe ( "**/test/**/*.kt" ) ;
170
+ expect ( result . globs ) . toBe ( "/path/to/ **/test/**/*.kt" ) ;
80
171
expect ( result . rule ) . toBe ( "# Test Rule\n\nThis is a test rule." ) ;
81
172
expect ( result . name ) . toBe ( "to/file" ) ; // Should use last two path segments
82
173
} ) ;
@@ -92,7 +183,7 @@ globs: "**/test/**/*.kt"\r
92
183
This is a test rule.` ;
93
184
94
185
const result = markdownToRule ( content , mockId ) ;
95
- expect ( result . globs ) . toBe ( "**/test/**/*.kt" ) ;
186
+ expect ( result . globs ) . toBe ( "/path/to/ **/test/**/*.kt" ) ;
96
187
// The result should be normalized to \n
97
188
expect ( result . rule ) . toBe ( "# Test Rule\n\nThis is a test rule." ) ;
98
189
expect ( result . name ) . toBe ( "to/file" ) ; // Should use last two path segments
@@ -110,7 +201,7 @@ This is a test rule.`;
110
201
111
202
// Should treat as only markdown when frontmatter is malformed
112
203
const result = markdownToRule ( content , mockId ) ;
113
- expect ( result . globs ) . toBeUndefined ( ) ;
204
+ expect ( result . globs ) . toBe ( "/path/to/**/*" ) ;
114
205
expect ( result . rule ) . toBe ( content ) ;
115
206
expect ( result . name ) . toBe ( "to/file" ) ; // Should use last two path segments
116
207
} ) ;
0 commit comments