@komatikai/trailhead 4.5.1 → 4.5.2

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
@@ -5585,6 +5585,10 @@ const RemediationConfig = objectType({
5585
5585
  enabled: booleanType().default(true),
5586
5586
  max_loop_rounds: numberType().int().min(0).default(3),
5587
5587
  });
5588
+ const RiskPathProfileConfig = objectType({
5589
+ /** Extra globs excluded from sensitive_files + test_coverage (not file_count/churn). */
5590
+ non_source_globs: arrayType(stringType()).default([]),
5591
+ });
5588
5592
  const OverrideConfig = objectType({
5589
5593
  enabled: booleanType().default(true),
5590
5594
  max_per_week: numberType().int().min(1).default(5),
@@ -5655,6 +5659,7 @@ const SubmissionConfig = objectType({
5655
5659
  const RepoConfig = objectType({
5656
5660
  schema_version: numberType().int().positive().default(1),
5657
5661
  gate: GateConfig.default({}),
5662
+ risk: RiskPathProfileConfig.optional(),
5658
5663
  remediation: RemediationConfig.optional(),
5659
5664
  override: OverrideConfig.optional(),
5660
5665
  tuning: TuningConfig.optional(),
@@ -11390,9 +11395,41 @@ function isTestFile(filename) {
11390
11395
  function isNonSourceFile(filename) {
11391
11396
  return NON_SOURCE_PATTERN.test(filename);
11392
11397
  }
11393
- function isSensitiveFile(filename) {
11398
+ function isWorkflowFile(filename) {
11399
+ return /(?:^|\/)\.github\/workflows\//i.test(filename);
11400
+ }
11401
+ /** Non-source for risk-factor purposes (markdown, config, consumer-declared globs). */
11402
+ function isContentNonSource(filename, config) {
11403
+ if (/(?:^|\/)migrations\//i.test(filename))
11404
+ return false;
11405
+ if (isNonSourceFile(filename) && !isWorkflowFile(filename))
11406
+ return true;
11407
+ const extra = config?.non_source_globs ?? [];
11408
+ return extra.length > 0 && matchesGlobs(filename, extra);
11409
+ }
11410
+ function isTestableSourceFile(filename, config) {
11411
+ if (isTestFile(filename))
11412
+ return false;
11413
+ if (/(?:^|\/)migrations\//i.test(filename))
11414
+ return false;
11415
+ return !isContentNonSource(filename, config);
11416
+ }
11417
+ function isSensitiveFile(filename, config) {
11418
+ if (isContentNonSource(filename, config) && !isWorkflowFile(filename))
11419
+ return false;
11394
11420
  return SENSITIVE_PATTERNS.some((p) => p.test(filename));
11395
11421
  }
11422
+ function riskConfigFromRepo(repo) {
11423
+ if (!repo)
11424
+ return null;
11425
+ return {
11426
+ sensitivity: repo.sensitivity,
11427
+ weights: repo.weights,
11428
+ ignore: repo.ignore,
11429
+ profiles: repo.profiles,
11430
+ non_source_globs: repo.risk?.non_source_globs,
11431
+ };
11432
+ }
11396
11433
  function sensitivityWeight(filename, config) {
11397
11434
  if (config) {
11398
11435
  if (config.ignore?.length && matchesGlobs(filename, config.ignore))
@@ -11468,10 +11505,10 @@ function computeRiskScore(files, config) {
11468
11505
  },
11469
11506
  });
11470
11507
  const testFileCount = effectiveFiles.filter((f) => isTestFile(f.filename)).length;
11471
- const nonSourceCount = effectiveFiles.filter((f) => !isTestFile(f.filename) && isNonSourceFile(f.filename)).length;
11472
- const sourceFileCount = effectiveFiles.length - testFileCount - nonSourceCount;
11473
- if (sourceFileCount > 0) {
11474
- const testRatio = testFileCount / sourceFileCount;
11508
+ const testableSourceFiles = effectiveFiles.filter((f) => isTestableSourceFile(f.filename, config));
11509
+ const nonSourceCount = effectiveFiles.filter((f) => !isTestFile(f.filename) && isContentNonSource(f.filename, config)).length;
11510
+ if (testableSourceFiles.length > 0) {
11511
+ const testRatio = testFileCount / testableSourceFiles.length;
11475
11512
  const testCoverageScore = testFileCount === 0
11476
11513
  ? 100
11477
11514
  : Math.round(Math.max(0, 100 - testRatio * 100 - Math.min(testFileCount, 5) * 10));
@@ -11480,9 +11517,10 @@ function computeRiskScore(files, config) {
11480
11517
  score: testCoverageScore,
11481
11518
  detail: {
11482
11519
  testFiles: testFileCount,
11483
- sourceFiles: sourceFileCount,
11520
+ sourceFiles: testableSourceFiles.length,
11484
11521
  nonSourceFiles: nonSourceCount,
11485
11522
  testRatio: Math.round(testRatio * 100) / 100,
11523
+ skipped: false,
11486
11524
  },
11487
11525
  });
11488
11526
  }
@@ -11490,7 +11528,7 @@ function computeRiskScore(files, config) {
11490
11528
  const sensitiveByConfig = highSensPatterns.length > 0
11491
11529
  ? effectiveFiles.filter((f) => matchesGlobs(f.filename, highSensPatterns))
11492
11530
  : [];
11493
- const sensitiveByDefault = effectiveFiles.filter((f) => isSensitiveFile(f.filename));
11531
+ const sensitiveByDefault = effectiveFiles.filter((f) => isSensitiveFile(f.filename, config));
11494
11532
  const sensitiveFilenames = new Set([
11495
11533
  ...sensitiveByConfig.map((f) => f.filename),
11496
11534
  ...sensitiveByDefault.map((f) => f.filename),