@kakarot-ci/core 0.7.0 → 0.7.1
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.
- package/README.md +457 -2
- package/dist/cli/index.js +102 -30
- package/dist/cli/index.js.map +2 -2
- package/dist/index.cjs +102 -30
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +102 -30
- package/dist/index.js.map +2 -2
- package/dist/src/github/client.d.ts.map +1 -1
- package/dist/src/utils/config-loader.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -161,24 +161,11 @@ async function findProjectRoot(startPath) {
|
|
|
161
161
|
async function loadConfig() {
|
|
162
162
|
const explorer = (0, import_cosmiconfig.cosmiconfig)("kakarot", {
|
|
163
163
|
searchPlaces: [
|
|
164
|
-
"kakarot.config.ts",
|
|
165
164
|
"kakarot.config.js",
|
|
166
|
-
".kakarot-ci.config.ts",
|
|
167
165
|
".kakarot-ci.config.js",
|
|
168
166
|
".kakarot-ci.config.json",
|
|
169
167
|
"package.json"
|
|
170
|
-
]
|
|
171
|
-
loaders: {
|
|
172
|
-
".ts": async (filepath) => {
|
|
173
|
-
try {
|
|
174
|
-
const configModule = await import(filepath);
|
|
175
|
-
return configModule.default || configModule.config || null;
|
|
176
|
-
} catch (err) {
|
|
177
|
-
error(`Failed to load TypeScript config: ${err instanceof Error ? err.message : String(err)}`);
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
168
|
+
]
|
|
182
169
|
});
|
|
183
170
|
try {
|
|
184
171
|
const result = await explorer.search();
|
|
@@ -215,7 +202,7 @@ async function loadConfig() {
|
|
|
215
202
|
} catch (err) {
|
|
216
203
|
if (err instanceof Error && err.message.includes("apiKey")) {
|
|
217
204
|
error(
|
|
218
|
-
"Missing required apiKey. Provide it via:\n - Config file (kakarot.config.
|
|
205
|
+
"Missing required apiKey. Provide it via:\n - Config file (kakarot.config.js, .kakarot-ci.config.js/json, or package.json)\n - Environment variable: KAKAROT_API_KEY"
|
|
219
206
|
);
|
|
220
207
|
}
|
|
221
208
|
throw err;
|
|
@@ -438,6 +425,7 @@ var GitHubClient = class {
|
|
|
438
425
|
async fileExists(ref, path) {
|
|
439
426
|
const originalError = console.error;
|
|
440
427
|
const originalWarn = console.warn;
|
|
428
|
+
const originalLog = console.log;
|
|
441
429
|
const suppress404 = (...args) => {
|
|
442
430
|
const message = String(args[0] || "");
|
|
443
431
|
if (message.includes("404") || message.includes("Not Found")) {
|
|
@@ -452,9 +440,17 @@ var GitHubClient = class {
|
|
|
452
440
|
}
|
|
453
441
|
originalWarn(...args);
|
|
454
442
|
};
|
|
443
|
+
const suppress404Log = (...args) => {
|
|
444
|
+
const message = String(args[0] || "");
|
|
445
|
+
if (message.includes("404") || message.includes("Not Found")) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
originalLog(...args);
|
|
449
|
+
};
|
|
455
450
|
try {
|
|
456
451
|
console.error = suppress404;
|
|
457
452
|
console.warn = suppress404Warn;
|
|
453
|
+
console.log = suppress404Log;
|
|
458
454
|
await this.octokit.rest.repos.getContent({
|
|
459
455
|
owner: this.owner,
|
|
460
456
|
repo: this.repo,
|
|
@@ -477,6 +473,7 @@ var GitHubClient = class {
|
|
|
477
473
|
} finally {
|
|
478
474
|
console.error = originalError;
|
|
479
475
|
console.warn = originalWarn;
|
|
476
|
+
console.log = originalLog;
|
|
480
477
|
}
|
|
481
478
|
}
|
|
482
479
|
/**
|
|
@@ -1148,15 +1145,49 @@ function buildSystemPrompt(framework) {
|
|
|
1148
1145
|
const importStatement = framework === "jest" ? "import { describe, it, expect } from 'jest';" : "import { describe, it, expect } from 'vitest';";
|
|
1149
1146
|
return `You are an expert ${frameworkName} test writer. Your task is to generate comprehensive unit tests for TypeScript/JavaScript functions.
|
|
1150
1147
|
|
|
1148
|
+
CRITICAL: Test the ACTUAL behavior of the code, not assumed behavior.
|
|
1149
|
+
|
|
1151
1150
|
Requirements:
|
|
1152
1151
|
1. Generate complete, runnable ${frameworkName} test code
|
|
1153
1152
|
2. Use ${frameworkName} syntax and best practices
|
|
1154
|
-
3.
|
|
1155
|
-
4.
|
|
1156
|
-
5.
|
|
1157
|
-
6.
|
|
1158
|
-
|
|
1159
|
-
|
|
1153
|
+
3. Analyze the function code to determine its ACTUAL runtime behavior before writing tests
|
|
1154
|
+
4. Test edge cases and normal operation based on what the code actually does
|
|
1155
|
+
5. Only test for errors/exceptions if the code actually throws them (check for try/catch, throw statements, or validation logic)
|
|
1156
|
+
6. Match JavaScript/TypeScript runtime semantics:
|
|
1157
|
+
- Arithmetic operations (+, -, *, /, %, **) do NOT throw errors for invalid inputs; they return NaN or Infinity
|
|
1158
|
+
- Division by zero returns Infinity (not an error)
|
|
1159
|
+
- Modulo by zero returns NaN (not an error)
|
|
1160
|
+
- Bitwise operations convert values to 32-bit integers
|
|
1161
|
+
- Operations with null/undefined may coerce to numbers or return NaN
|
|
1162
|
+
- TypeScript types are compile-time only; runtime behavior follows JavaScript rules
|
|
1163
|
+
7. For async functions:
|
|
1164
|
+
- Use async/await or .then()/.catch() appropriately
|
|
1165
|
+
- Test both resolved and rejected promises
|
|
1166
|
+
- Use resolves and rejects matchers when appropriate
|
|
1167
|
+
- Await async function calls in tests
|
|
1168
|
+
8. For functions with side effects or external dependencies:
|
|
1169
|
+
- Mock external dependencies (APIs, file system, databases, etc.)
|
|
1170
|
+
- Mock imported modules using ${framework === "jest" ? "jest.mock()" : "vi.mock()"}
|
|
1171
|
+
- Reset mocks between tests to ensure test isolation
|
|
1172
|
+
- Verify mock calls if the function's behavior depends on them
|
|
1173
|
+
9. For functions that modify state:
|
|
1174
|
+
- Test state before and after function calls
|
|
1175
|
+
- Reset state between tests if needed
|
|
1176
|
+
- Test state mutations, not just return values
|
|
1177
|
+
10. For error testing:
|
|
1178
|
+
- Only test for errors if the function actually throws them
|
|
1179
|
+
- Match actual error types and messages (use toThrow() with specific error types/messages)
|
|
1180
|
+
- For async errors, use rejects matcher
|
|
1181
|
+
11. Import handling:
|
|
1182
|
+
- Use the same import paths as the source file
|
|
1183
|
+
- Import types correctly (type imports for TypeScript types)
|
|
1184
|
+
- Mock dependencies at the module level, not the function level
|
|
1185
|
+
12. Test isolation:
|
|
1186
|
+
- Each test should be independent and not rely on other tests
|
|
1187
|
+
- Use beforeEach/afterEach for setup/teardown when needed
|
|
1188
|
+
- Don't share mutable state between tests
|
|
1189
|
+
13. Use descriptive test names that explain what is being tested
|
|
1190
|
+
14. Follow the existing test file structure if one exists
|
|
1160
1191
|
|
|
1161
1192
|
Output format:
|
|
1162
1193
|
- Return ONLY the test code, no explanations or markdown code blocks
|
|
@@ -1226,18 +1257,38 @@ ${existingTestFile}
|
|
|
1226
1257
|
|
|
1227
1258
|
`;
|
|
1228
1259
|
}
|
|
1229
|
-
prompt += `Generate comprehensive unit tests for ${target.functionName}.
|
|
1260
|
+
prompt += `Generate comprehensive unit tests for ${target.functionName}. IMPORTANT: Analyze the function code above to determine its ACTUAL behavior before writing tests.
|
|
1261
|
+
|
|
1262
|
+
`;
|
|
1263
|
+
prompt += `Include:
|
|
1230
1264
|
`;
|
|
1231
1265
|
prompt += `- Tests for normal operation with various inputs
|
|
1232
1266
|
`;
|
|
1233
|
-
prompt += `- Tests for edge cases (null, undefined, empty arrays, etc.)
|
|
1267
|
+
prompt += `- Tests for edge cases based on what the code actually does (null, undefined, empty arrays, etc.)
|
|
1234
1268
|
`;
|
|
1235
|
-
prompt += `- Tests for error conditions if
|
|
1269
|
+
prompt += `- Tests for error conditions ONLY if the code actually throws errors (check for throw statements, validation, or error handling)
|
|
1236
1270
|
`;
|
|
1237
1271
|
prompt += `- Tests for boundary conditions
|
|
1238
1272
|
`;
|
|
1239
1273
|
prompt += `- Proper mocking of dependencies if needed
|
|
1240
1274
|
|
|
1275
|
+
`;
|
|
1276
|
+
prompt += `Key considerations:
|
|
1277
|
+
`;
|
|
1278
|
+
prompt += `- If the function is async, use async/await in tests and test both success and error cases
|
|
1279
|
+
`;
|
|
1280
|
+
prompt += `- If the function uses external dependencies (imports), mock them appropriately
|
|
1281
|
+
`;
|
|
1282
|
+
prompt += `- If the function modifies state, test the state changes
|
|
1283
|
+
`;
|
|
1284
|
+
prompt += `- Match actual return types and values, not assumed types
|
|
1285
|
+
`;
|
|
1286
|
+
prompt += `- TypeScript types are compile-time only; test runtime behavior
|
|
1287
|
+
`;
|
|
1288
|
+
prompt += `- JavaScript/TypeScript arithmetic and bitwise operations do NOT throw errors for invalid inputs. They return NaN, Infinity, or perform type coercion. Only test for errors if the function code explicitly throws them.
|
|
1289
|
+
`;
|
|
1290
|
+
prompt += `- Use the same import paths as the source file for consistency
|
|
1291
|
+
|
|
1241
1292
|
`;
|
|
1242
1293
|
prompt += `Return ONLY the test code, no explanations or markdown formatting.`;
|
|
1243
1294
|
return prompt;
|
|
@@ -1262,13 +1313,34 @@ Context:
|
|
|
1262
1313
|
- The test code failed to run or produced incorrect results
|
|
1263
1314
|
- You need to analyze the error and fix the test code
|
|
1264
1315
|
|
|
1316
|
+
CRITICAL: Tests must match the ACTUAL behavior of the code being tested, not assumed behavior.
|
|
1317
|
+
|
|
1265
1318
|
Requirements:
|
|
1266
|
-
1.
|
|
1267
|
-
2.
|
|
1268
|
-
3.
|
|
1269
|
-
4.
|
|
1270
|
-
|
|
1271
|
-
|
|
1319
|
+
1. Analyze the original function code to understand its ACTUAL runtime behavior
|
|
1320
|
+
2. Fix the test code to match what the function actually does, not what it "should" do
|
|
1321
|
+
3. Only expect errors/exceptions if the function code actually throws them
|
|
1322
|
+
4. Match JavaScript/TypeScript runtime semantics:
|
|
1323
|
+
- Arithmetic operations do NOT throw errors; they return NaN or Infinity
|
|
1324
|
+
- Division by zero returns Infinity (not an error)
|
|
1325
|
+
- Modulo by zero returns NaN (not an error)
|
|
1326
|
+
- Bitwise operations convert values to 32-bit integers
|
|
1327
|
+
- TypeScript types are compile-time only; runtime behavior follows JavaScript rules
|
|
1328
|
+
5. For async functions:
|
|
1329
|
+
- Ensure tests properly await async calls
|
|
1330
|
+
- Use resolves/rejects matchers appropriately
|
|
1331
|
+
- Test both success and error cases for async functions
|
|
1332
|
+
6. For functions with dependencies:
|
|
1333
|
+
- Ensure mocks are properly set up
|
|
1334
|
+
- Verify import paths match the source file
|
|
1335
|
+
- Reset mocks if needed for test isolation
|
|
1336
|
+
7. For error testing:
|
|
1337
|
+
- Only expect errors if the function actually throws them
|
|
1338
|
+
- Match actual error types and messages
|
|
1339
|
+
- Use appropriate matchers (toThrow, rejects, etc.)
|
|
1340
|
+
8. Maintain the original test intent where possible, but prioritize correctness
|
|
1341
|
+
9. Use proper ${frameworkName} syntax
|
|
1342
|
+
10. Ensure all imports and dependencies are correct
|
|
1343
|
+
11. Fix any syntax errors, type errors, or logical errors
|
|
1272
1344
|
|
|
1273
1345
|
Output format:
|
|
1274
1346
|
- Return ONLY the fixed test code, no explanations or markdown code blocks
|