@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/dist/index.js CHANGED
@@ -95,24 +95,11 @@ async function findProjectRoot(startPath) {
95
95
  async function loadConfig() {
96
96
  const explorer = cosmiconfig("kakarot", {
97
97
  searchPlaces: [
98
- "kakarot.config.ts",
99
98
  "kakarot.config.js",
100
- ".kakarot-ci.config.ts",
101
99
  ".kakarot-ci.config.js",
102
100
  ".kakarot-ci.config.json",
103
101
  "package.json"
104
- ],
105
- loaders: {
106
- ".ts": async (filepath) => {
107
- try {
108
- const configModule = await import(filepath);
109
- return configModule.default || configModule.config || null;
110
- } catch (err) {
111
- error(`Failed to load TypeScript config: ${err instanceof Error ? err.message : String(err)}`);
112
- return null;
113
- }
114
- }
115
- }
102
+ ]
116
103
  });
117
104
  try {
118
105
  const result = await explorer.search();
@@ -149,7 +136,7 @@ async function loadConfig() {
149
136
  } catch (err) {
150
137
  if (err instanceof Error && err.message.includes("apiKey")) {
151
138
  error(
152
- "Missing required apiKey. Provide it via:\n - Config file (kakarot.config.ts, .kakarot-ci.config.js/json, or package.json)\n - Environment variable: KAKAROT_API_KEY"
139
+ "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"
153
140
  );
154
141
  }
155
142
  throw err;
@@ -372,6 +359,7 @@ var GitHubClient = class {
372
359
  async fileExists(ref, path) {
373
360
  const originalError = console.error;
374
361
  const originalWarn = console.warn;
362
+ const originalLog = console.log;
375
363
  const suppress404 = (...args) => {
376
364
  const message = String(args[0] || "");
377
365
  if (message.includes("404") || message.includes("Not Found")) {
@@ -386,9 +374,17 @@ var GitHubClient = class {
386
374
  }
387
375
  originalWarn(...args);
388
376
  };
377
+ const suppress404Log = (...args) => {
378
+ const message = String(args[0] || "");
379
+ if (message.includes("404") || message.includes("Not Found")) {
380
+ return;
381
+ }
382
+ originalLog(...args);
383
+ };
389
384
  try {
390
385
  console.error = suppress404;
391
386
  console.warn = suppress404Warn;
387
+ console.log = suppress404Log;
392
388
  await this.octokit.rest.repos.getContent({
393
389
  owner: this.owner,
394
390
  repo: this.repo,
@@ -411,6 +407,7 @@ var GitHubClient = class {
411
407
  } finally {
412
408
  console.error = originalError;
413
409
  console.warn = originalWarn;
410
+ console.log = originalLog;
414
411
  }
415
412
  }
416
413
  /**
@@ -1082,15 +1079,49 @@ function buildSystemPrompt(framework) {
1082
1079
  const importStatement = framework === "jest" ? "import { describe, it, expect } from 'jest';" : "import { describe, it, expect } from 'vitest';";
1083
1080
  return `You are an expert ${frameworkName} test writer. Your task is to generate comprehensive unit tests for TypeScript/JavaScript functions.
1084
1081
 
1082
+ CRITICAL: Test the ACTUAL behavior of the code, not assumed behavior.
1083
+
1085
1084
  Requirements:
1086
1085
  1. Generate complete, runnable ${frameworkName} test code
1087
1086
  2. Use ${frameworkName} syntax and best practices
1088
- 3. Test edge cases, error conditions, and normal operation
1089
- 4. Use descriptive test names that explain what is being tested
1090
- 5. Include proper setup/teardown if needed
1091
- 6. Mock external dependencies appropriately
1092
- 7. Test both success and failure scenarios
1093
- 8. Follow the existing test file structure if one exists
1087
+ 3. Analyze the function code to determine its ACTUAL runtime behavior before writing tests
1088
+ 4. Test edge cases and normal operation based on what the code actually does
1089
+ 5. Only test for errors/exceptions if the code actually throws them (check for try/catch, throw statements, or validation logic)
1090
+ 6. Match JavaScript/TypeScript runtime semantics:
1091
+ - Arithmetic operations (+, -, *, /, %, **) do NOT throw errors for invalid inputs; they return NaN or Infinity
1092
+ - Division by zero returns Infinity (not an error)
1093
+ - Modulo by zero returns NaN (not an error)
1094
+ - Bitwise operations convert values to 32-bit integers
1095
+ - Operations with null/undefined may coerce to numbers or return NaN
1096
+ - TypeScript types are compile-time only; runtime behavior follows JavaScript rules
1097
+ 7. For async functions:
1098
+ - Use async/await or .then()/.catch() appropriately
1099
+ - Test both resolved and rejected promises
1100
+ - Use resolves and rejects matchers when appropriate
1101
+ - Await async function calls in tests
1102
+ 8. For functions with side effects or external dependencies:
1103
+ - Mock external dependencies (APIs, file system, databases, etc.)
1104
+ - Mock imported modules using ${framework === "jest" ? "jest.mock()" : "vi.mock()"}
1105
+ - Reset mocks between tests to ensure test isolation
1106
+ - Verify mock calls if the function's behavior depends on them
1107
+ 9. For functions that modify state:
1108
+ - Test state before and after function calls
1109
+ - Reset state between tests if needed
1110
+ - Test state mutations, not just return values
1111
+ 10. For error testing:
1112
+ - Only test for errors if the function actually throws them
1113
+ - Match actual error types and messages (use toThrow() with specific error types/messages)
1114
+ - For async errors, use rejects matcher
1115
+ 11. Import handling:
1116
+ - Use the same import paths as the source file
1117
+ - Import types correctly (type imports for TypeScript types)
1118
+ - Mock dependencies at the module level, not the function level
1119
+ 12. Test isolation:
1120
+ - Each test should be independent and not rely on other tests
1121
+ - Use beforeEach/afterEach for setup/teardown when needed
1122
+ - Don't share mutable state between tests
1123
+ 13. Use descriptive test names that explain what is being tested
1124
+ 14. Follow the existing test file structure if one exists
1094
1125
 
1095
1126
  Output format:
1096
1127
  - Return ONLY the test code, no explanations or markdown code blocks
@@ -1160,18 +1191,38 @@ ${existingTestFile}
1160
1191
 
1161
1192
  `;
1162
1193
  }
1163
- prompt += `Generate comprehensive unit tests for ${target.functionName}. Include:
1194
+ prompt += `Generate comprehensive unit tests for ${target.functionName}. IMPORTANT: Analyze the function code above to determine its ACTUAL behavior before writing tests.
1195
+
1196
+ `;
1197
+ prompt += `Include:
1164
1198
  `;
1165
1199
  prompt += `- Tests for normal operation with various inputs
1166
1200
  `;
1167
- prompt += `- Tests for edge cases (null, undefined, empty arrays, etc.)
1201
+ prompt += `- Tests for edge cases based on what the code actually does (null, undefined, empty arrays, etc.)
1168
1202
  `;
1169
- prompt += `- Tests for error conditions if applicable
1203
+ prompt += `- Tests for error conditions ONLY if the code actually throws errors (check for throw statements, validation, or error handling)
1170
1204
  `;
1171
1205
  prompt += `- Tests for boundary conditions
1172
1206
  `;
1173
1207
  prompt += `- Proper mocking of dependencies if needed
1174
1208
 
1209
+ `;
1210
+ prompt += `Key considerations:
1211
+ `;
1212
+ prompt += `- If the function is async, use async/await in tests and test both success and error cases
1213
+ `;
1214
+ prompt += `- If the function uses external dependencies (imports), mock them appropriately
1215
+ `;
1216
+ prompt += `- If the function modifies state, test the state changes
1217
+ `;
1218
+ prompt += `- Match actual return types and values, not assumed types
1219
+ `;
1220
+ prompt += `- TypeScript types are compile-time only; test runtime behavior
1221
+ `;
1222
+ 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.
1223
+ `;
1224
+ prompt += `- Use the same import paths as the source file for consistency
1225
+
1175
1226
  `;
1176
1227
  prompt += `Return ONLY the test code, no explanations or markdown formatting.`;
1177
1228
  return prompt;
@@ -1196,13 +1247,34 @@ Context:
1196
1247
  - The test code failed to run or produced incorrect results
1197
1248
  - You need to analyze the error and fix the test code
1198
1249
 
1250
+ CRITICAL: Tests must match the ACTUAL behavior of the code being tested, not assumed behavior.
1251
+
1199
1252
  Requirements:
1200
- 1. Fix the test code to make it pass
1201
- 2. Maintain the original test intent
1202
- 3. Use proper ${frameworkName} syntax
1203
- 4. Ensure all imports and dependencies are correct
1204
- 5. Fix any syntax errors, type errors, or logical errors
1205
- 6. If the original code being tested has issues, note that but focus on fixing the test
1253
+ 1. Analyze the original function code to understand its ACTUAL runtime behavior
1254
+ 2. Fix the test code to match what the function actually does, not what it "should" do
1255
+ 3. Only expect errors/exceptions if the function code actually throws them
1256
+ 4. Match JavaScript/TypeScript runtime semantics:
1257
+ - Arithmetic operations do NOT throw errors; they return NaN or Infinity
1258
+ - Division by zero returns Infinity (not an error)
1259
+ - Modulo by zero returns NaN (not an error)
1260
+ - Bitwise operations convert values to 32-bit integers
1261
+ - TypeScript types are compile-time only; runtime behavior follows JavaScript rules
1262
+ 5. For async functions:
1263
+ - Ensure tests properly await async calls
1264
+ - Use resolves/rejects matchers appropriately
1265
+ - Test both success and error cases for async functions
1266
+ 6. For functions with dependencies:
1267
+ - Ensure mocks are properly set up
1268
+ - Verify import paths match the source file
1269
+ - Reset mocks if needed for test isolation
1270
+ 7. For error testing:
1271
+ - Only expect errors if the function actually throws them
1272
+ - Match actual error types and messages
1273
+ - Use appropriate matchers (toThrow, rejects, etc.)
1274
+ 8. Maintain the original test intent where possible, but prioritize correctness
1275
+ 9. Use proper ${frameworkName} syntax
1276
+ 10. Ensure all imports and dependencies are correct
1277
+ 11. Fix any syntax errors, type errors, or logical errors
1206
1278
 
1207
1279
  Output format:
1208
1280
  - Return ONLY the fixed test code, no explanations or markdown code blocks