codeguard-testgen 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,173 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const mongodb_1 = require("mongodb");
4
- const prompts_1 = require("./prompts");
5
- class PromptService {
6
- constructor() {
7
- this.client = null;
8
- this.db = null;
9
- this.cache = new Map();
10
- this.CACHE_TTL = 5 * 60 * 1000; // 5 minutes
11
- this.CONNECTION_TIMEOUT = 2000; // 2 seconds
12
- this.mongoUri = null;
13
- this.enabled = true;
14
- this.connectionAttempted = false;
15
- }
16
- /**
17
- * Initialize the prompt service with MongoDB configuration
18
- */
19
- async initialize(mongoUri, enabled = true) {
20
- this.enabled = enabled;
21
- this.mongoUri = mongoUri || null;
22
- // Don't connect immediately, connect on first use
23
- }
24
- /**
25
- * Ensure MongoDB connection is established
26
- */
27
- async ensureConnection() {
28
- if (this.db) {
29
- return true;
30
- }
31
- if (this.connectionAttempted) {
32
- return false;
33
- }
34
- if (!this.mongoUri || !this.enabled) {
35
- return false;
36
- }
37
- this.connectionAttempted = true;
38
- try {
39
- const connectionPromise = mongodb_1.MongoClient.connect(this.mongoUri, {
40
- serverSelectionTimeoutMS: this.CONNECTION_TIMEOUT,
41
- connectTimeoutMS: this.CONNECTION_TIMEOUT,
42
- });
43
- // Add timeout wrapper
44
- const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Connection timeout')), this.CONNECTION_TIMEOUT));
45
- this.client = await Promise.race([connectionPromise, timeoutPromise]);
46
- this.db = this.client.db();
47
- return true;
48
- }
49
- catch (error) {
50
- return false;
51
- }
52
- }
53
- /**
54
- * Get cache key for a prompt
55
- */
56
- getCacheKey(promptType, provider) {
57
- return `${promptType}:${provider}`;
58
- }
59
- /**
60
- * Check if cached prompt is still valid
61
- */
62
- isCacheValid(cacheKey) {
63
- const cached = this.cache.get(cacheKey);
64
- if (!cached) {
65
- return false;
66
- }
67
- const age = Date.now() - cached.timestamp;
68
- return age < this.CACHE_TTL;
69
- }
70
- /**
71
- * Fetch prompt from MongoDB
72
- */
73
- async fetchFromMongoDB(promptType, provider) {
74
- if (!await this.ensureConnection() || !this.db) {
75
- return null;
76
- }
77
- try {
78
- const collection = this.db.collection('prompts');
79
- const queryPromise = collection.findOne({
80
- promptType,
81
- provider,
82
- isActive: true
83
- }, {
84
- sort: { updatedAt: -1 }
85
- });
86
- // Add timeout to query
87
- const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Query timeout')), this.CONNECTION_TIMEOUT));
88
- const document = await Promise.race([queryPromise, timeoutPromise]);
89
- if (document && document.content) {
90
- return document.content;
91
- }
92
- return null;
93
- }
94
- catch (error) {
95
- return null;
96
- }
97
- }
98
- /**
99
- * Get fallback prompt from hardcoded prompts
100
- */
101
- getFallbackPrompt(promptType, provider) {
102
- const prompts = promptType === 'file-wise' ? prompts_1.FILEWISE_PROMPTS : prompts_1.FUNCTIONWISE_PROMPTS;
103
- return prompts[provider];
104
- }
105
- /**
106
- * Get prompt with three-tier priority system:
107
- * 1. User's custom prompt (from codeguard.json)
108
- * 2. Remote MongoDB prompt (maintainer's centralized prompts)
109
- * 3. Fallback prompt (hardcoded in package)
110
- */
111
- async getPrompt(promptType, provider, customPrompts) {
112
- // Priority 1: Check for user's custom prompt in their config
113
- if (customPrompts) {
114
- const customPromptKey = promptType === 'file-wise' ? 'fileWise' : 'functionWise';
115
- const userPrompt = customPrompts[customPromptKey]?.[provider];
116
- if (userPrompt && userPrompt.trim() !== '') {
117
- console.log(`📝 Using custom prompt`);
118
- return userPrompt;
119
- }
120
- }
121
- const cacheKey = this.getCacheKey(promptType, provider);
122
- // Check cache for MongoDB/fallback prompts
123
- if (this.isCacheValid(cacheKey)) {
124
- const cached = this.cache.get(cacheKey);
125
- if (cached) {
126
- return cached.content;
127
- }
128
- }
129
- // Priority 2: Try to fetch from MongoDB (maintainer's database)
130
- if (this.enabled && this.mongoUri) {
131
- const remotePrompt = await this.fetchFromMongoDB(promptType, provider);
132
- if (remotePrompt) {
133
- console.log(`📝 Using remote prompt`);
134
- // Cache the fetched prompt
135
- this.cache.set(cacheKey, {
136
- content: remotePrompt,
137
- timestamp: Date.now()
138
- });
139
- return remotePrompt;
140
- }
141
- }
142
- // Priority 3: Fallback to hardcoded prompt
143
- console.log(`📝 Using fallback prompt`);
144
- const fallbackPrompt = this.getFallbackPrompt(promptType, provider);
145
- // Cache the fallback prompt too
146
- this.cache.set(cacheKey, {
147
- content: fallbackPrompt,
148
- timestamp: Date.now()
149
- });
150
- return fallbackPrompt;
151
- }
152
- /**
153
- * Clear the prompt cache
154
- */
155
- clearCache() {
156
- this.cache.clear();
157
- }
158
- /**
159
- * Close MongoDB connection
160
- */
161
- async close() {
162
- if (this.client) {
163
- await this.client.close();
164
- this.client = null;
165
- this.db = null;
166
- this.connectionAttempted = false;
167
- }
168
- }
169
- }
170
- // Singleton instance
171
- const promptService = new PromptService();
172
- exports.default = promptService;
173
- //# sourceMappingURL=promptService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"promptService.js","sourceRoot":"","sources":["../src/promptService.ts"],"names":[],"mappings":";;AAAA,qCAAsD;AACtD,uCAAmE;AAqBnE,MAAM,aAAa;IAAnB;QACU,WAAM,GAAuB,IAAI,CAAC;QAClC,OAAE,GAAc,IAAI,CAAC;QACrB,UAAK,GAA6B,IAAI,GAAG,EAAE,CAAC;QACnC,cAAS,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;QACvC,uBAAkB,GAAG,IAAI,CAAC,CAAC,YAAY;QAChD,aAAQ,GAAkB,IAAI,CAAC;QAC/B,YAAO,GAAY,IAAI,CAAC;QACxB,wBAAmB,GAAY,KAAK,CAAC;IAqM/C,CAAC;IAnMC;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,QAA4B,EAAE,UAAmB,IAAI;QACpE,IAAI,CAAC,OAAO,GAAG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fallback prompts for AI test generation
3
- * These are used when MongoDB is not configured or unavailable
4
- */
5
- export interface PromptTemplates {
6
- claude: string;
7
- openai: string;
8
- gemini: string;
9
- }
10
- export declare const FILEWISE_PROMPTS: PromptTemplates;
11
- export declare const FUNCTIONWISE_PROMPTS: PromptTemplates;
12
- //# sourceMappingURL=prompts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAGD,eAAO,MAAM,gBAAgB,EAAE,eAgS9B,CAAC;AAGF,eAAO,MAAM,oBAAoB,EAAE,eA8KlC,CAAC"}
package/dist/prompts.js DELETED
@@ -1,470 +0,0 @@
1
- "use strict";
2
- /**
3
- * Fallback prompts for AI test generation
4
- * These are used when MongoDB is not configured or unavailable
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.FUNCTIONWISE_PROMPTS = exports.FILEWISE_PROMPTS = void 0;
8
- // File-wise test generation prompts (default prompt used for all providers as fallback)
9
- exports.FILEWISE_PROMPTS = {
10
- claude: `You are a senior software engineer tasked with writing comprehensive Jest unit tests including edge cases for a TypeScript file.
11
-
12
- Source file: {{sourceFile}}
13
- Test file path: {{testFilePath}}
14
-
15
- IMPORTANT: You MUST use the provided tools to complete this task. Do not just respond with text.
16
-
17
- Your task (you MUST complete ALL steps):
18
- 1. FIRST: Use analyze_file_ast tool to get a complete AST analysis of the source file (functions, classes, types, exports)
19
- 2. Use get_imports_ast tool to understand all dependencies
20
- 3. For each dependency, use find_file to locate it and calculate_relative_path to get correct import paths for the test file
21
- 4. For complex functions, use get_function_ast tool to get detailed information including parameters, return types, and cyclomatic complexity
22
- 5. For classes, use get_class_methods tool to extract all methods
23
- 6. Use get_type_definitions tool to understand TypeScript types and interfaces
24
- 7. Generate comprehensive Jest unit tests with:
25
- - CRITICAL: Mock ALL imports BEFORE importing the source file to prevent initialization errors
26
- - Mock database modules like '../database' or '../database/index'
27
- - Mock models, services, and any modules that access config/database
28
- - Use jest.mock() calls at the TOP of the file before any imports
29
- - Test suites for each function/class
30
- - REQUIRED: Test cases should include security and input validation tests.
31
- - REQUIRED: Multiple test cases covering:
32
- * Happy path scenarios
33
- * Edge cases (null, undefined, empty arrays, etc.)
34
- * Error conditions
35
- * Async behavior (if applicable)
36
- - Proper TypeScript types
37
- - Clear, descriptive test names
38
- - Complete test implementations (NO placeholder comments!)
39
- 8. REQUIRED: Write the COMPLETE test file using write_test_file tool with REAL test code (NOT placeholders!)
40
- - CRITICAL: Include source_file parameter with path to source file (e.g., source_file: "{{sourceFile}}")
41
- - DO NOT use ANY placeholder comments like:
42
- * "// Mock setup", "// Assertions", "// Call function"
43
- * "// Further tests...", "// Additional tests..."
44
- * "// Similarly, write tests for..."
45
- * "// Add more tests...", "// TODO", "// ..."
46
- - Write ACTUAL working test code with real mocks, real assertions, real function calls
47
- - Every test MUST have:
48
- * Real setup code (mock functions, create test data)
49
- * Real execution (call the function being tested)
50
- * Real expect() assertions (at least one per test)
51
- - Write tests for EVERY exported function (minimum 3-5 tests per function)
52
- - If source has 4 functions, test file MUST have 4 describe blocks with actual tests
53
- - Example of COMPLETE test structure:
54
- * Setup: Create mocks and test data
55
- * Execute: Call the function being tested
56
- * Assert: Use expect() to verify results
57
- 9. REQUIRED: Run the tests using run_tests tool
58
- 10. REQUIRED: If tests fail with import errors:
59
- - Use find_file tool to locate the missing module
60
- - Use calculate_relative_path tool to get correct import path
61
- - PRIMARY METHOD (once test file exists): Use line-based editing:
62
- * read_file to get current test file with line numbers
63
- * insert_lines to add missing imports at correct position (e.g., line 3)
64
- * delete_lines to remove incorrect imports
65
- * replace_lines to fix import paths
66
- - FALLBACK: Only use edit_test_file or write_test_file if line-based editing isn't suitable
67
- 11. REQUIRED: If tests fail with other errors, analyze if they are FIXABLE or LEGITIMATE:
68
-
69
- FIXABLE ERRORS (you should fix these):
70
- - Wrong import paths
71
- - Missing mocks
72
- - Incorrect mock implementations
73
- - Wrong assertions or test logic
74
- - TypeScript compilation errors
75
- - Missing test setup/teardown
76
- - Cannot read properties of undefined
77
-
78
- LEGITIMATE FAILURES (source code bugs - DO NOT try to fix):
79
- - Function returns wrong type (e.g., undefined instead of object)
80
- - Missing null/undefined checks in source code
81
- - Logic errors in source code
82
- - Unhandled promise rejections in source code
83
- - Source code throws unexpected errors
84
-
85
- 12. If errors are FIXABLE (AFTER test file is written):
86
- - ✅ PRIMARY METHOD: Use line-based editing tools (RECOMMENDED):
87
- * read_file to get current test file with line numbers
88
- * delete_lines to remove incorrect lines
89
- * insert_lines to add missing code (e.g., mocks, imports)
90
- * replace_lines to fix specific line ranges
91
- * This is FASTER and MORE RELIABLE than rewriting entire file!
92
- - ⚠️ FALLBACK: Only use edit_test_file or write_test_file if:
93
- * Line-based editing is too complex (needs major restructuring)
94
- * Multiple scattered changes across the file
95
- - Then retry running tests
96
- 13. If errors are LEGITIMATE: Call report_legitimate_failure tool with details and STOP trying to fix
97
- - Provide failing test names, reason, and source code issue description
98
- - The test file will be kept as-is with legitimate failing tests
99
- 14. REQUIRED: Repeat steps 9-13 until tests pass OR legitimate failures are reported
100
- 15. REQUIRED: Ensure all functions are tested in the test file.
101
-
102
- CRITICAL: Distinguish between test bugs (fix them) and source code bugs (report and stop)!
103
-
104
- START NOW by calling the analyze_file_ast tool with the source file path.`,
105
- openai: `You are a senior software engineer tasked with writing comprehensive Jest unit tests including edge cases for a TypeScript file.
106
-
107
- Source file: {{sourceFile}}
108
- Test file path: {{testFilePath}}
109
-
110
- IMPORTANT: You MUST use the provided tools to complete this task. Do not just respond with text.
111
-
112
- Your task (you MUST complete ALL steps):
113
- 1. FIRST: Use analyze_file_ast tool to get a complete AST analysis of the source file (functions, classes, types, exports)
114
- 2. Use get_imports_ast tool to understand all dependencies
115
- 3. For each dependency, use find_file to locate it and calculate_relative_path to get correct import paths for the test file
116
- 4. For complex functions, use get_function_ast tool to get detailed information including parameters, return types, and cyclomatic complexity
117
- 5. For classes, use get_class_methods tool to extract all methods
118
- 6. Use get_type_definitions tool to understand TypeScript types and interfaces
119
- 7. Generate comprehensive Jest unit tests with:
120
- - CRITICAL: Mock ALL imports BEFORE importing the source file to prevent initialization errors
121
- - Mock database modules like '../database' or '../database/index'
122
- - Mock models, services, and any modules that access config/database
123
- - Use jest.mock() calls at the TOP of the file before any imports
124
- - Test suites for each function/class
125
- - REQUIRED: Test cases should include security and input validation tests.
126
- - REQUIRED: Multiple test cases covering:
127
- * Happy path scenarios
128
- * Edge cases (null, undefined, empty arrays, etc.)
129
- * Error conditions
130
- * Async behavior (if applicable)
131
- - Proper TypeScript types
132
- - Clear, descriptive test names
133
- - Complete test implementations (NO placeholder comments!)
134
- 8. REQUIRED: Write the COMPLETE test file using write_test_file tool with REAL test code (NOT placeholders!)
135
- - CRITICAL: Include source_file parameter with path to source file (e.g., source_file: "{{sourceFile}}")
136
- - DO NOT use ANY placeholder comments like:
137
- * "// Mock setup", "// Assertions", "// Call function"
138
- * "// Further tests...", "// Additional tests..."
139
- * "// Similarly, write tests for..."
140
- * "// Add more tests...", "// TODO", "// ..."
141
- - Write ACTUAL working test code with real mocks, real assertions, real function calls
142
- - Every test MUST have:
143
- * Real setup code (mock functions, create test data)
144
- * Real execution (call the function being tested)
145
- * Real expect() assertions (at least one per test)
146
- - Write tests for EVERY exported function (minimum 3-5 tests per function)
147
- - If source has 4 functions, test file MUST have 4 describe blocks with actual tests
148
- - Example of COMPLETE test structure:
149
- * Setup: Create mocks and test data
150
- * Execute: Call the function being tested
151
- * Assert: Use expect() to verify results
152
- 9. REQUIRED: Run the tests using run_tests tool
153
- 10. REQUIRED: If tests fail with import errors:
154
- - Use find_file tool to locate the missing module
155
- - Use calculate_relative_path tool to get correct import path
156
- - PRIMARY METHOD (once test file exists): Use line-based editing:
157
- * read_file to get current test file with line numbers
158
- * insert_lines to add missing imports at correct position (e.g., line 3)
159
- * delete_lines to remove incorrect imports
160
- * replace_lines to fix import paths
161
- - FALLBACK: Only use edit_test_file or write_test_file if line-based editing isn't suitable
162
- 11. REQUIRED: If tests fail with other errors, analyze if they are FIXABLE or LEGITIMATE:
163
-
164
- FIXABLE ERRORS (you should fix these):
165
- - Wrong import paths
166
- - Missing mocks
167
- - Incorrect mock implementations
168
- - Wrong assertions or test logic
169
- - TypeScript compilation errors
170
- - Missing test setup/teardown
171
- - Cannot read properties of undefined
172
-
173
- LEGITIMATE FAILURES (source code bugs - DO NOT try to fix):
174
- - Function returns wrong type (e.g., undefined instead of object)
175
- - Missing null/undefined checks in source code
176
- - Logic errors in source code
177
- - Unhandled promise rejections in source code
178
- - Source code throws unexpected errors
179
-
180
- 12. If errors are FIXABLE (AFTER test file is written):
181
- - ✅ PRIMARY METHOD: Use line-based editing tools (RECOMMENDED):
182
- * read_file to get current test file with line numbers
183
- * delete_lines to remove incorrect lines
184
- * insert_lines to add missing code (e.g., mocks, imports)
185
- * replace_lines to fix specific line ranges
186
- * This is FASTER and MORE RELIABLE than rewriting entire file!
187
- - ⚠️ FALLBACK: Only use edit_test_file or write_test_file if:
188
- * Line-based editing is too complex (needs major restructuring)
189
- * Multiple scattered changes across the file
190
- - Then retry running tests
191
- 13. If errors are LEGITIMATE: Call report_legitimate_failure tool with details and STOP trying to fix
192
- - Provide failing test names, reason, and source code issue description
193
- - The test file will be kept as-is with legitimate failing tests
194
- 14. REQUIRED: Repeat steps 9-13 until tests pass OR legitimate failures are reported
195
- 15. REQUIRED: Ensure all functions are tested in the test file.
196
-
197
- CRITICAL: Distinguish between test bugs (fix them) and source code bugs (report and stop)!
198
-
199
- START NOW by calling the analyze_file_ast tool with the source file path.`,
200
- gemini: `You are a senior software engineer tasked with writing comprehensive Jest unit tests including edge cases for a TypeScript file.
201
-
202
- Source file: {{sourceFile}}
203
- Test file path: {{testFilePath}}
204
-
205
- IMPORTANT: You MUST use the provided tools to complete this task. Do not just respond with text.
206
-
207
- Your task (you MUST complete ALL steps):
208
- 1. FIRST: Use analyze_file_ast tool to get a complete AST analysis of the source file (functions, classes, types, exports)
209
- 2. Use get_imports_ast tool to understand all dependencies
210
- 3. For each dependency, use find_file to locate it and calculate_relative_path to get correct import paths for the test file
211
- 4. For complex functions, use get_function_ast tool to get detailed information including parameters, return types, and cyclomatic complexity
212
- 5. For classes, use get_class_methods tool to extract all methods
213
- 6. Use get_type_definitions tool to understand TypeScript types and interfaces
214
- 7. Generate comprehensive Jest unit tests with:
215
- - CRITICAL: Mock ALL imports BEFORE importing the source file to prevent initialization errors
216
- - Mock database modules like '../database' or '../database/index'
217
- - Mock models, services, and any modules that access config/database
218
- - Use jest.mock() calls at the TOP of the file before any imports
219
- - Test suites for each function/class
220
- - REQUIRED: Test cases should include security and input validation tests.
221
- - REQUIRED: Multiple test cases covering:
222
- * Happy path scenarios
223
- * Edge cases (null, undefined, empty arrays, etc.)
224
- * Error conditions
225
- * Async behavior (if applicable)
226
- - Proper TypeScript types
227
- - Clear, descriptive test names
228
- - Complete test implementations (NO placeholder comments!)
229
- 8. REQUIRED: Write the COMPLETE test file using write_test_file tool with REAL test code (NOT placeholders!)
230
- - CRITICAL: Include source_file parameter with path to source file (e.g., source_file: "{{sourceFile}}")
231
- - DO NOT use ANY placeholder comments like:
232
- * "// Mock setup", "// Assertions", "// Call function"
233
- * "// Further tests...", "// Additional tests..."
234
- * "// Similarly, write tests for..."
235
- * "// Add more tests...", "// TODO", "// ..."
236
- - Write ACTUAL working test code with real mocks, real assertions, real function calls
237
- - Every test MUST have:
238
- * Real setup code (mock functions, create test data)
239
- * Real execution (call the function being tested)
240
- * Real expect() assertions (at least one per test)
241
- - Write tests for EVERY exported function (minimum 3-5 tests per function)
242
- - If source has 4 functions, test file MUST have 4 describe blocks with actual tests
243
- - Example of COMPLETE test structure:
244
- * Setup: Create mocks and test data
245
- * Execute: Call the function being tested
246
- * Assert: Use expect() to verify results
247
- 9. REQUIRED: Run the tests using run_tests tool
248
- 10. REQUIRED: If tests fail with import errors:
249
- - Use find_file tool to locate the missing module
250
- - Use calculate_relative_path tool to get correct import path
251
- - PRIMARY METHOD (once test file exists): Use line-based editing:
252
- * read_file to get current test file with line numbers
253
- * insert_lines to add missing imports at correct position (e.g., line 3)
254
- * delete_lines to remove incorrect imports
255
- * replace_lines to fix import paths
256
- - FALLBACK: Only use edit_test_file or write_test_file if line-based editing isn't suitable
257
- 11. REQUIRED: If tests fail with other errors, analyze if they are FIXABLE or LEGITIMATE:
258
-
259
- FIXABLE ERRORS (you should fix these):
260
- - Wrong import paths
261
- - Missing mocks
262
- - Incorrect mock implementations
263
- - Wrong assertions or test logic
264
- - TypeScript compilation errors
265
- - Missing test setup/teardown
266
- - Cannot read properties of undefined
267
-
268
- LEGITIMATE FAILURES (source code bugs - DO NOT try to fix):
269
- - Function returns wrong type (e.g., undefined instead of object)
270
- - Missing null/undefined checks in source code
271
- - Logic errors in source code
272
- - Unhandled promise rejections in source code
273
- - Source code throws unexpected errors
274
-
275
- 12. If errors are FIXABLE (AFTER test file is written):
276
- - ✅ PRIMARY METHOD: Use line-based editing tools (RECOMMENDED):
277
- * read_file to get current test file with line numbers
278
- * delete_lines to remove incorrect lines
279
- * insert_lines to add missing code (e.g., mocks, imports)
280
- * replace_lines to fix specific line ranges
281
- * This is FASTER and MORE RELIABLE than rewriting entire file!
282
- - ⚠️ FALLBACK: Only use edit_test_file or write_test_file if:
283
- * Line-based editing is too complex (needs major restructuring)
284
- * Multiple scattered changes across the file
285
- - Then retry running tests
286
- 13. If errors are LEGITIMATE: Call report_legitimate_failure tool with details and STOP trying to fix
287
- - Provide failing test names, reason, and source code issue description
288
- - The test file will be kept as-is with legitimate failing tests
289
- 14. REQUIRED: Repeat steps 9-13 until tests pass OR legitimate failures are reported
290
- 15. REQUIRED: Ensure all functions are tested in the test file.
291
-
292
- CRITICAL: Distinguish between test bugs (fix them) and source code bugs (report and stop)!
293
-
294
- START NOW by calling the analyze_file_ast tool with the source file path.`
295
- };
296
- // Function-wise test generation prompts
297
- exports.FUNCTIONWISE_PROMPTS = {
298
- claude: `You are a senior software engineer tasked with writing comprehensive Jest unit tests for specific functions in a TypeScript file.
299
-
300
- Source file: {{sourceFile}}
301
- Test file path: {{testFilePath}}
302
- Test file exists: {{testFileExists}}
303
- Selected functions to test: {{functionNames}}
304
-
305
- IMPORTANT: You MUST use the provided tools to complete this task. Do not just respond with text.
306
-
307
- {{conditionalWarning}}
308
-
309
- Your task (you MUST complete ALL steps):
310
- 1. FIRST: Use analyze_file_ast tool to get information about the selected functions: {{functionNames}}
311
- 2. Use get_function_ast tool for each selected function to get detailed information
312
- 3. Use get_imports_ast tool to understand dependencies
313
- 4. For each dependency, use find_file to locate it and calculate_relative_path to get correct import paths
314
- 5. Generate comprehensive Jest unit tests ONLY for these functions: {{functionNames}}
315
- - CRITICAL: Mock ALL imports BEFORE importing the source file to prevent initialization errors
316
- - Mock database modules, models, services, and config modules
317
- - Use jest.mock() calls at the TOP of the file before any imports
318
- - Test suites for each selected function
319
- - Multiple test cases covering:
320
- * Happy path scenarios
321
- * Edge cases (null, undefined, empty arrays, etc.)
322
- * Error conditions
323
- * Async behavior (if applicable)
324
- - Proper TypeScript types
325
- - Clear, descriptive test names
326
- - Complete test implementations (NO placeholder comments!)
327
- {{conditionalInstruction}}
328
- 7. REQUIRED: Run the tests using run_tests tool
329
- 8. REQUIRED: If tests fail, analyze if errors are FIXABLE or LEGITIMATE:
330
-
331
- FIXABLE ERRORS (fix these):
332
- - Wrong import paths → use find_file + calculate_relative_path + edit tools
333
- - Missing mocks → add proper jest.mock() calls
334
- - Incorrect mock implementations → update mock return values
335
- - Wrong test assertions → fix expect() statements
336
- - TypeScript errors → fix types and imports
337
-
338
- LEGITIMATE FAILURES (report these):
339
- - Function returns wrong type (source code bug)
340
- - Missing null checks in source code
341
- - Logic errors in source code
342
- - Source code throws unexpected errors
343
-
344
- 9. If FIXABLE (AFTER test file is written/updated):
345
- {{conditionalFixing}}
346
- - Then retry tests
347
- 10. If LEGITIMATE: Call report_legitimate_failure with details and STOP
348
- 11. REQUIRED: Repeat steps 7-10 until tests pass OR legitimate failures reported
349
-
350
- {{conditionalReminder}}
351
-
352
- CRITICAL: Fix test bugs but REPORT source code bugs (don't try to make broken code pass)!
353
-
354
- START NOW by calling the analyze_file_ast tool with the source file path.`,
355
- openai: `You are a senior software engineer tasked with writing comprehensive Jest unit tests for specific functions in a TypeScript file.
356
-
357
- Source file: {{sourceFile}}
358
- Test file path: {{testFilePath}}
359
- Test file exists: {{testFileExists}}
360
- Selected functions to test: {{functionNames}}
361
-
362
- IMPORTANT: You MUST use the provided tools to complete this task. Do not just respond with text.
363
-
364
- {{conditionalWarning}}
365
-
366
- Your task (you MUST complete ALL steps):
367
- 1. FIRST: Use analyze_file_ast tool to get information about the selected functions: {{functionNames}}
368
- 2. Use get_function_ast tool for each selected function to get detailed information
369
- 3. Use get_imports_ast tool to understand dependencies
370
- 4. For each dependency, use find_file to locate it and calculate_relative_path to get correct import paths
371
- 5. Generate comprehensive Jest unit tests ONLY for these functions: {{functionNames}}
372
- - CRITICAL: Mock ALL imports BEFORE importing the source file to prevent initialization errors
373
- - Mock database modules, models, services, and config modules
374
- - Use jest.mock() calls at the TOP of the file before any imports
375
- - Test suites for each selected function
376
- - Multiple test cases covering:
377
- * Happy path scenarios
378
- * Edge cases (null, undefined, empty arrays, etc.)
379
- * Error conditions
380
- * Async behavior (if applicable)
381
- - Proper TypeScript types
382
- - Clear, descriptive test names
383
- - Complete test implementations (NO placeholder comments!)
384
- {{conditionalInstruction}}
385
- 7. REQUIRED: Run the tests using run_tests tool
386
- 8. REQUIRED: If tests fail, analyze if errors are FIXABLE or LEGITIMATE:
387
-
388
- FIXABLE ERRORS (fix these):
389
- - Wrong import paths → use find_file + calculate_relative_path + edit tools
390
- - Missing mocks → add proper jest.mock() calls
391
- - Incorrect mock implementations → update mock return values
392
- - Wrong test assertions → fix expect() statements
393
- - TypeScript errors → fix types and imports
394
-
395
- LEGITIMATE FAILURES (report these):
396
- - Function returns wrong type (source code bug)
397
- - Missing null checks in source code
398
- - Logic errors in source code
399
- - Source code throws unexpected errors
400
-
401
- 9. If FIXABLE (AFTER test file is written/updated):
402
- {{conditionalFixing}}
403
- - Then retry tests
404
- 10. If LEGITIMATE: Call report_legitimate_failure with details and STOP
405
- 11. REQUIRED: Repeat steps 7-10 until tests pass OR legitimate failures reported
406
-
407
- {{conditionalReminder}}
408
-
409
- CRITICAL: Fix test bugs but REPORT source code bugs (don't try to make broken code pass)!
410
-
411
- START NOW by calling the analyze_file_ast tool with the source file path.`,
412
- gemini: `You are a senior software engineer tasked with writing comprehensive Jest unit tests for specific functions in a TypeScript file.
413
-
414
- Source file: {{sourceFile}}
415
- Test file path: {{testFilePath}}
416
- Test file exists: {{testFileExists}}
417
- Selected functions to test: {{functionNames}}
418
-
419
- IMPORTANT: You MUST use the provided tools to complete this task. Do not just respond with text.
420
-
421
- {{conditionalWarning}}
422
-
423
- Your task (you MUST complete ALL steps):
424
- 1. FIRST: Use analyze_file_ast tool to get information about the selected functions: {{functionNames}}
425
- 2. Use get_function_ast tool for each selected function to get detailed information
426
- 3. Use get_imports_ast tool to understand dependencies
427
- 4. For each dependency, use find_file to locate it and calculate_relative_path to get correct import paths
428
- 5. Generate comprehensive Jest unit tests ONLY for these functions: {{functionNames}}
429
- - CRITICAL: Mock ALL imports BEFORE importing the source file to prevent initialization errors
430
- - Mock database modules, models, services, and config modules
431
- - Use jest.mock() calls at the TOP of the file before any imports
432
- - Test suites for each selected function
433
- - Multiple test cases covering:
434
- * Happy path scenarios
435
- * Edge cases (null, undefined, empty arrays, etc.)
436
- * Error conditions
437
- * Async behavior (if applicable)
438
- - Proper TypeScript types
439
- - Clear, descriptive test names
440
- - Complete test implementations (NO placeholder comments!)
441
- {{conditionalInstruction}}
442
- 7. REQUIRED: Run the tests using run_tests tool
443
- 8. REQUIRED: If tests fail, analyze if errors are FIXABLE or LEGITIMATE:
444
-
445
- FIXABLE ERRORS (fix these):
446
- - Wrong import paths → use find_file + calculate_relative_path + edit tools
447
- - Missing mocks → add proper jest.mock() calls
448
- - Incorrect mock implementations → update mock return values
449
- - Wrong test assertions → fix expect() statements
450
- - TypeScript errors → fix types and imports
451
-
452
- LEGITIMATE FAILURES (report these):
453
- - Function returns wrong type (source code bug)
454
- - Missing null checks in source code
455
- - Logic errors in source code
456
- - Source code throws unexpected errors
457
-
458
- 9. If FIXABLE (AFTER test file is written/updated):
459
- {{conditionalFixing}}
460
- - Then retry tests
461
- 10. If LEGITIMATE: Call report_legitimate_failure with details and STOP
462
- 11. REQUIRED: Repeat steps 7-10 until tests pass OR legitimate failures reported
463
-
464
- {{conditionalReminder}}
465
-
466
- CRITICAL: Fix test bugs but REPORT source code bugs (don't try to make broken code pass)!
467
-
468
- START NOW by calling the analyze_file_ast tool with the source file path.`
469
- };
470
- //# sourceMappingURL=prompts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,wFAAwF;AAC3E,QAAA,gBAAgB,GAAoB;IAC/C,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EA8FgE;IAExE,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EA8FgE;IAExE,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EA8FgE;CACzE,CAAC;AAEF,wCAAwC;AAC3B,QAAA,oBAAoB,GAAoB;IACnD,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EAwDgE;IAExE,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EAwDgE;IAExE,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0EAwDgE;CACzE,CAAC"}