@diffci.com/diffci 0.3.24 → 0.3.25

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.
@@ -2,13 +2,13 @@ import { extname, posix } from "node:path";
2
2
  import { isGoDiscoveryIgnoredPath } from "./adapters/go.js";
3
3
  import { inVuePackage } from "./vue-scope.js";
4
4
  import type { ChangedFile, GitDelta } from "../git/types.js";
5
- import type { DependencyGraph, DependencyGraphNode, DependencyGraphResult, EntryPoint, RepositoryProfile } from "./types.js";
5
+ import type { DependencyGraph, DependencyGraphNode, DependencyGraphResult, EntryPoint, RepositoryProfile, UnresolvedDependency } from "./types.js";
6
6
  import type { ChangedImpact, EntryPointImpact, ImpactEvidence, ImpactEvidencePath, ImpactReason, ImpactResult, ImpactRiskSignal, TestImpact } from "./impact-types.js";
7
7
  import { refineConfidenceForDelta } from "./graph.js";
8
8
  import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT, type RepositoryLayout } from "./layout.js";
9
9
  import { DEFAULT_TEST_FILE_MATCHER, matchesGlob as matchesTestGlob, testDiscoveryErrors, testFileMatcherForProfile } from "./test-discovery.js";
10
10
  import { resolveTestFixtureOwners } from "./test-fixture-ownership.js";
11
- import { infrastructureRole, isImplicitlyLoadedFile, isWorkerConfig, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
11
+ import { directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
12
12
  import { workflowFeedsTests } from "./workflow-test-steps.js";
13
13
  import { modelTestScriptUniverse, type ScriptUniverse } from "./script-universe.js";
14
14
  import { compiledProjects, type CompiledProject } from "./compiled-projects.js";
@@ -70,6 +70,8 @@ function isDatabaseFile(filePath: string): boolean { const DATABASE_DIRS = new S
70
70
  */
71
71
  function classifyNextEntryPoint(filePath: string, layout: RepositoryLayout): EntryPoint["kind"] | undefined { if (!layout.isNextApp) return undefined; if (!isSourceFilePath(filePath)) return undefined; const base = posix.basename(filePath, extname(filePath)); const lower = base.toLowerCase(); if (lower === "page") return "next-page"; if (lower === "layout") return "next-layout"; if (lower === "route") return "next-route"; if (lower === "api" && filePath.includes("/api/")) return "next-api"; if (lower === "loading") return "next-loading"; if (lower === "error") return "next-error"; if (lower === "template") return "next-template"; if (lower === "not-found") return "next-error"; if (lower === "middleware") return "next-api"; return undefined; }
72
72
  function allChangePaths(file: ChangedFile): string[] { return file.oldPath ? [file.path, file.oldPath] : [file.path]; }
73
+ /** The module an extensionless import of `path` names: `a/x.ts` -> `a/x`, `a/x/index.ts` -> `a/x`. */
74
+ function moduleKey(path: string): string { const stem = path.replace(/\.[^./]+$/, ""); return posix.basename(stem) === "index" ? posix.dirname(stem) : stem; }
73
75
  function nodeByPath(graph: DependencyGraph, path: string): DependencyGraphNode | undefined { return graph.nodes.find((n) => n.path === path); }
74
76
  function hasNode(graph: DependencyGraph, path: string): boolean { return nodeByPath(graph, path) !== undefined; }
75
77
  function isEntryPoint(profile: RepositoryProfile, path: string): EntryPoint | undefined { return profile.entryPoints.find((e) => e.path === path); }
@@ -263,6 +265,8 @@ export class ImpactAnalyzer {
263
265
  private testPhases = new Set<string>();
264
266
  private workersOutsideSuite: boolean | undefined;
265
267
  private runtimeTestSelection = false;
268
+ private unresolved: readonly UnresolvedDependency[] = [];
269
+ private walkerTests: string[] | undefined;
266
270
 
267
271
  /** Dependents whose tests a change to `path` can affect. When the graph allows runtime selection
268
272
  * (DependencyGraphResult.runtimeTestSelection) an `import type` edge selects only type tests. */
@@ -293,7 +297,9 @@ export class ImpactAnalyzer {
293
297
  this.selectTestPhases = options.selectTestPhases === true;
294
298
  this.testPhases = new Set();
295
299
  this.workersOutsideSuite = undefined;
300
+ this.walkerTests = undefined;
296
301
  this.runtimeTestSelection = graphResult.runtimeTestSelection === true;
302
+ this.unresolved = graphResult.unresolved ?? [];
297
303
  this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
298
304
  this.compiledProjectCache = undefined;
299
305
  // One read per file per analysis, however many changed files ask who reads them.
@@ -558,7 +564,11 @@ export class ImpactAnalyzer {
558
564
  .filter((ref) => ref.resolution === "external-package" && packageRoot(ref.specifier) === name)
559
565
  .map((ref) => ref.importer))].sort();
560
566
  if (importers.length === 0) {
561
- fail(`${dependencyChange(name)} and no repository source imports it; full validation required`);
567
+ const blocker = this.resolveUnimportedPackage(name, changedFile, closureBodies, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
568
+ if (blocker) {
569
+ evidence.push(makeEvidence("DEPENDENCY", changedFile, `${name}: ${blocker}`));
570
+ fail(`${dependencyChange(name)} and no repository source imports it; full validation required`);
571
+ }
562
572
  continue;
563
573
  }
564
574
  const quoted = new RegExp(`["'\`]${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:/[^"'\`]*)?["'\`]`);
@@ -588,6 +598,67 @@ export class ImpactAnalyzer {
588
598
  }
589
599
  }
590
600
 
601
+ /**
602
+ * A changed dependency no repository code imports (2026-11-04). Usually a CLI the repository runs by
603
+ * its executable's name: bumping `@diffci.com/diffci`, run as `diffci`, made all 601 DentalPresence
604
+ * tests run. Such a package reaches the suite only by being run or loaded, so it narrows when
605
+ * package-lock.json records its executables and every file naming the package or one of them
606
+ * resolves: a test is selected, graph code selects its dependent tests, and any other code or
607
+ * directing file must itself resolve by reference. Returns why it cannot narrow: the executables are
608
+ * unknown, the name suggests tooling loads it by convention (types, plugins, presets, test runners),
609
+ * or the test script, a file tooling loads, or a test-feeding workflow step names it.
610
+ */
611
+ private resolveUnimportedPackage(
612
+ name: string,
613
+ changedFile: string,
614
+ closureBodies: readonly string[],
615
+ graph: DependencyGraph,
616
+ profile: RepositoryProfile,
617
+ affectedSources: Map<string, ImpactEvidence[]>,
618
+ affectedEntryPoints: Map<string, EntryPointImpact>,
619
+ affectedTests: Map<string, TestImpact>,
620
+ affectedScripts: Map<string, ImpactEvidence[]>,
621
+ evidence: ImpactEvidence[],
622
+ ): string | undefined {
623
+ if (/(?:^@types\/|types|plugin|preset|config|loader|register|polyfill|setup|eslint|prettier|stylelint|babel|postcss|tailwind|jest|vitest|mocha|ava|playwright|cypress|typescript|ts-node|^tsx$|swc|esbuild|vite|webpack|rollup)/i.test(name)) {
624
+ return "tooling may load it by naming convention";
625
+ }
626
+ if (!this.repositoryFiles?.has("package-lock.json")) return "its executables are unknown without package-lock.json";
627
+ let bin: unknown;
628
+ try {
629
+ const lock = JSON.parse(this.readRepositoryFile!("package-lock.json") ?? "") as { packages?: Record<string, { bin?: unknown }> };
630
+ bin = lock.packages?.[`node_modules/${name}`]?.bin;
631
+ } catch { return "package-lock.json could not be parsed"; }
632
+ const bins = typeof bin === "string" ? [name.split("/").pop()!] : bin && typeof bin === "object" ? Object.keys(bin) : [];
633
+ if (bins.length === 0) return "it has no executable, so only tooling can load it";
634
+ const escape = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
635
+ const named = new RegExp(`(?:^|[\\s"'\`=/(])(?:${[name, ...bins].map(escape).join("|")})(?=$|[\\s"'\`/@),;:])`, "m");
636
+ if (closureBodies.some((body) => named.test(body))) return "the test script runs it";
637
+ const scripts = profile.packageJson.scripts;
638
+ for (const path of this.sortedRepositoryFiles) {
639
+ if (path === "package.json" || isLockfile(path) || this.layout.isDocumentationPath(path)) continue;
640
+ const content = this.readRepositoryFile!(path);
641
+ if (content === undefined || !named.test(content)) continue;
642
+ if (isImplicitlyLoadedFile(path) || loadsWithoutNaming(path) || posix.basename(path) === "package.json") return `${path} names it and tooling loads that file`;
643
+ if (path.startsWith(".github/")) {
644
+ if (path.startsWith(".github/actions/") || (/^\.github\/workflows\//.test(path) && workflowFeedsTests(content, named, scripts))) return `${path} runs it before tests`;
645
+ continue;
646
+ }
647
+ if (isSourceFilePath(path) && this.isTestFile(path)) {
648
+ evidence.push(makeEvidence("DEPENDENCY", changedFile, `${path} names ${name}`, path));
649
+ this.addAffectedTest(changedFile, path, graph, affectedTests, "DEPENDENCY", evidence);
650
+ } else if (isSourceFilePath(path) && hasNode(graph, path)) {
651
+ evidence.push(makeEvidence("DEPENDENCY", changedFile, `${path} names ${name}`, path));
652
+ this.processSourceChange(path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
653
+ } else if (isSourceFilePath(path) || DIRECTING_EXTENSIONS.test(path)) {
654
+ if (!this.resolveByReference(path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { implicitReadersUnresolvable: true })) {
655
+ return `${path} names it and its own readers could not be resolved`;
656
+ }
657
+ }
658
+ }
659
+ return undefined;
660
+ }
661
+
591
662
  private processChangedPath(
592
663
  changedPath: string,
593
664
  changedImpact: ChangedImpact,
@@ -608,6 +679,17 @@ export class ImpactAnalyzer {
608
679
  this.processAssetChange(changedPath, graph, profile, affectedAssets, affectedEntryPoints, affectedTests, affectedSources, evidence);
609
680
  return;
610
681
  }
682
+ // Non-code files are resolved by reference below, directories included; code is not, so a test that
683
+ // lists the directory a code file is in is added here (file-references.ts, directoryWalkers).
684
+ if (isSourceFilePath(changedPath) && this.readRepositoryFile) {
685
+ const read = this.readRepositoryFile;
686
+ this.walkerTests ??= this.sortedRepositoryFiles.filter((path) => this.isTestFile(path) && listsDirectories(read(path)));
687
+ for (const test of directoryWalkers(changedPath, this.walkerTests, this.readRepositoryFile)) {
688
+ if (test === changedPath) continue;
689
+ evidence.push(makeEvidence("FILE_REFERENCE", changedPath, `${test} lists a directory containing ${changedPath}`, test));
690
+ this.addAffectedTest(changedPath, test, graph, affectedTests, "FILE_REFERENCE", evidence);
691
+ }
692
+ }
611
693
  const category = changedImpact.category;
612
694
  if (changedPath === this.dependencyLockfile) {
613
695
  // Dependency selection does not cover a test that reads the lockfile's bytes. Unlike general
@@ -656,7 +738,9 @@ export class ImpactAnalyzer {
656
738
  return;
657
739
  }
658
740
  if (category === "docs") return;
659
- if (isAssetFilePath(changedPath) && !hasNode(graph, changedPath) && changedImpact.file.changeType !== "deleted" && !isDocumentationFile(changedPath, this.layout) && !isLockfile(changedPath)) {
741
+ // A rename's old path is gone at HEAD like a deleted file (`X.module.css` -> `X.css`).
742
+ const removed = changedImpact.file.changeType === "deleted" || (changedPath === changedImpact.file.oldPath && changedImpact.file.changeType === "renamed");
743
+ if (isAssetFilePath(changedPath) && !hasNode(graph, changedPath) && !removed && !isDocumentationFile(changedPath, this.layout) && !isLockfile(changedPath)) {
660
744
  // An asset no module imports can still be read from disk by a test. It used to select nothing
661
745
  // and require nothing, which is a silent skip; it now needs reader evidence like any other
662
746
  // non-code file (2026-10-21).
@@ -668,7 +752,8 @@ export class ImpactAnalyzer {
668
752
  return;
669
753
  }
670
754
  if (isAssetFilePath(changedPath)) {
671
- if (changedImpact.file.changeType === "deleted" && !hasNode(graph, changedPath)) {
755
+ if (removed && !hasNode(graph, changedPath)) {
756
+ if (this.resolveRemovedFile(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) return;
672
757
  const message = `Deleted source/asset ${changedPath} not present in HEAD dependency graph; legacy dependents cannot be determined`;
673
758
  evidence.push(makeEvidence("DELETED_FILE_UNKNOWABLE_GRAPH", changedPath, message));
674
759
  riskSignals.push({ level: "critical", reason: "DELETED_FILE_UNKNOWABLE_GRAPH", message, paths: [changedPath] });
@@ -708,6 +793,7 @@ export class ImpactAnalyzer {
708
793
  return;
709
794
  }
710
795
  if (changedImpact.file.changeType === "deleted" && !hasNode(graph, changedPath)) {
796
+ if (this.resolveRemovedFile(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) return;
711
797
  const message = `Deleted source/asset ${changedPath} not present in HEAD dependency graph; legacy dependents cannot be determined`;
712
798
  evidence.push(makeEvidence("DELETED_FILE_UNKNOWABLE_GRAPH", changedPath, message));
713
799
  riskSignals.push({ level: "critical", reason: "DELETED_FILE_UNKNOWABLE_GRAPH", message, paths: [changedPath] });
@@ -717,6 +803,45 @@ export class ImpactAnalyzer {
717
803
  this.processSourceChange(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
718
804
  }
719
805
 
806
+ /**
807
+ * A file gone at HEAD that the HEAD graph has no node for (2026-11-04). Its old importers cannot be
808
+ * listed, but each one is either changed in this delta (its import was edited or removed, so it is
809
+ * analysed as a changed file), still imports the missing path (an unresolved import), or now resolves
810
+ * the same specifier to a sibling (`./x` from a deleted `x.ts` to a surviving `x/index.ts`). The last
811
+ * two are found here; anything else observes the absence only by naming the file, which the reference
812
+ * resolver checks without its directories. A directory listing is not modelled, as for an added asset
813
+ * the graph does import, nor is a tsconfig `paths` fallback that now resolves to another directory. Previously every such file fell back: the LobeHub catch replay's StyleX
814
+ * migration renames `X.module.css` to `X.css` and 16 of 47 verify commits ran the full suite for it.
815
+ */
816
+ private resolveRemovedFile(
817
+ removedPath: string,
818
+ graph: DependencyGraph,
819
+ profile: RepositoryProfile,
820
+ affectedSources: Map<string, ImpactEvidence[]>,
821
+ affectedEntryPoints: Map<string, EntryPointImpact>,
822
+ affectedTests: Map<string, TestImpact>,
823
+ affectedScripts: Map<string, ImpactEvidence[]>,
824
+ evidence: ImpactEvidence[],
825
+ ): boolean {
826
+ if (this.repositoryFiles?.has(removedPath)) return false;
827
+ const key = moduleKey(removedPath);
828
+ const names = new Set([posix.basename(removedPath), posix.basename(removedPath.replace(/\.[^./]+$/, "")), posix.basename(key)]);
829
+ // Conservative: any unresolved import whose last segment could name the file blocks, wherever it is.
830
+ const importer = this.unresolved.find((ref) => !ref.computed && names.has(posix.basename(ref.specifier.split(/[?#]/)[0]!)));
831
+ if (importer) {
832
+ evidence.push(makeEvidence("UNKNOWN_FILE", removedPath, `${importer.importer} imports ${importer.specifier}, which may have resolved to the removed ${removedPath}`));
833
+ return false;
834
+ }
835
+ if (!this.resolveByReference(removedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { implicitReadersUnresolvable: true, removed: true })) return false;
836
+ for (const node of graph.nodes) {
837
+ if (node.path === removedPath || moduleKey(node.path) !== key) continue;
838
+ evidence.push(makeEvidence("DELETED_FILE_LEGACY_DEPENDENTS", removedPath, `${node.path} may now resolve imports of the removed ${removedPath}`, node.path));
839
+ this.processSourceChange(node.path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
840
+ }
841
+ evidence.push(makeEvidence("DELETED_FILE_LEGACY_DEPENDENTS", removedPath, `No HEAD import can still reach the removed ${removedPath}; its former importers are changed files`));
842
+ return true;
843
+ }
844
+
720
845
  /** Projects some test compiles (src/repo/compiled-projects.ts), computed once per analysis and only
721
846
  * when file contents are available. */
722
847
  private compiledProjectsFor(graph: DependencyGraph): CompiledProject[] {
@@ -763,7 +888,7 @@ export class ImpactAnalyzer {
763
888
  affectedTests: Map<string, TestImpact>,
764
889
  affectedScripts: Map<string, ImpactEvidence[]>,
765
890
  evidence: ImpactEvidence[],
766
- { implicitReadersUnresolvable = false, allowNoReaders = false }: { implicitReadersUnresolvable?: boolean; allowNoReaders?: boolean } = {},
891
+ { implicitReadersUnresolvable = false, allowNoReaders = false, removed = false }: { implicitReadersUnresolvable?: boolean; allowNoReaders?: boolean; removed?: boolean } = {},
767
892
  ): boolean {
768
893
  if (!this.repositoryFiles || !this.readRepositoryFile) return false;
769
894
  if (isImplicitlyLoadedFile(changedPath) && !(isWorkerConfig(changedPath) && this.workerConfigsOutsideSuite())) return false;
@@ -780,6 +905,7 @@ export class ImpactAnalyzer {
780
905
  contentCleared: this.contentCleared,
781
906
  implicitReadersUnresolvable,
782
907
  allowNoReaders,
908
+ removed,
783
909
  testPhases: this.selectTestPhases,
784
910
  workerConfigsOutsideSuite: this.workerConfigsOutsideSuite(),
785
911
  });
@@ -75,16 +75,18 @@ function commandRunsTests(text: string, scripts: Readonly<Record<string, string>
75
75
  * authoritative, not part of the suite DiffCI selects from. One dogfood repository's deploy workflow runs two such
76
76
  * checks, and counting them blocked every site HTML change in its replayed history.
77
77
  *
78
- * So the answer is true when a job step matching `names` is, or precedes, a step that runs the test
78
+ * So the answer is true when a job step `names` matches is, or precedes, a step that runs the test
79
79
  * command or a test runner, or an action not known to be test-free; when a reusable-workflow job or
80
80
  * job-level configuration names it in a job that runs tests; and whenever the YAML cannot be read.
81
81
  */
82
- export function workflowFeedsTests(workflowText: string, names: RegExp, scripts: Readonly<Record<string, string>> = {}): boolean {
82
+ export function workflowFeedsTests(workflowText: string, names: RegExp | ((text: string) => boolean), scripts: Readonly<Record<string, string>> = {}): boolean {
83
83
  let document: unknown;
84
84
  try { document = parse(workflowText); } catch { return true; }
85
85
  if (!document || typeof document !== "object") return true;
86
+ // A word-level matcher reads steps as JSON text, whose escapes (`\n`, `\"`) would join into words.
87
+ const named = typeof names === "function" ? (text: string) => names(text.replace(/\\[nrt]/g, " ").replace(/\\"/g, '"')) : (text: string) => names.test(text);
86
88
  const jobs = (document as { jobs?: unknown }).jobs;
87
- if (!jobs || typeof jobs !== "object") return names.test(workflowText);
89
+ if (!jobs || typeof jobs !== "object") return named(workflowText);
88
90
  const testStep = (step: unknown): boolean => {
89
91
  if (!step || typeof step !== "object") return true;
90
92
  const { uses, run } = step as { uses?: unknown; run?: unknown };
@@ -99,11 +101,11 @@ export function workflowFeedsTests(workflowText: string, names: RegExp, scripts:
99
101
  if (!job || typeof job !== "object") return true;
100
102
  if (jobDisabled(job)) continue;
101
103
  const { steps, uses, ...configuration } = job as { steps?: unknown; uses?: unknown };
102
- if (uses !== undefined) { if (names.test(JSON.stringify(job))) return true; continue; }
104
+ if (uses !== undefined) { if (named(JSON.stringify(job))) return true; continue; }
103
105
  if (!Array.isArray(steps)) return true;
104
- const firstNaming = steps.findIndex((step) => names.test(JSON.stringify(step)));
106
+ const firstNaming = steps.findIndex((step) => named(JSON.stringify(step)));
105
107
  const jobRunsTests = steps.some(testStep);
106
- if (jobRunsTests && names.test(JSON.stringify(configuration))) return true;
108
+ if (jobRunsTests && named(JSON.stringify(configuration))) return true;
107
109
  if (firstNaming !== -1 && steps.slice(firstNaming).some(testStep)) return true;
108
110
  }
109
111
  return false;
@@ -112,6 +112,15 @@ function cloneSort(comparator) {
112
112
  return templateFn(comparator);
113
113
  }
114
114
 
115
+ let isEvalAllowed = (function () {
116
+ try {
117
+ new Function('return 0')();
118
+ return true;
119
+ } catch {
120
+ return false;
121
+ }
122
+ })();
123
+
115
124
  /**
116
125
  * Sort the given array in-place with the given comparator function.
117
126
  *
@@ -123,7 +132,7 @@ function cloneSort(comparator) {
123
132
 
124
133
  let sortCache = new WeakMap();
125
134
  exports.quickSort = function (ary, comparator, start = 0) {
126
- let doQuickSort = sortCache.get(comparator);
135
+ let doQuickSort = isEvalAllowed ? sortCache.get(comparator) : SortTemplate(comparator);
127
136
  if (doQuickSort === void 0) {
128
137
  doQuickSort = cloneSort(comparator);
129
138
  sortCache.set(comparator, doQuickSort);
@@ -11,6 +11,14 @@ var ArraySet = require('./array-set').ArraySet;
11
11
  var base64VLQ = require('./base64-vlq');
12
12
  var quickSort = require('./quick-sort').quickSort;
13
13
 
14
+ // Upper bound for a section's `offset.line` in an indexed source map. A flat
15
+ // map spends one ';' per generated line, so a tiny indexed map with a huge
16
+ // offset.line turns into a huge amount of work and memory once its mappings
17
+ // are copied into a SourceMapGenerator (CVE-2026-93749). Ten million lines is
18
+ // far beyond any real generated file. Columns are VLQ-encoded as deltas and
19
+ // don't amplify, so they only need to be valid integers.
20
+ var MAX_SECTION_OFFSET_LINE = 1e7;
21
+
14
22
  function SourceMapConsumer(aSourceMap, aSourceMapURL) {
15
23
  var sourceMap = aSourceMap;
16
24
  if (typeof aSourceMap === 'string') {
@@ -935,6 +943,7 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
935
943
  line: -1,
936
944
  column: 0
937
945
  };
946
+ var maxOffsetLine = 0;
938
947
  this._sections = sections.map(function (s) {
939
948
  if (s.url) {
940
949
  // The url field will require support for asynchronicity.
@@ -945,12 +954,32 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
945
954
  var offsetLine = util.getArg(offset, 'line');
946
955
  var offsetColumn = util.getArg(offset, 'column');
947
956
 
957
+ if (!isValidOffset(offsetLine) || !isValidOffset(offsetColumn)) {
958
+ throw new Error('Section offset line and column must be non-negative integers.');
959
+ }
960
+ if (offsetLine > MAX_SECTION_OFFSET_LINE) {
961
+ throw new Error('Section offset line must not exceed ' + MAX_SECTION_OFFSET_LINE + '.');
962
+ }
963
+
948
964
  if (offsetLine < lastOffset.line ||
949
965
  (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
950
966
  throw new Error('Section offsets must be ordered and non-overlapping.');
951
967
  }
952
968
  lastOffset = offset;
953
969
 
970
+ var consumer = new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL);
971
+
972
+ // Offsets of a nested indexed map add up with this one, so apply the
973
+ // bound to the total.
974
+ var totalOffsetLine = offsetLine + (consumer._maxOffsetLine || 0);
975
+ if (totalOffsetLine > MAX_SECTION_OFFSET_LINE) {
976
+ throw new Error('Section offset line must not exceed ' + MAX_SECTION_OFFSET_LINE +
977
+ ', including offsets of nested sections.');
978
+ }
979
+ if (totalOffsetLine > maxOffsetLine) {
980
+ maxOffsetLine = totalOffsetLine;
981
+ }
982
+
954
983
  return {
955
984
  generatedOffset: {
956
985
  // The offset fields are 0-based, but we use 1-based indices when
@@ -958,9 +987,24 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
958
987
  generatedLine: offsetLine + 1,
959
988
  generatedColumn: offsetColumn + 1
960
989
  },
961
- consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
990
+ consumer: consumer
962
991
  }
963
992
  });
993
+
994
+ // The largest offset.line of any section, including nested sections.
995
+ this._maxOffsetLine = maxOffsetLine;
996
+ }
997
+
998
+ /**
999
+ * Section offsets come from untrusted input and are used as line/column
1000
+ * numbers, so only accept non-negative safe integers (rejects NaN, Infinity,
1001
+ * strings, fractions, etc).
1002
+ */
1003
+ function isValidOffset(aValue) {
1004
+ return typeof aValue === 'number' &&
1005
+ aValue >= 0 &&
1006
+ aValue <= 9007199254740991 && // Number.MAX_SAFE_INTEGER
1007
+ Math.floor(aValue) === aValue;
964
1008
  }
965
1009
 
966
1010
  IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
@@ -978,8 +1022,12 @@ Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
978
1022
  get: function () {
979
1023
  var sources = [];
980
1024
  for (var i = 0; i < this._sections.length; i++) {
981
- for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
982
- sources.push(this._sections[i].consumer.sources[j]);
1025
+ // Read the getter once per section: for a nested indexed map it is
1026
+ // itself this getter, and re-reading it per item is exponential in the
1027
+ // nesting depth (CVE-2026-93749).
1028
+ var sectionSources = this._sections[i].consumer.sources;
1029
+ for (var j = 0; j < sectionSources.length; j++) {
1030
+ sources.push(sectionSources[j]);
983
1031
  }
984
1032
  }
985
1033
  return sources;
@@ -348,10 +348,12 @@ SourceMapGenerator.prototype._serializeMappings =
348
348
 
349
349
  if (mapping.generatedLine !== previousGeneratedLine) {
350
350
  previousGeneratedColumn = 0;
351
- while (mapping.generatedLine !== previousGeneratedLine) {
352
- next += ';';
353
- previousGeneratedLine++;
354
- }
351
+ // One ';' per skipped line. Build large gaps with a single flat
352
+ // string: appending ';' one by one creates a rope node per line, which
353
+ // can exhaust the heap for a big gap (CVE-2026-93749).
354
+ var lineDelta = mapping.generatedLine - previousGeneratedLine;
355
+ next += lineDelta === 1 ? ';' : ';'.repeat(lineDelta);
356
+ previousGeneratedLine = mapping.generatedLine;
355
357
  }
356
358
  else {
357
359
  if (i > 0) {
@@ -113,6 +113,13 @@ SourceNode.fromStringWithSourceMap =
113
113
  // to the SourceNode without any mapping.
114
114
  // Each line is added as separate string.
115
115
  while (lastGeneratedLine < mapping.generatedLine) {
116
+ if (remainingLinesIndex >= remainingLines.length) {
117
+ // The generated code is exhausted. Skip the rest instead of adding
118
+ // empty lines one by one: a mapping may point far past the end of
119
+ // the code (e.g. an indexed map section with a huge offset.line).
120
+ lastGeneratedLine = mapping.generatedLine;
121
+ break;
122
+ }
116
123
  node.add(shiftNextLine());
117
124
  lastGeneratedLine++;
118
125
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "source-map-js",
3
3
  "description": "Generates and consumes source maps",
4
- "version": "1.2.1",
4
+ "version": "1.2.2",
5
5
  "homepage": "https://github.com/7rulnik/source-map-js",
6
6
  "author": "Valentin 7rulnik Semirulnik <v7rulnik@gmail.com>",
7
7
  "contributors": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffci.com/diffci",
3
- "version": "0.3.24",
3
+ "version": "0.3.25",
4
4
  "description": "Fail-closed, change-aware verification for AI coding agents with conservative affected-test selection",
5
5
  "keywords": [
6
6
  "ci",
@@ -66,7 +66,7 @@
66
66
  "test": "node scripts/run-tests.mjs"
67
67
  },
68
68
  "dependencies": {
69
- "@diffci.com/core": "git+https://github.com/DiffCI/core.git#5ffdd32b58c7eed44c3bc14fd6dbfc0e849bcf91",
69
+ "@diffci.com/core": "git+https://github.com/DiffCI/core.git#7fe80905e10a59dca840a1551269f471eaf2973e",
70
70
  "yaml": "^2.9.0"
71
71
  },
72
72
  "devDependencies": {