@probelabs/visor 0.1.81 → 0.1.82

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/sdk/sdk.js CHANGED
@@ -7324,172 +7324,187 @@ ${expr}
7324
7324
  let finalResult;
7325
7325
  if (isForEachDependent && forEachParentName) {
7326
7326
  this.recordForEachPreview(checkName, forEachItems);
7327
- if (debug) {
7328
- log2(
7329
- `\u{1F504} Debug: Check "${checkName}" depends on forEach check "${forEachParentName}", executing ${forEachItems.length} times`
7327
+ if (forEachItems.length === 0) {
7328
+ if (debug) {
7329
+ log2(
7330
+ `\u{1F504} Debug: Skipping check "${checkName}" - forEach check "${forEachParentName}" returned 0 items`
7331
+ );
7332
+ }
7333
+ logger.info(` forEach: no items from "${forEachParentName}", skipping check...`);
7334
+ finalResult = {
7335
+ issues: [],
7336
+ output: []
7337
+ };
7338
+ finalResult.isForEach = true;
7339
+ finalResult.forEachItems = [];
7340
+ } else {
7341
+ if (debug) {
7342
+ log2(
7343
+ `\u{1F504} Debug: Check "${checkName}" depends on forEach check "${forEachParentName}", executing ${forEachItems.length} times`
7344
+ );
7345
+ }
7346
+ logger.info(
7347
+ ` forEach: processing ${forEachItems.length} items from "${forEachParentName}"...`
7330
7348
  );
7331
- }
7332
- logger.info(
7333
- ` forEach: processing ${forEachItems.length} items from "${forEachParentName}"...`
7334
- );
7335
- const allIssues = [];
7336
- const allOutputs = [];
7337
- const aggregatedContents = [];
7338
- const itemTasks = forEachItems.map((item, itemIndex) => async () => {
7339
- const forEachDependencyResults = /* @__PURE__ */ new Map();
7340
- for (const [depName, depResult] of dependencyResults) {
7341
- if (forEachParents.includes(depName)) {
7342
- const depForEachResult = depResult;
7343
- if (Array.isArray(depForEachResult.output) && depForEachResult.output[itemIndex] !== void 0) {
7344
- const modifiedResult = {
7345
- issues: [],
7346
- output: depForEachResult.output[itemIndex]
7347
- };
7348
- forEachDependencyResults.set(depName, modifiedResult);
7349
- const rawResult = {
7350
- issues: [],
7351
- output: depForEachResult.output
7352
- };
7353
- forEachDependencyResults.set(`${depName}-raw`, rawResult);
7349
+ const allIssues = [];
7350
+ const allOutputs = [];
7351
+ const aggregatedContents = [];
7352
+ const itemTasks = forEachItems.map((item, itemIndex) => async () => {
7353
+ const forEachDependencyResults = /* @__PURE__ */ new Map();
7354
+ for (const [depName, depResult] of dependencyResults) {
7355
+ if (forEachParents.includes(depName)) {
7356
+ const depForEachResult = depResult;
7357
+ if (Array.isArray(depForEachResult.output) && depForEachResult.output[itemIndex] !== void 0) {
7358
+ const modifiedResult = {
7359
+ issues: [],
7360
+ output: depForEachResult.output[itemIndex]
7361
+ };
7362
+ forEachDependencyResults.set(depName, modifiedResult);
7363
+ const rawResult = {
7364
+ issues: [],
7365
+ output: depForEachResult.output
7366
+ };
7367
+ forEachDependencyResults.set(`${depName}-raw`, rawResult);
7368
+ } else {
7369
+ forEachDependencyResults.set(depName, depResult);
7370
+ }
7354
7371
  } else {
7355
7372
  forEachDependencyResults.set(depName, depResult);
7356
7373
  }
7357
- } else {
7358
- forEachDependencyResults.set(depName, depResult);
7359
7374
  }
7360
- }
7361
- if (checkConfig.if) {
7362
- const conditionResults = new Map(results);
7363
- for (const [depName, depResult] of forEachDependencyResults) {
7364
- conditionResults.set(depName, depResult);
7375
+ if (checkConfig.if) {
7376
+ const conditionResults = new Map(results);
7377
+ for (const [depName, depResult] of forEachDependencyResults) {
7378
+ conditionResults.set(depName, depResult);
7379
+ }
7380
+ const shouldRun = await this.evaluateCheckCondition(
7381
+ checkName,
7382
+ checkConfig.if,
7383
+ prInfo,
7384
+ conditionResults,
7385
+ debug
7386
+ );
7387
+ if (!shouldRun) {
7388
+ if (debug) {
7389
+ log2(
7390
+ `\u{1F504} Debug: Skipping forEach item ${itemIndex + 1} for check "${checkName}" (if condition evaluated to false)`
7391
+ );
7392
+ }
7393
+ return {
7394
+ index: itemIndex,
7395
+ itemResult: { issues: [] },
7396
+ skipped: true
7397
+ };
7398
+ }
7365
7399
  }
7366
- const shouldRun = await this.evaluateCheckCondition(
7400
+ if (debug) {
7401
+ log2(
7402
+ `\u{1F504} Debug: Executing check "${checkName}" for item ${itemIndex + 1}/${forEachItems.length}`
7403
+ );
7404
+ }
7405
+ const iterationStart = this.recordIterationStart(checkName);
7406
+ const itemResult = await this.executeWithRouting(
7367
7407
  checkName,
7368
- checkConfig.if,
7408
+ checkConfig,
7409
+ provider,
7410
+ providerConfig,
7369
7411
  prInfo,
7370
- conditionResults,
7371
- debug
7412
+ forEachDependencyResults,
7413
+ sessionInfo,
7414
+ config,
7415
+ dependencyGraph,
7416
+ debug,
7417
+ results,
7418
+ /*foreachContext*/
7419
+ {
7420
+ index: itemIndex,
7421
+ total: forEachItems.length,
7422
+ parent: forEachParentName
7423
+ }
7372
7424
  );
7373
- if (!shouldRun) {
7425
+ const hadFatalError = (itemResult.issues || []).some((issue) => {
7426
+ const id = issue.ruleId || "";
7427
+ return id === "command/execution_error" || id.endsWith("/command/execution_error") || id === "command/transform_js_error" || id.endsWith("/command/transform_js_error") || id === "command/transform_error" || id.endsWith("/command/transform_error");
7428
+ });
7429
+ const iterationDuration = (Date.now() - iterationStart) / 1e3;
7430
+ this.recordIterationComplete(
7431
+ checkName,
7432
+ iterationStart,
7433
+ !hadFatalError,
7434
+ // Success if no fatal errors
7435
+ itemResult.issues || [],
7436
+ itemResult.output
7437
+ );
7438
+ logger.info(
7439
+ ` \u2714 ${itemIndex + 1}/${forEachItems.length} (${iterationDuration.toFixed(1)}s)`
7440
+ );
7441
+ return { index: itemIndex, itemResult };
7442
+ });
7443
+ const forEachConcurrency = Math.max(
7444
+ 1,
7445
+ Math.min(forEachItems.length, effectiveMaxParallelism)
7446
+ );
7447
+ if (debug && forEachConcurrency > 1) {
7448
+ log2(
7449
+ `\u{1F504} Debug: Limiting forEach concurrency for check "${checkName}" to ${forEachConcurrency}`
7450
+ );
7451
+ }
7452
+ const forEachResults = await this.executeWithLimitedParallelism(
7453
+ itemTasks,
7454
+ forEachConcurrency,
7455
+ false
7456
+ );
7457
+ for (const result of forEachResults) {
7458
+ if (result.status === "rejected") {
7459
+ const error = result.reason;
7460
+ const errorMessage = error instanceof Error ? error.message : String(error);
7461
+ allIssues.push({
7462
+ ruleId: `${checkName}/forEach/iteration_error`,
7463
+ severity: "error",
7464
+ category: "logic",
7465
+ message: `forEach iteration failed: ${errorMessage}`,
7466
+ file: "",
7467
+ line: 0
7468
+ });
7374
7469
  if (debug) {
7375
7470
  log2(
7376
- `\u{1F504} Debug: Skipping forEach item ${itemIndex + 1} for check "${checkName}" (if condition evaluated to false)`
7471
+ `\u{1F504} Debug: forEach iteration for check "${checkName}" failed: ${errorMessage}`
7377
7472
  );
7378
7473
  }
7379
- return {
7380
- index: itemIndex,
7381
- itemResult: { issues: [] },
7382
- skipped: true
7383
- };
7474
+ continue;
7384
7475
  }
7385
- }
7386
- if (debug) {
7387
- log2(
7388
- `\u{1F504} Debug: Executing check "${checkName}" for item ${itemIndex + 1}/${forEachItems.length}`
7389
- );
7390
- }
7391
- const iterationStart = this.recordIterationStart(checkName);
7392
- const itemResult = await this.executeWithRouting(
7393
- checkName,
7394
- checkConfig,
7395
- provider,
7396
- providerConfig,
7397
- prInfo,
7398
- forEachDependencyResults,
7399
- sessionInfo,
7400
- config,
7401
- dependencyGraph,
7402
- debug,
7403
- results,
7404
- /*foreachContext*/
7405
- {
7406
- index: itemIndex,
7407
- total: forEachItems.length,
7408
- parent: forEachParentName
7476
+ if (result.value.skipped) {
7477
+ continue;
7409
7478
  }
7410
- );
7411
- const hadFatalError = (itemResult.issues || []).some((issue) => {
7412
- const id = issue.ruleId || "";
7413
- return id === "command/execution_error" || id.endsWith("/command/execution_error") || id === "command/transform_js_error" || id.endsWith("/command/transform_js_error") || id === "command/transform_error" || id.endsWith("/command/transform_error");
7414
- });
7415
- const iterationDuration = (Date.now() - iterationStart) / 1e3;
7416
- this.recordIterationComplete(
7417
- checkName,
7418
- iterationStart,
7419
- !hadFatalError,
7420
- // Success if no fatal errors
7421
- itemResult.issues || [],
7422
- itemResult.output
7423
- );
7424
- logger.info(
7425
- ` \u2714 ${itemIndex + 1}/${forEachItems.length} (${iterationDuration.toFixed(1)}s)`
7426
- );
7427
- return { index: itemIndex, itemResult };
7428
- });
7429
- const forEachConcurrency = Math.max(
7430
- 1,
7431
- Math.min(forEachItems.length, effectiveMaxParallelism)
7432
- );
7433
- if (debug && forEachConcurrency > 1) {
7434
- log2(
7435
- `\u{1F504} Debug: Limiting forEach concurrency for check "${checkName}" to ${forEachConcurrency}`
7436
- );
7437
- }
7438
- const forEachResults = await this.executeWithLimitedParallelism(
7439
- itemTasks,
7440
- forEachConcurrency,
7441
- false
7442
- );
7443
- for (const result of forEachResults) {
7444
- if (result.status === "rejected") {
7445
- const error = result.reason;
7446
- const errorMessage = error instanceof Error ? error.message : String(error);
7447
- allIssues.push({
7448
- ruleId: `${checkName}/forEach/iteration_error`,
7449
- severity: "error",
7450
- category: "logic",
7451
- message: `forEach iteration failed: ${errorMessage}`,
7452
- file: "",
7453
- line: 0
7454
- });
7455
- if (debug) {
7456
- log2(
7457
- `\u{1F504} Debug: forEach iteration for check "${checkName}" failed: ${errorMessage}`
7458
- );
7479
+ const { itemResult } = result.value;
7480
+ if (itemResult.issues) {
7481
+ allIssues.push(...itemResult.issues);
7482
+ }
7483
+ const resultWithOutput = itemResult;
7484
+ if (resultWithOutput.output !== void 0) {
7485
+ allOutputs.push(resultWithOutput.output);
7486
+ }
7487
+ const itemContent = resultWithOutput.content;
7488
+ if (typeof itemContent === "string" && itemContent.trim()) {
7489
+ aggregatedContents.push(itemContent.trim());
7459
7490
  }
7460
- continue;
7461
- }
7462
- if (result.value.skipped) {
7463
- continue;
7464
- }
7465
- const { itemResult } = result.value;
7466
- if (itemResult.issues) {
7467
- allIssues.push(...itemResult.issues);
7468
7491
  }
7469
- const resultWithOutput = itemResult;
7470
- if (resultWithOutput.output !== void 0) {
7471
- allOutputs.push(resultWithOutput.output);
7492
+ const finalOutput = allOutputs.length > 0 ? allOutputs : void 0;
7493
+ finalResult = {
7494
+ issues: allIssues,
7495
+ ...finalOutput !== void 0 ? { output: finalOutput } : {}
7496
+ };
7497
+ if (allOutputs.length > 0) {
7498
+ finalResult.isForEach = true;
7499
+ finalResult.forEachItems = allOutputs;
7472
7500
  }
7473
- const itemContent = resultWithOutput.content;
7474
- if (typeof itemContent === "string" && itemContent.trim()) {
7475
- aggregatedContents.push(itemContent.trim());
7501
+ if (aggregatedContents.length > 0) {
7502
+ finalResult.content = aggregatedContents.join("\n");
7476
7503
  }
7504
+ log2(
7505
+ `\u{1F504} Debug: Completed forEach execution for check "${checkName}", total issues: ${allIssues.length}`
7506
+ );
7477
7507
  }
7478
- const finalOutput = allOutputs.length > 0 ? allOutputs : void 0;
7479
- finalResult = {
7480
- issues: allIssues,
7481
- ...finalOutput !== void 0 ? { output: finalOutput } : {}
7482
- };
7483
- if (allOutputs.length > 0) {
7484
- finalResult.isForEach = true;
7485
- finalResult.forEachItems = allOutputs;
7486
- }
7487
- if (aggregatedContents.length > 0) {
7488
- finalResult.content = aggregatedContents.join("\n");
7489
- }
7490
- log2(
7491
- `\u{1F504} Debug: Completed forEach execution for check "${checkName}", total issues: ${allIssues.length}`
7492
- );
7493
7508
  } else {
7494
7509
  if (checkConfig.if) {
7495
7510
  const shouldRun = await this.evaluateCheckCondition(