@diffci.com/diffci 0.3.53 → 0.3.55

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.
Files changed (130) hide show
  1. package/dist-client/src/client/agent-selection.d.ts +81 -1
  2. package/dist-client/src/client/agent-selection.js +107 -4
  3. package/dist-client/src/client/agent-setup.js +1 -1
  4. package/dist-client/src/client/cli.js +140 -18
  5. package/dist-client/src/client/command-batches.js +3 -2
  6. package/dist-client/src/client/context.js +32 -2
  7. package/dist-client/src/client/coverage-map.js +6 -1
  8. package/dist-client/src/client/full-command.js +19 -14
  9. package/dist-client/src/client/hook.d.ts +17 -0
  10. package/dist-client/src/client/hook.js +53 -1
  11. package/dist-client/src/client/install.d.ts +6 -0
  12. package/dist-client/src/client/install.js +30 -1
  13. package/dist-client/src/client/isolated-worktree.d.ts +31 -0
  14. package/dist-client/src/client/isolated-worktree.js +130 -0
  15. package/dist-client/src/client/mcp.js +23 -4
  16. package/dist-client/src/client/observe.d.ts +2 -0
  17. package/dist-client/src/client/observe.js +7 -2
  18. package/dist-client/src/client/report.d.ts +1 -1
  19. package/dist-client/src/client/shared-graph-cache.js +4 -2
  20. package/dist-client/src/client/telemetry.js +2 -1
  21. package/dist-client/src/client/usage-signal.d.ts +1 -1
  22. package/dist-client/src/client/verify-savings.d.ts +6 -0
  23. package/dist-client/src/client/verify-savings.js +15 -3
  24. package/dist-client/src/client/verify.d.ts +47 -3
  25. package/dist-client/src/client/verify.js +244 -22
  26. package/dist-client/src/client/working-tree.d.ts +22 -0
  27. package/dist-client/src/client/working-tree.js +45 -6
  28. package/node_modules/@diffci.com/core/README.md +17 -10
  29. package/node_modules/@diffci.com/core/dist/ci-inference/expression.d.ts +5 -0
  30. package/node_modules/@diffci.com/core/dist/ci-inference/expression.js +38 -5
  31. package/node_modules/@diffci.com/core/dist/ci-inference/expression.js.map +1 -1
  32. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +26 -6
  33. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
  34. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.d.ts +2 -1
  35. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +7 -2
  36. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
  37. package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js +15 -8
  38. package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js.map +1 -1
  39. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +6 -2
  40. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
  41. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +19 -4
  42. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
  43. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +13 -1
  44. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -1
  45. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +5 -0
  46. package/node_modules/@diffci.com/core/dist/git/git-diff.js +22 -20
  47. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  48. package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +22 -1
  49. package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
  50. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +6 -0
  51. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +14 -2
  52. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -1
  53. package/node_modules/@diffci.com/core/dist/planner/planner.js +65 -14
  54. package/node_modules/@diffci.com/core/dist/planner/planner.js.map +1 -1
  55. package/node_modules/@diffci.com/core/dist/planner/rust-command.js +43 -1
  56. package/node_modules/@diffci.com/core/dist/planner/rust-command.js.map +1 -1
  57. package/node_modules/@diffci.com/core/dist/planner/script-reads.js +5 -2
  58. package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
  59. package/node_modules/@diffci.com/core/dist/planner/test-command.js +17 -2
  60. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  61. package/node_modules/@diffci.com/core/dist/planner/type-program.js +27 -1
  62. package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
  63. package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +5 -1
  64. package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
  65. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +21 -2
  66. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
  67. package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +9 -1
  68. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +158 -14
  69. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
  70. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +1 -0
  71. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +180 -15
  72. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
  73. package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +7 -0
  74. package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
  75. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +16 -0
  76. package/node_modules/@diffci.com/core/dist/repo/file-references.js +76 -5
  77. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  78. package/node_modules/@diffci.com/core/dist/repo/graph.js +100 -29
  79. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  80. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
  81. package/node_modules/@diffci.com/core/dist/repo/impact.js +55 -8
  82. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  83. package/node_modules/@diffci.com/core/dist/repo/layout.js +4 -1
  84. package/node_modules/@diffci.com/core/dist/repo/layout.js.map +1 -1
  85. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +10 -1
  86. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
  87. package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
  88. package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
  89. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +5 -1
  90. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
  91. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +3 -0
  92. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +3 -3
  93. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
  94. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +65 -13
  95. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
  96. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +47 -2
  97. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
  98. package/node_modules/@diffci.com/core/package.json +1 -0
  99. package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +38 -5
  100. package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +21 -6
  101. package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +7 -2
  102. package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +15 -8
  103. package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +6 -2
  104. package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +18 -4
  105. package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +8 -1
  106. package/node_modules/@diffci.com/core/src/git/git-diff.ts +20 -21
  107. package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +22 -1
  108. package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +13 -2
  109. package/node_modules/@diffci.com/core/src/planner/planner.ts +42 -14
  110. package/node_modules/@diffci.com/core/src/planner/rust-command.ts +37 -1
  111. package/node_modules/@diffci.com/core/src/planner/script-reads.ts +5 -1
  112. package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -2
  113. package/node_modules/@diffci.com/core/src/planner/type-program.ts +25 -1
  114. package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +5 -1
  115. package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +20 -2
  116. package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +133 -14
  117. package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +136 -16
  118. package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +7 -1
  119. package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
  120. package/node_modules/@diffci.com/core/src/repo/graph.ts +81 -20
  121. package/node_modules/@diffci.com/core/src/repo/impact.ts +56 -7
  122. package/node_modules/@diffci.com/core/src/repo/layout.ts +5 -1
  123. package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +11 -1
  124. package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
  125. package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +4 -1
  126. package/node_modules/@diffci.com/core/src/repo/types.ts +3 -1
  127. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +3 -3
  128. package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +43 -13
  129. package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +44 -2
  130. package/package.json +2 -2
@@ -81,7 +81,27 @@ export function resolveExpression(expression: string, context: ExpressionContext
81
81
  return { expression: trimmed, kind: value === "" ? "DEFINED_EMPTY" : "DEFINED", value };
82
82
  }
83
83
 
84
- const EXPRESSION = /\$\{\{([^}]*)\}\}/g;
84
+ /**
85
+ * Replaces each `${{ body }}` whose body has no `}`, as `/\$\{\{([^}]*)\}\}/g` would, in linear time: the
86
+ * regex rescans to the next `}` from every `${{`, which is quadratic on a line of repeated `${{` (CodeQL alert 12).
87
+ */
88
+ export function replaceExpressions(line: string, replace: (body: string) => string): string {
89
+ let out = "";
90
+ let from = 0;
91
+ for (let start = line.indexOf("${{"); start !== -1; start = line.indexOf("${{", from)) {
92
+ const close = line.indexOf("}", start + 3);
93
+ if (close === -1) break;
94
+ if (line[close + 1] === "}") {
95
+ out += line.slice(from, start) + replace(line.slice(start + 3, close));
96
+ from = close + 2;
97
+ } else {
98
+ // Every `${{` before this `}` stops at the same `}`, so none of them can match either.
99
+ out += line.slice(from, close + 1);
100
+ from = close + 1;
101
+ }
102
+ }
103
+ return out + line.slice(from);
104
+ }
85
105
 
86
106
  export interface RenderedCommand {
87
107
  /** The line with every expression substituted as GitHub would substitute it. */
@@ -101,7 +121,7 @@ export interface RenderedCommand {
101
121
  /** Substitutes every expression in a line, applying GitHub's coercion at the boundary. */
102
122
  export function renderCommand(line: string, context: ExpressionContext): RenderedCommand {
103
123
  const resolutions: Resolution[] = [];
104
- const rendered = line.replace(EXPRESSION, (_match, body: string) => {
124
+ const rendered = replaceExpressions(line, (body) => {
105
125
  const resolution = resolveExpression(body, context);
106
126
  resolutions.push(resolution);
107
127
  return resolution.value;
@@ -121,15 +141,22 @@ export interface ConditionEvaluation {
121
141
 
122
142
  /** `a == b` / `a != b` where each side is a context lookup or a quoted literal. */
123
143
  const COMPARISON = /^(.+?)\s*(==|!=)\s*(.+)$/;
144
+ const MAX_CONDITION_LENGTH = 1000;
124
145
 
125
146
  function operandValue(token: string, context: ExpressionContext): { value: string; resolution?: Resolution } {
126
- const trimmed = token.trim().replace(/^\$\{\{\s*|\s*\}\}$/g, "").trim();
147
+ const trimmed = unwrapExpression(token.trim()).trim();
127
148
  const quoted = /^'([^']*)'$/.exec(trimmed) ?? /^"([^"]*)"$/.exec(trimmed);
128
149
  if (quoted) return { value: quoted[1]! };
129
150
  const resolution = resolveExpression(trimmed, context);
130
151
  return { value: resolution.value, resolution };
131
152
  }
132
153
 
154
+ /** `text` without a leading `${{` and a trailing `}}`; a regex with `\s*` before `}}$` is quadratic on long runs of spaces (CodeQL alert 13). */
155
+ function unwrapExpression(text: string): string {
156
+ const opened = text.startsWith("${{") ? text.slice(3) : text;
157
+ return opened.trimEnd().endsWith("}}") ? opened.trimEnd().slice(0, -2) : opened;
158
+ }
159
+
133
160
  /**
134
161
  * Evaluates a step's `if:` for one matrix instance.
135
162
  *
@@ -139,9 +166,14 @@ function operandValue(token: string, context: ExpressionContext): { value: strin
139
166
  * does not run" are different claims and only one of them is safe to act on.
140
167
  */
141
168
  export function evaluateCondition(expression: string, context: ExpressionContext, evidence?: EvidenceRef): ConditionEvaluation {
142
- const raw = expression.trim().replace(/^\$\{\{\s*|\s*\}\}$/g, "").trim();
169
+ const raw = unwrapExpression(expression.trim()).trim();
143
170
  const base = { expression: raw, ...(evidence ? { evidence } : {}) };
144
171
 
172
+ // Real `if:` conditions are short; the comparison regex below is quadratic on long whitespace runs.
173
+ if (raw.length > MAX_CONDITION_LENGTH) {
174
+ return { ...base, result: "UNRESOLVED", reason: `the condition is longer than ${MAX_CONDITION_LENGTH} characters, so it is not modelled`, resolutions: [] };
175
+ }
176
+
145
177
  if (/^true$/i.test(raw)) return { ...base, result: "TRUE", resolutions: [] };
146
178
  if (/^false$/i.test(raw)) return { ...base, result: "FALSE", resolutions: [] };
147
179
 
@@ -169,6 +201,7 @@ export function evaluateCondition(expression: string, context: ExpressionContext
169
201
  };
170
202
  }
171
203
 
172
- const equal = left.value === right.value;
204
+ // GitHub ignores case when comparing strings, so `matrix.os == 'Ubuntu-Latest'` is true for `ubuntu-latest`.
205
+ const equal = left.value.toUpperCase() === right.value.toUpperCase();
173
206
  return { ...base, result: (operator === "==" ? equal : !equal) ? "TRUE" : "FALSE", resolutions };
174
207
  }
@@ -97,15 +97,30 @@ function actionName(uses: string): string {
97
97
  // repository declares. These are REMOVED rather than left unused: dead code that still encodes the old
98
98
  // authority is one careless call away from reinstating it, and a test asserts the pattern is absent.
99
99
 
100
- /** Split a CI run line into argv without a shell. Refuses anything with shell control characters. */
100
+ /**
101
+ * Split a CI run line into argv the way `sh` would, without a shell. Refuses anything with shell control
102
+ * characters, and any word whose meaning `sh` would change that this splitter does not reproduce: a
103
+ * backslash (an escape, or a line continuation that joins the next `run:` line), an unbalanced quote, a
104
+ * comment, an unquoted glob or `~` that `sh` would expand, or a leading `NAME=value` environment
105
+ * assignment. Plain single and double quotes are removed, as `sh` removes them.
106
+ */
101
107
  function argvOf(line: string): { argv: string[]; unresolved?: Unresolved } {
108
+ const refuse = (why: string) => ({ argv: [] as string[], unresolved: { what: line, why } });
102
109
  if (/[|&;<>$`(){}]/.test(line)) {
103
- return {
104
- argv: [],
105
- unresolved: { what: line, why: "contains shell control characters; running it would need a shell, which this engine does not model" },
106
- };
110
+ return refuse("contains shell control characters; running it would need a shell, which this engine does not model");
111
+ }
112
+ if (line.includes("\\")) return refuse("contains a backslash escape or line continuation, which this engine does not model");
113
+ const argv: string[] = [];
114
+ for (const match of line.matchAll(/(?:[^\s"']+|"[^"]*"|'[^']*')+|["']/g)) {
115
+ const word = match[0];
116
+ if (word === '"' || word === "'") return refuse("contains an unbalanced quote");
117
+ const unquoted = word.replace(/"[^"]*"|'[^']*'/g, "");
118
+ if (unquoted.startsWith("#")) return refuse("contains a shell comment, which this engine does not model");
119
+ if (/[*?[]/.test(unquoted) || unquoted.startsWith("~")) return refuse("contains an unquoted glob or `~` that the shell would expand, which this engine does not model");
120
+ if (argv.length === 0 && /^[A-Za-z_][A-Za-z0-9_]*=/.test(word)) return refuse("starts with an environment assignment, which this engine does not model as argv");
121
+ argv.push(word.replace(/"([^"]*)"|'([^']*)'/g, (_all, double, single) => double ?? single));
107
122
  }
108
- return { argv: line.split(/\s+/).filter(Boolean) };
123
+ return { argv };
109
124
  }
110
125
 
111
126
  /**
@@ -95,7 +95,8 @@ export interface PurposePlan {
95
95
  /**
96
96
  * Resolves the execution path for one requested outcome.
97
97
  *
98
- * Deterministic: among jobs that provide the purpose, the one with the fewest blocked operations wins;
98
+ * Deterministic: among jobs that provide the purpose, one that runs a step of it in this instance beats one
99
+ * whose every such step its condition skips; then the one with the fewest blocked operations wins;
99
100
  * workflow-then-job order breaks ties. Preferring the least-blocked job is not a quality judgement about
100
101
  * the repository — it is choosing the path this engine can actually account for.
101
102
  *
@@ -114,7 +115,11 @@ export function planForPurpose(jobs: InferredJob[], purpose: Purpose): PurposePl
114
115
  }
115
116
 
116
117
  const blockedCount = (j: InferredJob): number => j.operations.filter((o) => !o.executable).length;
117
- const chosen = [...providers].sort((a, b) => blockedCount(a) - blockedCount(b))[0]!;
118
+ // A job (or matrix instance) whose every step of this purpose is skipped by its condition provides
119
+ // nothing here, so it is chosen only when no job runs such a step: a `matrix.os == 'ubuntu-latest'`
120
+ // test step must not make the windows instance, skipped, stand for the ubuntu one that runs it.
121
+ const skipsPurpose = (j: InferredJob): number => (j.operations.some((o) => purposeOfKind(o.kind) === purpose && o.willExecute !== false) ? 0 : 1);
122
+ const chosen = [...providers].sort((a, b) => skipsPurpose(a) - skipsPurpose(b) || blockedCount(a) - blockedCount(b))[0]!;
118
123
 
119
124
  // The prerequisite chain: install first when the job has one, then everything up to and including the
120
125
  // operations that deliver the requested purpose. Steps AFTER it are not needed for this outcome.
@@ -95,11 +95,13 @@ export function expandMatrix(matrix: unknown, evidence?: EvidenceRef): MatrixExp
95
95
  axes.push([key, values]);
96
96
  }
97
97
 
98
- // Cartesian product, in declaration order so expansion is deterministic across runs.
99
- let instances: MatrixAssignment[] = [{}];
98
+ // Cartesian product, in declaration order so expansion is deterministic across runs. A matrix with no
99
+ // axes has no original combinations: every `include` entry then becomes its own cell.
100
+ let instances: MatrixAssignment[] = axes.length > 0 ? [{}] : [];
100
101
  for (const [key, values] of axes) {
101
102
  instances = instances.flatMap((base) => values.map((v) => ({ ...base, [key]: v })));
102
103
  }
104
+ const originalKeys = new Set(axes.map(([key]) => key));
103
105
 
104
106
  const excludeRaw = Array.isArray(source.exclude) ? source.exclude : [];
105
107
  for (const entry of excludeRaw) {
@@ -117,6 +119,8 @@ export function expandMatrix(matrix: unknown, evidence?: EvidenceRef): MatrixExp
117
119
  }
118
120
 
119
121
  const includeRaw = Array.isArray(source.include) ? source.include : [];
122
+ let original = instances;
123
+ const appended: MatrixAssignment[] = [];
120
124
  for (const entry of includeRaw) {
121
125
  if (!entry || typeof entry !== "object") {
122
126
  unsupported.push({ what: JSON.stringify(entry), why: "an include entry must be an object" });
@@ -128,14 +132,17 @@ export function expandMatrix(matrix: unknown, evidence?: EvidenceRef): MatrixExp
128
132
  if (s === undefined) unsupported.push({ what: `include ${k}`, why: "non-scalar include value" });
129
133
  else addition[k] = s;
130
134
  }
131
- // GitHub: an include that matches existing combinations EXTENDS them; otherwise it appends a cell.
132
- const extended = instances.filter((i) => matches(i, addition));
133
- if (extended.length > 0) {
134
- instances = instances.map((i) => (matches(i, addition) ? { ...i, ...addition } : i));
135
- } else if (!instances.some((i) => sameAssignment(i, addition))) {
136
- instances.push(addition);
135
+ // GitHub: an include is added to every ORIGINAL combination whose original values it does not
136
+ // overwrite; values an earlier include added can be overwritten. When it fits no original
137
+ // combination it becomes a new one, and later includes never extend such an appended cell.
138
+ const fits = (i: MatrixAssignment) => Object.entries(addition).every(([k, v]) => !originalKeys.has(k) || i[k] === v);
139
+ if (original.some(fits)) {
140
+ original = original.map((i) => (fits(i) ? { ...i, ...addition } : i));
141
+ } else if (![...original, ...appended].some((i) => sameAssignment(i, addition))) {
142
+ appended.push(addition);
137
143
  }
138
144
  }
145
+ instances = [...original, ...appended];
139
146
 
140
147
  return { instances, unsupported, ...(evidence ? { evidence } : {}) };
141
148
  }
@@ -42,7 +42,7 @@ export interface PurposeVerdict {
42
42
  }
43
43
 
44
44
  /** Shell operators that end one command and begin another. */
45
- const COMMAND_SEPARATOR = /\s*(?:\|\||&&|\||;)\s*/;
45
+ const SEPARATOR_TOKEN = /\|\||&&|\||;/;
46
46
 
47
47
  /**
48
48
  * The tokens of the FIRST command on a line, even when the line as a whole is not safe argv.
@@ -53,7 +53,11 @@ const COMMAND_SEPARATOR = /\s*(?:\|\||&&|\||;)\s*/;
53
53
  * statement about the EXECUTOR. It must not delete what the step is for.
54
54
  */
55
55
  export function firstCommandTokens(line: string): string[] {
56
- const [first = ""] = line.trim().split(COMMAND_SEPARATOR);
56
+ // The first command only: everything before the first separator. Splitting on a separator with
57
+ // `\s*` edges is quadratic on long runs of spaces (CodeQL alert 37); the whitespace split drops them anyway.
58
+ const trimmed = line.trim();
59
+ const cut = trimmed.search(SEPARATOR_TOKEN);
60
+ const first = cut === -1 ? trimmed : trimmed.slice(0, cut);
57
61
  return first.split(/\s+/).filter(Boolean);
58
62
  }
59
63
 
@@ -13,6 +13,7 @@
13
13
  import { existsSync, readFileSync } from "node:fs";
14
14
  import { join } from "node:path";
15
15
 
16
+ import { replaceExpressions } from "./expression.js";
16
17
  import type { EvidenceRef, ObservedFact } from "./schema.js";
17
18
  import type { ReferenceNode } from "./reference-graph.js";
18
19
 
@@ -20,7 +21,19 @@ import type { ReferenceNode } from "./reference-graph.js";
20
21
  const OPAQUE_WRAPPERS = /^(kcd-scripts|react-scripts|nx|turbo|lerna|ut|rush|nps)\b/;
21
22
 
22
23
  /** `${{ ... }}` expressions and shell variables that repository evidence cannot settle. */
23
- const EXPRESSION = /\$\{\{\s*([^}]+?)\s*\}\}/g;
24
+ /**
25
+ * The bodies `/\$\{\{\s*([^}]+?)\s*\}\}/g` captured, in linear time (that regex is quadratic on a `${{` followed by a
26
+ * long run of spaces, CodeQL alert 38). A whitespace-only body still captures its last character, as the regex did.
27
+ */
28
+ function expressionBodies(command: string): string[] {
29
+ const bodies: string[] = [];
30
+ replaceExpressions(command, (inner) => {
31
+ const body = inner.trim() || inner.slice(-1);
32
+ if (body) bodies.push(body);
33
+ return "";
34
+ });
35
+ return bodies;
36
+ }
24
37
 
25
38
  let counter = 0;
26
39
  function nextId(prefix: string): string {
@@ -41,8 +54,7 @@ export function resetReferenceIds(): void {
41
54
  */
42
55
  export function expressionReferences(command: string, evidence: EvidenceRef): ReferenceNode[] {
43
56
  const nodes: ReferenceNode[] = [];
44
- for (const match of command.matchAll(EXPRESSION)) {
45
- const expr = match[1]!;
57
+ for (const expr of expressionBodies(command)) {
46
58
  const isMatrix = /^matrix\./.test(expr);
47
59
  const isSecret = /^secrets\./.test(expr);
48
60
  nodes.push({
@@ -121,7 +133,9 @@ export function resolveScript(repoPath: string, scriptName: string, evidence: Ev
121
133
  // A script that invokes further scripts: follow each.
122
134
  const nested: ReferenceNode[] = [];
123
135
  for (const m of body.matchAll(/\b(?:npm run|yarn(?: run)?|pnpm(?: run)?)\s+([A-Za-z0-9:_-]+)/g)) {
124
- nested.push(...resolveScript(repoPath, m[1]!, bodyEvidence, seen));
136
+ // `seen` holds this script's ancestors only. A script reached twice through different branches (a
137
+ // diamond: `ci` runs `build` and `test`, and `test` runs `build` too) is not a cycle.
138
+ nested.push(...resolveScript(repoPath, m[1]!, bodyEvidence, new Set(seen)));
125
139
  }
126
140
 
127
141
  const expressions = expressionReferences(body, bodyEvidence);
@@ -23,7 +23,14 @@ export function isConventionalCiConfigPath(path: string): boolean {
23
23
  if (path.startsWith(".github/workflows/")) return true;
24
24
  const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
25
25
  if (/(?:^|\.)gitlab-ci\.ya?ml$/.test(base)) return true; // .gitlab-ci.yml, test.gitlab-ci.yml
26
- return path.startsWith(".gitlab/") && YAML.test(path); // .gitlab/ci/*.yml and similar
26
+ if (path.startsWith(".gitlab/") && YAML.test(path)) return true; // .gitlab/ci/*.yml and similar
27
+ // Other providers' conventional pipeline files (#183). Azure Pipelines is where the DiffCIObserve task runs;
28
+ // before this, a change to its pipeline was an unknown file narrowed to the tests that read it.
29
+ if (/^azure-pipelines\.ya?ml$/.test(base)) return true;
30
+ if (/^\.(?:azure-pipelines|azuredevops)\//.test(path) && YAML.test(path)) return true;
31
+ if (path.startsWith(".circleci/") || path.startsWith(".buildkite/")) return true;
32
+ if (path === "bitbucket-pipelines.yml" || path === ".travis.yml") return true;
33
+ return path.slice(path.lastIndexOf("/") + 1) === "Jenkinsfile";
27
34
  }
28
35
 
29
36
  export interface GitlabIncludes {
@@ -148,30 +148,25 @@ export function parseNameStatus(buffer: Buffer): ChangedFile[] {
148
148
  return files;
149
149
  }
150
150
 
151
- function parseNumstatRecord(record: string): { path: string; isBinary: boolean } | undefined {
152
- if (!record) return undefined;
153
-
154
- const fields = record.split("\t");
155
- if (fields.length < 3) return undefined;
156
-
157
- const isBinary = fields[0]?.trimStart().startsWith("-") ?? false;
158
- const hasRename = fields.length >= 4;
159
- const newPath = hasRename ? fields[fields.length - 1] : fields[2];
160
-
161
- if (!newPath) return undefined;
162
- return { path: newPath, isBinary };
163
- }
164
-
151
+ /**
152
+ * Parses `git diff-tree --numstat -z`. Each record is `added\tdeleted\tpath\0`, except a rename or copy:
153
+ * `added\tdeleted\t\0old\0new\0`, an empty path followed by both paths as their own fields (#175).
154
+ * `-z` leaves paths unquoted, so a path may itself contain a tab.
155
+ */
165
156
  export function parseNumstat(buffer: Buffer): Map<string, boolean> {
166
- const text = buffer.toString("utf8");
167
- const records = text.split("\0");
157
+ const tokens = buffer.toString("utf8").split("\0");
168
158
  const binaryByNewPath = new Map<string, boolean>();
169
159
 
170
- for (const record of records) {
171
- const parsed = parseNumstatRecord(record);
172
- if (parsed) {
173
- binaryByNewPath.set(parsed.path, parsed.isBinary);
160
+ for (let i = 0; i < tokens.length; i++) {
161
+ const fields = tokens[i]!.split("\t");
162
+ if (fields.length < 3) continue;
163
+ const isBinary = fields[0]!.trimStart().startsWith("-");
164
+ let path = fields.slice(2).join("\t");
165
+ if (path === "") {
166
+ path = tokens[i + 2] ?? "";
167
+ i += 2;
174
168
  }
169
+ if (path) binaryByNewPath.set(path, isBinary);
175
170
  }
176
171
 
177
172
  return binaryByNewPath;
@@ -239,7 +234,7 @@ export const CONFIG_PATTERNS = [
239
234
  // Python projects (2026-11-06): what pytest, the interpreter and the installed packages are.
240
235
  /^pyproject\.toml$/,
241
236
  /^setup\.(?:py|cfg)$/,
242
- /^pytest\.ini$/,
237
+ /^\.?pytest\.ini$/,
243
238
  /^tox\.ini$/,
244
239
  /^noxfile\.py$/,
245
240
  /^requirements[^/]*\.(?:txt|in)$/,
@@ -252,6 +247,10 @@ export const CONFIG_PATTERNS = [
252
247
  /^\.nvmrc$/,
253
248
  /^\.node-version$/,
254
249
  /^\.npmrc$/,
250
+ // Mocha's configuration (issue #142). `.mocharc.json` reads as an asset by extension and
251
+ // `.mocharc.js` as code with no importers, so neither reached the configuration signals; both
252
+ // decide how the suite runs.
253
+ /^\.mocharc(?:\.[^/]+)?$/,
255
254
  ];
256
255
 
257
256
  // Stage 1B fix (2026-08-21, docs/research/2026-08-21-stage1b-*.md): root-caused in Stage 1A's fallback-
@@ -161,6 +161,26 @@ function covers(target: string, path: string, extensions: readonly string[]): bo
161
161
  return inside && extensions.includes(posix.extname(path).slice(1));
162
162
  }
163
163
 
164
+ /** Other names configuration uses for a file type: `@eslint/markdown` lints `.md`, `eslint-plugin-yml` `.yaml`. */
165
+ const EXTENSION_ALIASES: Readonly<Record<string, readonly string[]>> = { md: ["markdown"], yml: ["yaml"], yaml: ["yml"], jsonc: ["json"], json5: ["json"] };
166
+
167
+ /**
168
+ * Extensions of changed files that the ESLint configuration names (2026-11-17). A directory target lints
169
+ * every file a flat config's `files` (or an eslintrc `overrides[].files`) reaches, not only JavaScript and
170
+ * TypeScript: `...vue.configs["flat/recommended"]` makes `eslint src` lint `src/App.vue`. A changed file's
171
+ * extension that appears in the configuration text, or a plugin named for it, therefore counts as linted.
172
+ */
173
+ function configuredExtensions(changes: readonly ChangedPath[], texts: readonly string[]): string[] {
174
+ const found = new Set<string>();
175
+ for (const { path } of changes) {
176
+ const extension = posix.extname(path).slice(1).toLowerCase();
177
+ if (!/^\w+$/.test(extension) || ESLINT_EXTENSIONS.includes(extension) || found.has(extension)) continue;
178
+ const names = [extension, ...(EXTENSION_ALIASES[extension] ?? [])];
179
+ if (texts.some((text) => names.some((name) => new RegExp(`\\b${name}\\b`, "i").test(text)))) found.add(extension);
180
+ }
181
+ return [...found];
182
+ }
183
+
164
184
  /** Root configuration files of the tool that exist, and the paths each one names relatively. */
165
185
  function configReferences(tool: Tool, input: NarrowingInput, explicit: string | undefined): { texts: string[]; referenced: string[] } {
166
186
  const candidates = explicit ? [posix.normalize(explicit)] : tool.name === "eslint"
@@ -224,7 +244,8 @@ function decide(check: GateCheck, input: NarrowingInput, cache: RootTextCache):
224
244
 
225
245
  const extensions = tool.name === "eslint" && values.has("--ext")
226
246
  ? [...ESLINT_EXTENSIONS, ...values.get("--ext")!.split(",").map((ext) => ext.replace(/^\./, ""))]
227
- : tool.extensions;
247
+ : tool.name === "eslint" ? [...ESLINT_EXTENSIONS, ...configuredExtensions(input.changes, texts)]
248
+ : tool.extensions;
228
249
  if (tool.name === "eslint") {
229
250
  const nested = input.files?.find((path) => path.includes("/") && ESLINT_CONFIG.test(posix.basename(path)) && !posix.basename(path).endsWith("ignore"));
230
251
  const importRules = texts.some((text) => IMPORT_RULES.test(text));
@@ -64,7 +64,7 @@ const CONCURRENTLY = /^(?:npx\s+(?:--no-install\s+)?)?concurrently\b(.*)$/;
64
64
  const REPO_RUNNER = /^(?:node|tsx|bun)\s+(\.{0,2}\/?[\w./-]+\.(?:m?[jt]s|c[jt]s))((?:\s+[\w:.@/-]+)+)$/;
65
65
  /** Shell syntax whose meaning changes when the script is split into parts or run outside its shell. */
66
66
  const UNSPLITTABLE = /\|\||[|<>`$()\\]|^\s*\w+=|\s\w+=\S/;
67
- const TEST_RUNNER = /(?:^|[\s/])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine)(?:\s|$)|(?:node|tsx|bun|deno)(?:\s+--?[\w-]+(?:=\S+)?)*\s+--test\b|^(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test(?:\s|$)/;
67
+ const TEST_RUNNER = /(?:^|[\s/])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine)(?:\s|$)|(?:node|tsx|bun|deno)(?:\s+-\S*)*\s+--test\b|^(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test(?:\s|$)/;
68
68
 
69
69
  function kindOf(command: string): GateCheckKind {
70
70
  if (/(?:^|[\s/])(?:tsc|vue-tsc|svelte-check|tsgo)(?:\s|$)/.test(command)) return "typecheck";
@@ -100,10 +100,21 @@ function splitParts(body: string): string[] | undefined {
100
100
  parts.push(current.trim());
101
101
  const unquoted = parts.map((part) => part.replace(/"[^"]*"|'[^']*'/g, "\"\""));
102
102
  // A double-quoted `$` or backtick still expands in the shell.
103
- if (parts.some((part) => !part || /"[^"]*[$`][^"]*"/.test(part)) || unquoted.some((part) => UNSPLITTABLE.test(part))) return undefined;
103
+ if (parts.some((part) => !part || expandsBetweenDoubleQuotes(part)) || unquoted.some((part) => UNSPLITTABLE.test(part))) return undefined;
104
104
  return parts;
105
105
  }
106
106
 
107
+ /**
108
+ * True when a `$` or backtick sits between two double quotes, the answer `/"[^"]*[$`][^"]*"/` gives.
109
+ * That regex is quadratic on a `"` followed by a long run of backticks with no closing quote (#300);
110
+ * this is one linear pass: the text strictly between two consecutive `"` holds a `$` or backtick.
111
+ */
112
+ export function expandsBetweenDoubleQuotes(part: string): boolean {
113
+ const segments = part.split("\"");
114
+ for (let i = 1; i < segments.length - 1; i++) if (/[$`]/.test(segments[i]!)) return true;
115
+ return false;
116
+ }
117
+
107
118
  function globToRegExp(pattern: string): RegExp {
108
119
  return new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, ".*").replace(/\*/g, "[^:]*")}$`);
109
120
  }
@@ -19,25 +19,53 @@ function expandBraces(pattern: string): string[] {
19
19
  return result;
20
20
  }
21
21
 
22
+ /**
23
+ * A task input glob as an anchored regex, with the same reading as the research matcher (#178/#179). `**\/`
24
+ * is any number of leading directories, a trailing `/**` is anything below, and any other `**` (`**.js`, a
25
+ * bare `**`) is any run of characters including `/`, as in GitHub's path filters. `*` and `?` stay within one
26
+ * segment, `[...]`/`[!...]` is a character class, `\` escapes the next character, and every other character
27
+ * is literal, so route directories like `app/(marketing)`, `routes/$id.tsx` and `c++/` match themselves.
28
+ */
22
29
  function regexFrom(pattern: string): RegExp {
23
- let escaped = pattern.replace(/\\/g, "\\\\").replace(/\./g, "\\.");
24
- // Protect the multi-segment globstar sequences behind placeholders before the
25
- // single-`*` replace runs below - otherwise the `*` inside "(?:.*/)?"/"(?:/.*)?" gets
26
- // re-matched and mangled by that same replace (e.g. "src/**/*.test.ts" would wrongly
27
- // fail to match files nested two or more directories under src/, since the resulting
28
- // regex only reliably matched zero or one intervening path segment).
29
- escaped = escaped
30
- .replace(/\*\*\//g, "\0GLOBSTAR_SLASH\0")
31
- .replace(/\/\*\*/g, "\0SLASH_GLOBSTAR\0")
32
- .replace(/\*/g, "[^/]*")
33
- .replace(/\0GLOBSTAR_SLASH\0/g, "(?:.*/)?")
34
- .replace(/\0SLASH_GLOBSTAR\0/g, "(?:/.*)?");
35
- return new RegExp(`^${escaped}$`);
30
+ const literal = (character: string): string => character.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
31
+ let source = "";
32
+ for (let index = 0; index < pattern.length; index++) {
33
+ const character = pattern[index]!;
34
+ if (pattern.startsWith("**/", index)) { source += "(?:.*/)?"; index += 2; continue; }
35
+ if (pattern.startsWith("/**", index) && index + 3 === pattern.length) { source += "(?:/.*)?"; index += 2; continue; }
36
+ if (pattern.startsWith("**", index)) { source += ".*"; index += 1; continue; }
37
+ if (character === "*") { source += "[^/]*"; continue; }
38
+ if (character === "?") { source += "[^/]"; continue; }
39
+ if (character === "\\" && index + 1 < pattern.length) { source += literal(pattern[++index]!); continue; }
40
+ if (character === "[") {
41
+ const close = pattern.indexOf("]", index + 2);
42
+ if (close > index) {
43
+ let body = pattern.slice(index + 1, close);
44
+ const negated = body.startsWith("!") || body.startsWith("^");
45
+ if (negated) body = body.slice(1);
46
+ source += `[${negated ? "^/" : ""}${body.replace(/[\\\]^[]/g, "\\$&")}]`;
47
+ index = close;
48
+ continue;
49
+ }
50
+ }
51
+ source += literal(character);
52
+ }
53
+ return new RegExp(`^${source}$`);
36
54
  }
37
55
 
38
56
  function matches(path: string, pattern: string): boolean {
39
57
  const normalized = path.replace(/\\/g, "/");
40
- return expandBraces(pattern).some((p) => regexFrom(p).test(normalized));
58
+ return expandBraces(pattern).some((p) => {
59
+ let regex: RegExp;
60
+ try {
61
+ regex = regexFrom(p);
62
+ } catch {
63
+ // A pattern that is not a valid filter cannot rule a change out: count it as matching, so the
64
+ // task runs rather than the whole plan throwing.
65
+ return true;
66
+ }
67
+ return regex.test(normalized);
68
+ });
41
69
  }
42
70
 
43
71
  function matchesAny(path: string, patterns: string[] | undefined): boolean {
@@ -4,6 +4,8 @@ import type { SelectiveTestCommandGroup, SelectiveTestCommandPlan } from "./test
4
4
 
5
5
  /** Cargo target names are literal arguments, not paths, globs, package specs or shell fragments. */
6
6
  const literalName = /^[A-Za-z0-9_][A-Za-z0-9_-]*$/;
7
+ /** A package is its name, or NAME@VERSION when a dependency shares the name (adapters/rust.ts). */
8
+ const packageSpec = /^[A-Za-z0-9_][A-Za-z0-9_-]*(?:@\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)?$/;
7
9
 
8
10
  /** Only the Rust adapter may attest that the repository's invocation is reproducible. Missing
9
11
  * evidence (including old cached profiles) must never become a guessed default test command. */
@@ -31,16 +33,27 @@ export function planRustTestCommands(profile: RepositoryProfile, selectedPaths:
31
33
  return refuse("Rust tests require verified Cargo package and target metadata");
32
34
  }
33
35
  const target = targets[path]!;
34
- if (!literalName.test(packages[path]!) || !literalName.test(target.name)
36
+ if (!packageSpec.test(packages[path]!) || !literalName.test(target.name)
35
37
  || !["lib", "bin", "test", "bench", "example"].includes(target.kind)) {
36
38
  return refuse("Invalid Cargo package or test target");
37
39
  }
38
40
  }
41
+ // A target with `required-features` runs only when Cargo enables those features for its package.
42
+ // Naming it (`--test name`) makes Cargo fail instead of skipping it, so its package stays whole:
43
+ // `cargo test -p name` runs exactly the targets the full run runs for that package.
44
+ const gated = new Set(paths.filter(path => targets[path]!.requiredFeatures !== undefined).map(path => packages[path]!));
45
+ for (const path of paths) {
46
+ const required = targets[path]!.requiredFeatures;
47
+ if (required !== undefined && (!Array.isArray(required) || !required.length || required.some(feature => typeof feature !== "string"))) {
48
+ return refuse("Invalid Cargo package or test target");
49
+ }
50
+ }
39
51
  const groups: SelectiveTestCommandGroup[] = [];
40
52
  const cratePackages: string[] = [];
41
53
  const cratePaths: string[] = [];
42
54
  for (const pkg of [...new Set(paths.map(path => packages[path]!))].sort()) {
43
55
  const owned = paths.filter(path => packages[path] === pkg);
56
+ if (gated.has(pkg)) { cratePackages.push(pkg); cratePaths.push(...owned); continue; }
44
57
  const ordinary = owned.filter(path => ["lib", "bin", "test"].includes(targets[path]!.kind));
45
58
  if (ordinary.length) {
46
59
  // A crate unit-test root represents the whole crate, including doctests. Do not narrow it to
@@ -74,6 +87,29 @@ export function planRustTestCommands(profile: RepositoryProfile, selectedPaths:
74
87
  // as the full `cargo test` does (see rustFeatureCoverage in adapters/rust.ts).
75
88
  const coverage = profile.rustFeatureCoverage;
76
89
  if (!coverage) return refuse("Rust tests require verified Cargo feature resolution");
90
+ const uncovered = (selected: ReadonlySet<string>) => [...selected].sort().flatMap(pkg => coverage.deficits[pkg] ?? [])
91
+ .find(dependency => !coverage.units.some(unit => unit.covers.includes(dependency) && unit.crates.every(name => selected.has(name))));
92
+ const packageGroup = groups.find(group => group.runnerId === "cargo:test:packages");
93
+ if (packageGroup) {
94
+ // When testing only the selected crates would build a shared dependency with fewer features than
95
+ // the full run, add the tested crates of the smallest unit Cargo resolved with the full run's
96
+ // features. Features only grow with the crates selected and never exceed the full run's, so the
97
+ // larger command still builds that dependency exactly as the full run does; it runs more tests
98
+ // than selected, but fewer than the full run. Each round adds a crate, so this ends.
99
+ const selected = new Set(cratePackages);
100
+ for (let missing = uncovered(selected); missing !== undefined; missing = uncovered(selected)) {
101
+ const extra = (unit: { crates: string[] }) => unit.crates.filter(name => !selected.has(name)).length;
102
+ const unit = coverage.units.filter(candidate => candidate.covers.includes(missing!) && candidate.crates.every(name => packageSpec.test(name)))
103
+ .sort((a, b) => extra(a) - extra(b) || a.crates.join(" ").localeCompare(b.crates.join(" ")))[0];
104
+ if (!unit) break;
105
+ for (const name of unit.crates) selected.add(name);
106
+ }
107
+ const added = [...selected].filter(name => !cratePackages.includes(name)).sort();
108
+ if (added.length) {
109
+ packageGroup.commandSpec = { executable: "cargo", args: ["test", ...[...selected].sort().flatMap(pkg => ["-p", pkg])] };
110
+ packageGroup.label = `Cargo package tests (with ${added.join(", ")} for the full run's features)`;
111
+ }
112
+ }
77
113
  for (const group of groups) {
78
114
  const args = group.commandSpec.args;
79
115
  const selected = new Set(args.flatMap((arg, index) => args[index - 1] === "-p" ? [arg] : []));
@@ -65,7 +65,11 @@ function scanModule(path: string, text: string): { literals: string[]; imports:
65
65
  else computed = true;
66
66
  }
67
67
  if (ts.isStringLiteralLike(node)) literals.push(node.text);
68
- else if (ts.isTemplateExpression(node)) literals.push(node.head.text);
68
+ else if (ts.isTemplateExpression(node)) {
69
+ // Text after a substitution is read too: `${process.cwd()}/data/schema.json` names data/schema.json, and
70
+ // the `/` that joins it to the substitution is not an absolute path.
71
+ literals.push(node.head.text, ...node.templateSpans.map((span) => span.literal.text.replace(/^\/+/, "")));
72
+ }
69
73
  ts.forEachChild(node, visit);
70
74
  };
71
75
  visit(source);
@@ -141,9 +141,24 @@ function configAllowsPath(config: TestRunnerConfig, path: string): boolean {
141
141
  const PATTERN_CHARACTERS = /[[\]*?{}()+^$|]/;
142
142
  const LITERAL_PATH_FRAMEWORKS: ReadonlySet<KnownTestFramework> = new Set(["vitest", "bun:test"]);
143
143
 
144
+ /**
145
+ * Whether `path` has a `{...,...}` or `{...}` range with `..`, as `/\{[^}]*(?:,|\.\.)[^}]*\}/` tests, in linear
146
+ * time (that regex is quadratic on a long run of `{`, CodeQL alert 14). The widest candidate before each `}` starts
147
+ * at the first `{` after the previous `}`, so checking that one per segment is enough.
148
+ */
149
+ function hasBraceExpansion(path: string): boolean {
150
+ const segments = path.split("}");
151
+ return segments.slice(0, -1).some((segment) => {
152
+ const open = segment.indexOf("{");
153
+ if (open === -1) return false;
154
+ const body = segment.slice(open + 1);
155
+ return body.includes(",") || body.includes("..");
156
+ });
157
+ }
158
+
144
159
  /** `path` as a `node --test` glob that matches only itself, or undefined when none can. */
145
160
  export function nodeTestGlobForPath(path: string): string | undefined {
146
- if (/\{[^}]*(?:,|\.\.)[^}]*\}/.test(path)) return undefined;
161
+ if (hasBraceExpansion(path)) return undefined;
147
162
  return path.replace(/[[\]*?{}()]/g, (character) => `@([${character}])`);
148
163
  }
149
164
 
@@ -234,7 +249,7 @@ function runsOnlyDefaultVitest(scripts: Readonly<Record<string, string>>, name =
234
249
  const script = scripts[name];
235
250
  if (script === undefined) return depth > 0;
236
251
  if (depth > 5 || !script.trim() || scripts[`pre${name}`] || scripts[`post${name}`]) return false;
237
- return script.split(/\s*&&\s*/).every((phase) => {
252
+ return script.split("&&").every((phase) => {
238
253
  const run = /^(?:npm|pnpm|yarn|bun) (?:run )?([\w:-]+)$/.exec(phase.trim());
239
254
  if (run) return runsOnlyDefaultVitest(scripts, run[1]!, depth + 1);
240
255
  const words = phase.trim().split(/\s+/);