@@ -60,6 +60,44 @@ When using the `generate` command with the `--json` flag, it returns a JSON resp
60
60
]
61
61
}
62
62
// Additional prompts...
63
+ ],
64
+ "tools" : [
65
+ {
66
+ "id" : " tool-id" ,
67
+ "description" : " Tool description" ,
68
+ "type" : " run|http" ,
69
+ "schema" : {
70
+ "properties" : {
71
+ "paramName" : {
72
+ "type" : " string|number|boolean" ,
73
+ "description" : " Parameter description"
74
+ }
75
+ },
76
+ "required" : [
77
+ " paramName"
78
+ ]
79
+ },
80
+ "commands" : [
81
+ {
82
+ "cmd" : " command-name" ,
83
+ "args" : [
84
+ " arg1" ,
85
+ " arg2"
86
+ ]
87
+ }
88
+ ],
89
+ "requests" : [
90
+ {
91
+ "url" : " https://api.example.com/endpoint" ,
92
+ "method" : " GET|POST" ,
93
+ "headers" : {
94
+ "Content-Type" : " application/json" ,
95
+ "Authorization" : " Bearer {{TOKEN}}"
96
+ }
97
+ }
98
+ ]
99
+ }
100
+ // Additional tools...
63
101
]
64
102
}
65
103
```
@@ -85,6 +123,7 @@ The test files should follow these naming conventions:
85
123
- ` LocalImportTest.php ` - Tests for local imports
86
124
- ` UrlImportTest.php ` - Tests for URL imports
87
125
- ` PromptsTest.php ` - Tests for prompts functionality
126
+ - ` ToolsTest.php ` - Tests for tools functionality
88
127
89
128
Each test class should extend ` Tests\Feature\Console\ConsoleTestCase ` to access the common testing functionality.
90
129
@@ -115,6 +154,7 @@ tests/fixtures/Console/GenerateCommand/GithubSource/
115
154
tests/fixtures/Console/GenerateCommand/GitlabSource/
116
155
tests/fixtures/Console/GenerateCommand/UrlSource/
117
156
tests/fixtures/Console/GenerateCommand/Prompts/
157
+ tests/fixtures/Console/GenerateCommand/Tools/
118
158
```
119
159
120
160
### Creating Fixtures
@@ -205,6 +245,18 @@ $this
205
245
| `assertPromptCount(count)` | Check the number of prompts |
206
246
| `assertNoPrompts()` | Check that no prompts were found |
207
247
248
+ # ## Tool Assertions
249
+
250
+ | Method | Description |
251
+ |----------------------------------------------|------------------------------------------------|
252
+ | `assertToolExists(id)` | Check that a tool with the specified ID exists |
253
+ | `assertTool(id, properties)` | Check tool properties |
254
+ | `assertToolSchema(id, properties, required)` | Check tool schema structure |
255
+ | `assertToolCommands(id, expectedCommands)` | Check commands in a run-type tool |
256
+ | `assertToolRequests(id, expectedRequests)` | Check requests in an http-type tool |
257
+ | `assertToolCount(count)` | Check the number of tools |
258
+ | `assertNoTools()` | Check that no tools were found |
259
+
208
260
# ## Example Prompt Test
209
261
210
262
` ` ` php
@@ -233,6 +285,65 @@ public function basic_prompts_should_be_compiled(): void
233
285
}
234
286
` ` `
235
287
288
+ # ## Example Tool Test
289
+
290
+ ` ` ` php
291
+ public function basic_tools_should_be_compiled(): void
292
+ {
293
+ $this
294
+ ->buildContext(
295
+ workDir: $this->outputDir,
296
+ configPath: $this->getFixturesDir('Console/GenerateCommand/Tools/basic.yaml'),
297
+ )
298
+ ->assertSuccessfulCompiled()
299
+ ->assertToolExists('test-command')
300
+ ->assertTool('test-command', [
301
+ 'type' => 'run',
302
+ 'description' => 'A simple test command',
303
+ ])
304
+ ->assertToolSchema('test-command',
305
+ [
306
+ 'param' => [
307
+ 'type' => 'string',
308
+ 'description' => 'Command parameter',
309
+ ],
310
+ ],
311
+ ['param'],
312
+ )
313
+ ->assertToolCommands('test-command', [
314
+ [
315
+ 'cmd' => 'echo',
316
+ 'args' => ['Hello', '{{param}}'],
317
+ ],
318
+ ]);
319
+ }
320
+
321
+ public function http_tools_should_be_compiled(): void
322
+ {
323
+ $this
324
+ ->buildContext(
325
+ workDir: $this->outputDir,
326
+ configPath: $this->getFixturesDir('Console/GenerateCommand/Tools/http.yaml'),
327
+ )
328
+ ->assertSuccessfulCompiled()
329
+ ->assertToolExists('test-api')
330
+ ->assertTool('test-api', [
331
+ 'type' => 'http',
332
+ 'description' => 'A simple HTTP API tool',
333
+ ])
334
+ ->assertToolRequests('test-api', [
335
+ [
336
+ 'method' => 'GET',
337
+ 'url' => 'https://api.example.com/data',
338
+ 'headers' => [
339
+ 'Content-Type' => 'application/json',
340
+ 'Authorization' => 'Bearer {{token}}',
341
+ ],
342
+ ],
343
+ ]);
344
+ }
345
+ ` ` `
346
+
236
347
# # 5. Testing Best Practices
237
348
238
349
# ## Use Data Providers
@@ -335,3 +446,15 @@ When testing imports:
335
446
4. Test wildcard patterns
336
447
5. Test variable substitution
337
448
6. Test error handling (404, invalid configs)
449
+
450
+ # ## Testing Tools
451
+
452
+ When testing tools :
453
+
454
+ 1. Test basic 'run' type tools with simple commands
455
+ 2. Test tools with command arguments and conditional arguments
456
+ 3. Test 'http' type tools with different request methods
457
+ 4. Test tools with environment variables
458
+ 5. Test tools with complex schemas
459
+ 6. Test tool error handling (validation errors, execution errors)
460
+ 7. Test the interaction between tools and other config sections (like variables)
0 commit comments