@@ -11,6 +11,7 @@ import (
11
11
"github.com/coder/coder/v2/coderd/coderdtest"
12
12
"github.com/coder/coder/v2/coderd/database"
13
13
"github.com/coder/coder/v2/coderd/database/dbfake"
14
+ "github.com/coder/coder/v2/coderd/database/dbgen"
14
15
"github.com/coder/coder/v2/codersdk"
15
16
"github.com/coder/coder/v2/codersdk/toolsdk"
16
17
)
@@ -99,6 +100,67 @@ func TestChatGPTSearch_TemplateSearch(t *testing.T) {
99
100
}
100
101
}
101
102
103
+ func TestChatGPTSearch_TemplateMultipleFilters (t * testing.T ) {
104
+ t .Parallel ()
105
+
106
+ // Setup
107
+ client , store := coderdtest .NewWithDatabase (t , nil )
108
+ owner := coderdtest .CreateFirstUser (t , client )
109
+
110
+ // Create templates directly with specific names for testing filters
111
+ dockerTemplate1 := dbgen .Template (t , store , database.Template {
112
+ OrganizationID : owner .OrganizationID ,
113
+ CreatedBy : owner .UserID ,
114
+ Name : "docker-development" , // Name contains "docker"
115
+ DisplayName : "Docker Development" ,
116
+ Description : "A Docker-based development template" ,
117
+ })
118
+
119
+ // Create another template that doesn't contain "docker"
120
+ dbgen .Template (t , store , database.Template {
121
+ OrganizationID : owner .OrganizationID ,
122
+ CreatedBy : owner .UserID ,
123
+ Name : "python-web" , // Name doesn't contain "docker"
124
+ DisplayName : "Python Web" ,
125
+ Description : "A Python web development template" ,
126
+ })
127
+
128
+ // Create third template with "docker" in name
129
+ dockerTemplate2 := dbgen .Template (t , store , database.Template {
130
+ OrganizationID : owner .OrganizationID ,
131
+ CreatedBy : owner .UserID ,
132
+ Name : "old-docker-template" , // Name contains "docker"
133
+ DisplayName : "Old Docker Template" ,
134
+ Description : "An old Docker template" ,
135
+ })
136
+
137
+ // Create tool dependencies
138
+ deps , err := toolsdk .NewDeps (client )
139
+ require .NoError (t , err )
140
+
141
+ // Execute tool with name filter - should only return templates with "docker" in name
142
+ args := toolsdk.SearchArgs {Query : "templates/name:docker" }
143
+ result , err := testTool (t , toolsdk .ChatGPTSearch , deps , args )
144
+
145
+ // Verify results
146
+ require .NoError (t , err )
147
+ require .Len (t , result .Results , 2 , "Should match both docker templates" )
148
+
149
+ // Validate the results contain both docker templates
150
+ templateIDs := make (map [string ]bool )
151
+ for _ , item := range result .Results {
152
+ require .NotEmpty (t , item .ID )
153
+ require .Contains (t , item .ID , "template:" )
154
+ require .Contains (t , item .URL , "/templates/" )
155
+ templateIDs [item .ID ] = true
156
+ }
157
+
158
+ expectedID1 := "template:" + dockerTemplate1 .ID .String ()
159
+ expectedID2 := "template:" + dockerTemplate2 .ID .String ()
160
+ require .True (t , templateIDs [expectedID1 ], "Should contain first docker template" )
161
+ require .True (t , templateIDs [expectedID2 ], "Should contain second docker template" )
162
+ }
163
+
102
164
func TestChatGPTSearch_WorkspaceSearch (t * testing.T ) {
103
165
t .Parallel ()
104
166
@@ -119,7 +181,7 @@ func TestChatGPTSearch_WorkspaceSearch(t *testing.T) {
119
181
},
120
182
{
121
183
name : "ValidWorkspacesQuery_CurrentUserMe" ,
122
- query : "workspaces:me" ,
184
+ query : "workspaces/owner :me" ,
123
185
setupOwner : "self" ,
124
186
setupWorkspace : true ,
125
187
expectError : false ,
@@ -133,7 +195,7 @@ func TestChatGPTSearch_WorkspaceSearch(t *testing.T) {
133
195
},
134
196
{
135
197
name : "ValidWorkspacesQuery_SpecificUser" ,
136
- query : "workspaces:otheruser" ,
198
+ query : "workspaces/owner :otheruser" ,
137
199
setupOwner : "other" ,
138
200
setupWorkspace : true ,
139
201
expectError : false ,
@@ -229,12 +291,12 @@ func TestChatGPTSearch_QueryParsing(t *testing.T) {
229
291
},
230
292
{
231
293
name : "ValidWorkspacesMeQuery" ,
232
- query : "workspaces:me" ,
294
+ query : "workspaces/owner :me" ,
233
295
expectError : false ,
234
296
},
235
297
{
236
298
name : "ValidWorkspacesUserQuery" ,
237
- query : "workspaces:testuser" ,
299
+ query : "workspaces/owner :testuser" ,
238
300
expectError : false ,
239
301
},
240
302
{
@@ -251,7 +313,7 @@ func TestChatGPTSearch_QueryParsing(t *testing.T) {
251
313
},
252
314
{
253
315
name : "MalformedQuery" ,
254
- query : "workspaces:user:extra " ,
316
+ query : "invalidtype/somequery " ,
255
317
expectError : true ,
256
318
errorMsg : "invalid query" ,
257
319
},
0 commit comments