sedum-cli 0.1.0-alpha.10 → 0.1.0-alpha.12

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.
@@ -0,0 +1,392 @@
1
+ import {
2
+ discoverRunTests
3
+ } from "./chunk-AWBC7NOM.js";
4
+ import {
5
+ createCliProvider,
6
+ providerDiagnostic
7
+ } from "./chunk-S7OB3JEF.js";
8
+ import {
9
+ affectedPathIgnored,
10
+ loadProjectConfig,
11
+ validAffectedGlob
12
+ } from "./chunk-FAGJCNV7.js";
13
+
14
+ // src/affected-selection.ts
15
+ import { realpath } from "fs/promises";
16
+ import path2 from "path";
17
+ import {
18
+ isScriptTestFile,
19
+ loadFlowFile,
20
+ ProviderError,
21
+ resolveFlowModules
22
+ } from "@sedum-dev/core";
23
+
24
+ // src/affected-git.ts
25
+ import path from "path";
26
+
27
+ // src/affected-git-read.ts
28
+ import { spawn } from "child_process";
29
+ import { isUtf8 } from "buffer";
30
+ var MAX_DIFF_BYTES = 16 * 1024 * 1024;
31
+ var AffectedSelectionError = class extends Error {
32
+ };
33
+ function gitRead(cwd, args, signal, limit = MAX_DIFF_BYTES) {
34
+ return new Promise((resolve, reject) => {
35
+ const child = spawn("git", args, {
36
+ cwd,
37
+ stdio: ["ignore", "pipe", "ignore"],
38
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
39
+ ...signal ? { signal } : {}
40
+ });
41
+ const buffers = [];
42
+ let bytes = 0;
43
+ let exceeded = false;
44
+ child.stdout.on("data", (buffer) => {
45
+ bytes += buffer.length;
46
+ if (bytes > limit) {
47
+ exceeded = true;
48
+ child.kill();
49
+ } else buffers.push(buffer);
50
+ });
51
+ child.on("error", reject);
52
+ child.on("close", (code) => {
53
+ if (exceeded)
54
+ reject(
55
+ new AffectedSelectionError(
56
+ "Retained Git input exceeds the 16 MiB guard. Run the full suite; input was not truncated."
57
+ )
58
+ );
59
+ else if (code !== 0) reject(new Error("Git read failed"));
60
+ else resolve(Buffer.concat(buffers));
61
+ });
62
+ }).then(decodeGitOutput);
63
+ }
64
+ function decodeGitOutput(output) {
65
+ if (!isUtf8(output))
66
+ throw new AffectedSelectionError(
67
+ "Git input is not valid UTF-8. Run the full suite."
68
+ );
69
+ return output.toString("utf8");
70
+ }
71
+
72
+ // src/affected-git.ts
73
+ async function assertAffectedSnapshot({
74
+ root,
75
+ head,
76
+ signal
77
+ }) {
78
+ signal?.throwIfAborted();
79
+ await assertVisibleIndex({ root, head, signal });
80
+ const status = await gitRead(
81
+ root,
82
+ [
83
+ "status",
84
+ "--porcelain=v1",
85
+ "-z",
86
+ "--untracked-files=no",
87
+ "--ignore-submodules=none"
88
+ ],
89
+ signal
90
+ );
91
+ if (status)
92
+ throw new AffectedSelectionError(
93
+ "Tracked staged or unstaged changes (including dirty submodules) are not allowed with --affected, even on ignored paths. Commit or stash them first; no sources were sent."
94
+ );
95
+ if ((await gitRead(root, ["rev-parse", "HEAD"], signal)).trim() !== head)
96
+ throw new AffectedSelectionError(
97
+ "HEAD changed during affected selection. Retry from a clean checkout."
98
+ );
99
+ }
100
+ async function assertVisibleIndex({
101
+ root,
102
+ signal
103
+ }) {
104
+ const entries = (await gitRead(
105
+ root,
106
+ ["ls-files", "-v", "-z", "--full-name", "--", ":/"],
107
+ signal
108
+ )).split("\0");
109
+ if (entries.some((entry) => /^[a-zS] /u.test(entry)))
110
+ throw new AffectedSelectionError(
111
+ "Tracked files with assume-unchanged or skip-worktree flags are not supported with --affected, even on ignored paths. Clear those index flags or run without --affected; no sources were sent."
112
+ );
113
+ }
114
+ async function readCommittedSource({ root, head, signal }, file) {
115
+ const relative = repositoryRelativePath(root, file);
116
+ try {
117
+ return await gitRead(root, ["show", `${head}:${relative}`], signal);
118
+ } catch (error) {
119
+ rethrowGitError(
120
+ error,
121
+ signal,
122
+ "A test or module is not readable at pinned HEAD. Commit test sources before using --affected."
123
+ );
124
+ }
125
+ }
126
+ function rethrowGitError(error, signal, message) {
127
+ if (error instanceof AffectedSelectionError) throw error;
128
+ signal?.throwIfAborted();
129
+ throw new AffectedSelectionError(message);
130
+ }
131
+ function repositoryRelativePath(root, file) {
132
+ const relative = path.relative(root, file).split(path.sep).join("/");
133
+ if (relative.startsWith("../") || path.isAbsolute(relative))
134
+ throw new AffectedSelectionError(
135
+ "A test or module is outside the Git repository."
136
+ );
137
+ return relative;
138
+ }
139
+ async function findBaseRef({ root, signal }) {
140
+ for (const candidate of [
141
+ "refs/heads/main",
142
+ "refs/remotes/origin/main",
143
+ "refs/heads/master",
144
+ "refs/remotes/origin/master"
145
+ ]) {
146
+ try {
147
+ await gitRead(
148
+ root,
149
+ ["rev-parse", "--verify", "--end-of-options", `${candidate}^{commit}`],
150
+ signal
151
+ );
152
+ return candidate;
153
+ } catch {
154
+ signal?.throwIfAborted();
155
+ }
156
+ }
157
+ throw new AffectedSelectionError(
158
+ "No main or master ref found. Fetch the base branch or pass --base <ref>."
159
+ );
160
+ }
161
+ async function resolveBranchRange(snapshot, base) {
162
+ const reference = base || await findBaseRef(snapshot);
163
+ const commit = (await gitRead(
164
+ snapshot.root,
165
+ ["rev-parse", "--verify", "--end-of-options", `${reference}^{commit}`],
166
+ snapshot.signal
167
+ )).trim();
168
+ const mergeBase = (await gitRead(
169
+ snapshot.root,
170
+ ["merge-base", commit, snapshot.head],
171
+ snapshot.signal
172
+ )).trim();
173
+ return { reference, mergeBase };
174
+ }
175
+ async function assertUntrackedIgnored({ root, signal }, ignore) {
176
+ const untracked = (await gitRead(
177
+ root,
178
+ [
179
+ "ls-files",
180
+ "--others",
181
+ "--exclude-standard",
182
+ "--full-name",
183
+ "-z",
184
+ "--",
185
+ ":/"
186
+ ],
187
+ signal
188
+ )).split("\0").filter(Boolean);
189
+ if (untracked.some((file) => !affectedPathIgnored(file, ignore)))
190
+ throw new AffectedSelectionError(
191
+ "Untracked files are not represented in committed git diff. Commit intended files or ignore unrelated files before using --affected."
192
+ );
193
+ }
194
+ var DIFF_ARGS = [
195
+ "diff",
196
+ "--no-ext-diff",
197
+ "--no-textconv",
198
+ "--no-renames",
199
+ "--no-relative",
200
+ "--ignore-submodules=none"
201
+ ];
202
+ async function readRetainedPatches({ root, head, signal }, mergeBase, files) {
203
+ const patches = [];
204
+ let bytes = 0;
205
+ for (const file of files) {
206
+ const patch = await gitRead(
207
+ root,
208
+ [
209
+ ...DIFF_ARGS,
210
+ "--no-color",
211
+ "--submodule=short",
212
+ "--src-prefix=a/",
213
+ "--dst-prefix=b/",
214
+ "--unified=3",
215
+ mergeBase,
216
+ head,
217
+ "--",
218
+ `:(top,literal)${file}`
219
+ ],
220
+ signal,
221
+ MAX_DIFF_BYTES - bytes
222
+ );
223
+ if (/^Binary files .* differ$/mu.test(patch) || /^[+ -]Subproject commit /mu.test(patch))
224
+ throw new AffectedSelectionError(
225
+ "Binary or submodule changes cannot be scored reliably. Run the full suite without --affected."
226
+ );
227
+ bytes += Buffer.byteLength(patch);
228
+ patches.push(patch);
229
+ }
230
+ return patches.join("");
231
+ }
232
+ function assertValidIgnores(ignore) {
233
+ if (ignore.some((pattern) => !validAffectedGlob(pattern)))
234
+ throw new AffectedSelectionError(
235
+ "Affected ignores must be valid nonempty repository-relative POSIX globs."
236
+ );
237
+ }
238
+ async function readBranchDiff(cwd, base, signal, ignore = []) {
239
+ assertValidIgnores(ignore);
240
+ const git = (...args) => gitRead(cwd, args, signal);
241
+ try {
242
+ const root = (await git("rev-parse", "--show-toplevel")).trim();
243
+ const head = (await git("rev-parse", "--verify", "HEAD^{commit}")).trim();
244
+ const snapshot = { root, head, signal };
245
+ await assertAffectedSnapshot(snapshot);
246
+ const { reference, mergeBase } = await resolveBranchRange(snapshot, base);
247
+ await assertUntrackedIgnored(snapshot, ignore);
248
+ const changed = (await git(...DIFF_ARGS, "--name-only", "-z", mergeBase, head, "--", ":/")).split("\0").filter(Boolean);
249
+ const ignoredFiles = changed.filter(
250
+ (file) => affectedPathIgnored(file, ignore)
251
+ );
252
+ const diff = await readRetainedPatches(
253
+ snapshot,
254
+ mergeBase,
255
+ changed.filter((file) => !affectedPathIgnored(file, ignore))
256
+ );
257
+ await assertAffectedSnapshot(snapshot);
258
+ return {
259
+ root,
260
+ base: reference,
261
+ head,
262
+ mergeBase,
263
+ diff,
264
+ changed,
265
+ ignoredFiles
266
+ };
267
+ } catch (error) {
268
+ rethrowGitError(
269
+ error,
270
+ signal,
271
+ "Could not read a complete Git diff. Check the base ref and merge-base history (fetch deeper for shallow clones), or run without --affected."
272
+ );
273
+ }
274
+ }
275
+
276
+ // src/affected-selection.ts
277
+ async function selectAffectedTests(options) {
278
+ const config = await loadProjectConfig(options.cwd, process.env, {
279
+ ...options.environment ? { environment: options.environment } : {}
280
+ });
281
+ const canonicalProjectRoot = await realpath(config.projectRoot);
282
+ const branch = await readBranchDiff(
283
+ config.projectRoot,
284
+ options.base,
285
+ options.signal,
286
+ [...config.affected.ignore, ...options.ignore ?? []]
287
+ );
288
+ const snapshot = {
289
+ root: branch.root,
290
+ head: branch.head,
291
+ signal: options.signal
292
+ };
293
+ const source = async (file) => readCommittedSource(snapshot, await realpath(file));
294
+ const selection = await discoverRunTests(
295
+ config,
296
+ options.paths,
297
+ options.filters
298
+ );
299
+ if (selection.invalid.length || selection.problems.length || !selection.tests.length)
300
+ throw new AffectedSelectionError(
301
+ "Test discovery is empty or invalid. Run sedum validate and fix discovery before using --affected."
302
+ );
303
+ const changed = new Set(
304
+ branch.changed.map((file) => path2.resolve(branch.root, file))
305
+ );
306
+ for (const file of [...changed])
307
+ changed.add(await realpath(file).catch(() => file));
308
+ const tests = [];
309
+ const forced = [];
310
+ for (const test of selection.tests) {
311
+ const file = path2.join(config.projectRoot, test.file);
312
+ if (isScriptTestFile(file)) {
313
+ if (tests.some((scored) => scored.file === test.file)) continue;
314
+ forced.push(changed.has(await realpath(file)));
315
+ tests.push({
316
+ file: test.file,
317
+ source: await source(file),
318
+ modules: []
319
+ });
320
+ continue;
321
+ }
322
+ const parsed = await loadFlowFile(file, {
323
+ repoRoot: config.projectRoot,
324
+ rejectSymlinks: true
325
+ });
326
+ const resolved = await resolveFlowModules(parsed, {
327
+ repoRoot: config.projectRoot
328
+ });
329
+ if (!resolved.value || resolved.diagnostics.some((item) => item.severity === "error"))
330
+ throw new AffectedSelectionError(
331
+ "A test or module is invalid. Run sedum validate before using --affected."
332
+ );
333
+ const files = [await realpath(file), ...resolved.moduleFiles];
334
+ forced.push(files.some((source2) => changed.has(source2)));
335
+ tests.push({
336
+ file: test.file,
337
+ source: await source(file),
338
+ modules: await Promise.all(
339
+ resolved.moduleFiles.map(async (module) => ({
340
+ file: path2.relative(canonicalProjectRoot, module).split(path2.sep).join("/"),
341
+ source: await source(module)
342
+ }))
343
+ )
344
+ });
345
+ }
346
+ options.signal?.throwIfAborted();
347
+ await assertAffectedSnapshot(snapshot);
348
+ const candidates = tests.filter((_, index) => !forced[index]);
349
+ let scores;
350
+ try {
351
+ scores = branch.diff && candidates.length ? await (options.createProvider ? await options.createProvider(config) : await createCliProvider(config)).scoreRelevance(
352
+ branch.diff,
353
+ candidates,
354
+ options.signal ? { signal: options.signal } : void 0
355
+ ) : { probabilities: candidates.map(() => 0), calls: [], chunkCount: 0 };
356
+ } catch (error) {
357
+ if (error instanceof ProviderError && (error.code === "authentication" || error.code === "configuration")) {
358
+ const diagnostic = providerDiagnostic(config.providerName, error.code);
359
+ throw new AffectedSelectionError(
360
+ `${diagnostic.message}
361
+ Fix: ${diagnostic.fix}`
362
+ );
363
+ }
364
+ throw error;
365
+ }
366
+ let candidateIndex = 0;
367
+ const probabilities = tests.map(
368
+ (_, index) => forced[index] ? 1 : scores.probabilities[candidateIndex++]
369
+ );
370
+ return {
371
+ base: branch.base,
372
+ head: branch.head,
373
+ mergeBase: branch.mergeBase,
374
+ changedFiles: branch.changed,
375
+ ignoredFiles: branch.ignoredFiles,
376
+ chunkCount: scores.chunkCount ?? (scores.calls.length ? 1 : 0),
377
+ aggregation: "max",
378
+ threshold: options.threshold,
379
+ calls: scores.calls,
380
+ tests: tests.map((test, index) => ({
381
+ file: test.file,
382
+ probability: probabilities[index],
383
+ selected: forced[index] || branch.diff !== "" && probabilities[index] >= options.threshold,
384
+ reason: forced[index] ? "test-or-module-changed" : branch.diff ? "model" : branch.ignoredFiles.length ? "all-ignored" : "no-diff"
385
+ }))
386
+ };
387
+ }
388
+ export {
389
+ AffectedSelectionError,
390
+ readBranchDiff,
391
+ selectAffectedTests
392
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  discoverConfiguredTests
3
- } from "./chunk-VNGIF7AY.js";
3
+ } from "./chunk-FAGJCNV7.js";
4
4
 
5
5
  // src/run-selection.ts
6
6
  import { lstat, realpath } from "fs/promises";
@@ -2,8 +2,44 @@
2
2
  import { readFile, readdir } from "fs/promises";
3
3
  import path from "path";
4
4
  import { parseEnv } from "util";
5
- import { minimatch } from "minimatch";
5
+ import { minimatch as minimatch2 } from "minimatch";
6
6
  import { isMap, LineCounter, parseDocument, visit } from "yaml";
7
+
8
+ // src/affected-paths.ts
9
+ import { minimatch } from "minimatch";
10
+ function validAffectedGlob(pattern) {
11
+ if (!pattern.trim()) return false;
12
+ if (/^[/!]|^[A-Za-z]:|\\/u.test(pattern)) return false;
13
+ if (pattern.split("/").includes("..")) return false;
14
+ return balancedGlobDelimiters(pattern);
15
+ }
16
+ function balancedGlobDelimiters(pattern) {
17
+ const stack = [];
18
+ for (let index = 0; index < pattern.length; index++) {
19
+ const character = pattern[index];
20
+ if (character === "[") {
21
+ const closing = pattern.indexOf("]", index + 1);
22
+ if (closing < 0) return false;
23
+ index = closing;
24
+ continue;
25
+ }
26
+ if ("{(".includes(character)) stack.push(character);
27
+ const opening = { ")": "(", "}": "{" }[character];
28
+ if (opening && stack.pop() !== opening) return false;
29
+ }
30
+ return stack.length === 0;
31
+ }
32
+ function affectedPathIgnored(file, patterns) {
33
+ return patterns.some(
34
+ (pattern) => minimatch(file, pattern.endsWith("/") ? `${pattern}**` : pattern, {
35
+ dot: true,
36
+ nonegate: true,
37
+ nocomment: true
38
+ })
39
+ );
40
+ }
41
+
42
+ // src/config.ts
7
43
  var CONFIG_FILE = "sedum.config.yaml";
8
44
  var ProjectConfigError = class extends Error {
9
45
  constructor(diagnostics) {
@@ -37,6 +73,7 @@ var DEFAULT_PROVIDER_MODEL = "jev-latest";
37
73
  var allowed = {
38
74
  root: /* @__PURE__ */ new Set([
39
75
  "tests",
76
+ "affected",
40
77
  "browser",
41
78
  "viewport",
42
79
  "thresholds",
@@ -50,6 +87,7 @@ var allowed = {
50
87
  "provider"
51
88
  ]),
52
89
  tests: /* @__PURE__ */ new Set(["directory", "include", "exclude"]),
90
+ affected: /* @__PURE__ */ new Set(["ignore"]),
53
91
  viewport: /* @__PURE__ */ new Set(["width", "height"]),
54
92
  thresholds: /* @__PURE__ */ new Set(["verify", "lowConfidenceBand", "contradiction"]),
55
93
  environment: /* @__PURE__ */ new Set(["baseUrl", "variables"]),
@@ -303,6 +341,8 @@ async function findConfig(start) {
303
341
  function freeze(config) {
304
342
  Object.freeze(config.include);
305
343
  Object.freeze(config.exclude);
344
+ Object.freeze(config.affected.ignore);
345
+ Object.freeze(config.affected);
306
346
  Object.freeze(config.viewport);
307
347
  Object.freeze(config.thresholds);
308
348
  Object.freeze(config.vision);
@@ -403,6 +443,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
403
443
  );
404
444
  const maps = [
405
445
  ["tests", allowed.tests],
446
+ ["affected", allowed.affected],
406
447
  ["viewport", allowed.viewport],
407
448
  ["thresholds", allowed.thresholds],
408
449
  ["vision", allowed.vision],
@@ -443,6 +484,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
443
484
  "Use `tests: { directory: tests }`."
444
485
  );
445
486
  for (const [key, value] of [
487
+ ["affected", raw.affected],
446
488
  ["viewport", raw.viewport],
447
489
  ["thresholds", raw.thresholds],
448
490
  ["environments", raw.environments],
@@ -461,6 +503,27 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
461
503
  `Write \`${key}: {}\` and add its documented child keys.`
462
504
  );
463
505
  const viewport = object(raw.viewport) ? raw.viewport : {};
506
+ const affected = object(raw.affected) ? raw.affected : {};
507
+ const affectedIgnore = stringList(
508
+ affected.ignore,
509
+ [],
510
+ "affected.ignore",
511
+ diagnostics,
512
+ file,
513
+ counter,
514
+ node("affected.ignore")
515
+ );
516
+ if (affectedIgnore.some((glob) => !validAffectedGlob(glob)))
517
+ diagnostic(
518
+ diagnostics,
519
+ file,
520
+ counter,
521
+ node("affected.ignore"),
522
+ "affected.ignore",
523
+ "invalid_affected_glob",
524
+ "Affected ignores must be valid repository-relative POSIX globs.",
525
+ "Use patterns such as `docs/` or `**/*.lock`."
526
+ );
464
527
  const thresholds = object(raw.thresholds) ? raw.thresholds : {};
465
528
  const environments = object(raw.environments) ? raw.environments : {};
466
529
  const vision = object(raw.vision) ? raw.vision : {};
@@ -821,6 +884,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
821
884
  testDirectory,
822
885
  include,
823
886
  exclude,
887
+ affected: { ignore: affectedIgnore },
824
888
  browser,
825
889
  viewport: { width, height },
826
890
  thresholds: { minP: verify, band, contradictionCutoff },
@@ -857,7 +921,7 @@ async function discoverConfiguredTests(config) {
857
921
  if (entry.isDirectory()) await visit2(absolute);
858
922
  else if (entry.isFile()) {
859
923
  const relative = path.relative(config.testDirectory, absolute).split(path.sep).join("/");
860
- if ((relative.endsWith(".test.ts") || relative.endsWith(".test.yaml")) && config.include.some((pattern) => minimatch(relative, pattern)) && !config.exclude.some((pattern) => minimatch(relative, pattern)))
924
+ if ((relative.endsWith(".test.ts") || relative.endsWith(".test.yaml")) && config.include.some((pattern) => minimatch2(relative, pattern)) && !config.exclude.some((pattern) => minimatch2(relative, pattern)))
861
925
  files.push(absolute);
862
926
  }
863
927
  }
@@ -867,6 +931,8 @@ async function discoverConfiguredTests(config) {
867
931
  }
868
932
 
869
933
  export {
934
+ validAffectedGlob,
935
+ affectedPathIgnored,
870
936
  ProjectConfigError,
871
937
  DEFAULT_PROVIDER_BASE_URL,
872
938
  DEFAULT_PROVIDER_MODEL,
@@ -7,12 +7,13 @@ import {
7
7
  configDiagnostic,
8
8
  createCliProvider,
9
9
  renderDiagnostic
10
- } from "./chunk-NOGCXR4U.js";
10
+ } from "./chunk-S7OB3JEF.js";
11
11
  import {
12
12
  ProjectConfigError,
13
13
  discoverConfiguredTests,
14
- loadProjectConfig
15
- } from "./chunk-VNGIF7AY.js";
14
+ loadProjectConfig,
15
+ validAffectedGlob
16
+ } from "./chunk-FAGJCNV7.js";
16
17
 
17
18
  // src/invocation.ts
18
19
  function sedumCommand(env = process.env, script = process.argv[1] ?? "") {
@@ -714,6 +715,11 @@ var collectOrigin = collector(new OriginCollector());
714
715
  var collectValue = collector(new ValueCollector());
715
716
  var collectReporter = collector(new ReporterCollector());
716
717
  var collectGlob = collector(new GlobCollector());
718
+ function collectAffectedGlob(value, previous) {
719
+ if (!validAffectedGlob(value))
720
+ invalid("Affected ignore must be a valid repository-relative POSIX glob.");
721
+ return [...previous, value];
722
+ }
717
723
  var collectLabels = collector(new LabelCollector());
718
724
  var nonnegativeInteger = rangedNumber({
719
725
  minimum: 0,
@@ -790,7 +796,7 @@ async function runCli(args, version, runtime = {}) {
790
796
  const writeOut = (value) => rawOut(withCommand(value, command));
791
797
  const writeErr = (value) => rawErr(withCommand(value, command));
792
798
  const capabilities = runtime.capabilities ?? plainOutput;
793
- const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-DEWAPQML.js")).executeRunCommand(options));
799
+ const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-ZEIANJWZ.js")).executeRunCommand(options));
794
800
  const cwd = runtime.cwd ?? process.cwd();
795
801
  let exitCode = 3;
796
802
  const program = new Command2().name("sedum").description(
@@ -808,7 +814,7 @@ async function runCli(args, version, runtime = {}) {
808
814
  "after",
809
815
  "\nCreates a config, a SauceDemo example, .env.example, and ignore rules.\nExisting files are never replaced.\n"
810
816
  ).action(async () => {
811
- const { executeInitCommand } = await import("./init-command-SXAVPVX6.js");
817
+ const { executeInitCommand } = await import("./init-command-62IUO5LA.js");
812
818
  const interactive = capabilities.stdoutIsTTY && (process.stdin.isTTY === true || runtime.confirmInit !== void 0);
813
819
  const confirm = runtime.confirmInit ?? (interactive ? async (question) => {
814
820
  const { createInterface } = await import("readline/promises");
@@ -842,8 +848,13 @@ async function runCli(args, version, runtime = {}) {
842
848
  "experimental: send Git diff and test sources to the text provider; run relevant tests",
843
849
  false
844
850
  ).option("--base <ref>", "base ref for --affected (default main or master)").option(
851
+ "--affected-ignore <glob>",
852
+ "exclude matching repository-relative diff paths (repeatable)",
853
+ collectAffectedGlob,
854
+ []
855
+ ).option(
845
856
  "--threshold <probability>",
846
- "minimum relevance probability for --affected (default 0.1)",
857
+ "minimum relevance probability for --affected (default 0.3)",
847
858
  relevanceThreshold
848
859
  ).option(
849
860
  "--selection-only",
@@ -947,18 +958,18 @@ async function runCli(args, version, runtime = {}) {
947
958
  exitCode = 3;
948
959
  return;
949
960
  }
950
- if (!options.affected && (options.base !== void 0 || options.threshold !== void 0 || options.selectionOnly)) {
961
+ if (!options.affected && (options.base !== void 0 || options.affectedIgnore.length > 0 || options.threshold !== void 0 || options.selectionOnly)) {
951
962
  writeErr(
952
- "--base, --threshold, and --selection-only require --affected.\n"
963
+ "--base, --threshold, --affected-ignore, and --selection-only require --affected.\n"
953
964
  );
954
965
  exitCode = 3;
955
966
  return;
956
967
  }
957
968
  if (options.affected) {
958
- const { selectAffectedTests, AffectedSelectionError } = await import("./affected-selection-ENIH4AGP.js");
969
+ const { selectAffectedTests, AffectedSelectionError } = await import("./affected-selection-WV5WY5NQ.js");
959
970
  const { ProviderError: ProviderError2 } = await import("@sedum-dev/core");
960
971
  writeErr(
961
- "Experimental selection sends the tracked Git diff and test/module sources to the configured provider. Full CI is still recommended.\n"
972
+ "Experimental selection sends the committed Git diff and complete test/module sources to the configured provider. Tracked local edits are refused. Full CI is still recommended.\n"
962
973
  );
963
974
  try {
964
975
  const selection = await selectAffectedTests({
@@ -971,7 +982,8 @@ async function runCli(args, version, runtime = {}) {
971
982
  names: options.name,
972
983
  ids: options.id
973
984
  },
974
- threshold: options.threshold ?? 0.1,
985
+ threshold: options.threshold ?? 0.3,
986
+ ignore: options.affectedIgnore,
975
987
  ...options.base !== void 0 ? { base: options.base } : {},
976
988
  ...options.env ? { environment: options.env } : {},
977
989
  ...runtime.signal ? { signal: runtime.signal } : {},
@@ -1147,7 +1159,7 @@ No tests were run. Fix the selection error or run without --affected.
1147
1159
  "after",
1148
1160
  "\nThe authenticated API check makes one small, potentially billable request.\n\nExit codes:\n 0 all checks passed\n 3 one or more prerequisites failed\n"
1149
1161
  ).action(async (options) => {
1150
- const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-XRE6PEGU.js");
1162
+ const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-F4Y5KW36.js");
1151
1163
  const result = await executeDoctorCommand(cwd, runtime.doctorProbes, {
1152
1164
  vision: options.vision
1153
1165
  });
@@ -2,7 +2,7 @@ import {
2
2
  DEFAULT_PROVIDER_BASE_URL,
3
3
  DEFAULT_PROVIDER_MODEL,
4
4
  loadProjectConfig
5
- } from "./chunk-VNGIF7AY.js";
5
+ } from "./chunk-FAGJCNV7.js";
6
6
 
7
7
  // src/doctor-command.ts
8
8
  import { lstat, mkdir, mkdtemp, rm, rmdir, writeFile } from "fs/promises";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ProjectConfigError
3
- } from "./chunk-VNGIF7AY.js";
3
+ } from "./chunk-FAGJCNV7.js";
4
4
 
5
5
  // src/diagnostics.ts
6
6
  import { BrowserDriverError, ProviderError } from "@sedum-dev/core";
package/dist/cli.js CHANGED
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  runCli,
4
4
  sedumCommand
5
- } from "./chunk-4LEXNO2M.js";
5
+ } from "./chunk-HT6BIET2.js";
6
6
  import "./chunk-EFRMSNBD.js";
7
- import "./chunk-NOGCXR4U.js";
8
- import "./chunk-VNGIF7AY.js";
7
+ import "./chunk-S7OB3JEF.js";
8
+ import "./chunk-FAGJCNV7.js";
9
9
 
10
10
  // src/cli.ts
11
11
  import { createRequire } from "module";
@@ -5,8 +5,8 @@ import {
5
5
  keyPresent,
6
6
  renderDoctorText,
7
7
  supportedNode
8
- } from "./chunk-H4QXVVQI.js";
9
- import "./chunk-VNGIF7AY.js";
8
+ } from "./chunk-HXQDSNLL.js";
9
+ import "./chunk-FAGJCNV7.js";
10
10
  export {
11
11
  browserAvailable,
12
12
  checkOutputWritable,
package/dist/index.d.ts CHANGED
@@ -57,6 +57,9 @@ interface ResolvedProjectConfig {
57
57
  readonly testDirectory: string;
58
58
  readonly include: readonly string[];
59
59
  readonly exclude: readonly string[];
60
+ readonly affected: {
61
+ readonly ignore: readonly string[];
62
+ };
60
63
  readonly browser: BrowserKind;
61
64
  readonly viewport: {
62
65
  readonly width: number;
package/dist/index.js CHANGED
@@ -2,14 +2,14 @@ import {
2
2
  renderRunSummary,
3
3
  runCli,
4
4
  runExitCode
5
- } from "./chunk-4LEXNO2M.js";
5
+ } from "./chunk-HT6BIET2.js";
6
6
  import "./chunk-EFRMSNBD.js";
7
- import "./chunk-NOGCXR4U.js";
7
+ import "./chunk-S7OB3JEF.js";
8
8
  import {
9
9
  ProjectConfigError,
10
10
  discoverConfiguredTests,
11
11
  loadProjectConfig
12
- } from "./chunk-VNGIF7AY.js";
12
+ } from "./chunk-FAGJCNV7.js";
13
13
 
14
14
  // src/index.ts
15
15
  import { test, expect, secret } from "@sedum-dev/core/script";
@@ -2,11 +2,11 @@ import {
2
2
  browserAvailable,
3
3
  keyPresent,
4
4
  supportedNode
5
- } from "./chunk-H4QXVVQI.js";
5
+ } from "./chunk-HXQDSNLL.js";
6
6
  import {
7
7
  ProjectConfigError,
8
8
  loadProjectConfig
9
- } from "./chunk-VNGIF7AY.js";
9
+ } from "./chunk-FAGJCNV7.js";
10
10
 
11
11
  // src/init-command.ts
12
12
  import { constants } from "fs";
@@ -5,7 +5,7 @@ import {
5
5
  } from "./chunk-EFRMSNBD.js";
6
6
  import {
7
7
  discoverRunTests
8
- } from "./chunk-7M7YUTRH.js";
8
+ } from "./chunk-AWBC7NOM.js";
9
9
  import {
10
10
  canonicalDiagnosticError,
11
11
  createCliProvider,
@@ -13,20 +13,20 @@ import {
13
13
  outputDiagnostic,
14
14
  setupDiagnostic,
15
15
  stopsRun
16
- } from "./chunk-NOGCXR4U.js";
16
+ } from "./chunk-S7OB3JEF.js";
17
17
  import {
18
18
  ProjectConfigError,
19
19
  loadProjectConfig
20
- } from "./chunk-VNGIF7AY.js";
20
+ } from "./chunk-FAGJCNV7.js";
21
21
 
22
- // src/run-command-implementation.ts
22
+ // src/run-command/implementation.ts
23
23
  import {
24
24
  RejectionRouter
25
25
  } from "@sedum-dev/core";
26
26
  import { randomUUID } from "crypto";
27
27
  import path10 from "path";
28
28
 
29
- // src/run-command-discovery.ts
29
+ // src/run-command/discovery.ts
30
30
  import path from "path";
31
31
 
32
32
  // src/run-shard.ts
@@ -56,7 +56,7 @@ function shardProblems(problems, shard) {
56
56
  return problems.filter((problem) => owned.has(problem.file));
57
57
  }
58
58
 
59
- // src/run-command-discovery.ts
59
+ // src/run-command/discovery.ts
60
60
  async function discoverCommandTests(config, options, safeText2) {
61
61
  const selection = await discoverRunTests(
62
62
  config,
@@ -88,7 +88,7 @@ async function discoverCommandTests(config, options, safeText2) {
88
88
  };
89
89
  }
90
90
 
91
- // src/run-command-outcome.ts
91
+ // src/run-command/outcome.ts
92
92
  import path2 from "path";
93
93
  function interruptionConclusion(timedOut) {
94
94
  return timedOut ? {
@@ -180,7 +180,7 @@ function completedRunConclusion(operational, erroredTests, discoveryProblems) {
180
180
  return null;
181
181
  }
182
182
 
183
- // src/run-command-output.ts
183
+ // src/run-command/output.ts
184
184
  import {
185
185
  RunRecorder,
186
186
  validateRunResult as validateRunResult2
@@ -530,7 +530,7 @@ var ProgressWriter = class _ProgressWriter {
530
530
  }
531
531
  };
532
532
 
533
- // src/run-command-output.ts
533
+ // src/run-command/output.ts
534
534
  var ReporterOutputError = class extends Error {
535
535
  };
536
536
  function reportSelection(options) {
@@ -780,7 +780,7 @@ async function unavailablePreExecutionResult(runId, intended, diagnostic) {
780
780
  };
781
781
  }
782
782
 
783
- // src/run-command-session.ts
783
+ // src/run-command/session.ts
784
784
  import { RunRecorder as RunRecorder2 } from "@sedum-dev/core";
785
785
  import path6 from "path";
786
786
  async function openRunSession(request) {
@@ -988,7 +988,7 @@ var RunOutputSession = class {
988
988
  }
989
989
  };
990
990
 
991
- // src/run-command-setup.ts
991
+ // src/run-command/setup.ts
992
992
  import path7 from "path";
993
993
  var SUPPORTED_BROWSERS = /* @__PURE__ */ new Set(["chrome", "chromium"]);
994
994
  async function resolveRunConfig(invocationRoot, options) {
@@ -1068,7 +1068,7 @@ function validateVisionKey(config) {
1068
1068
  ]);
1069
1069
  }
1070
1070
 
1071
- // src/run-command-support.ts
1071
+ // src/run-command/support.ts
1072
1072
  import { safeText } from "@sedum-dev/core";
1073
1073
  import path8 from "path";
1074
1074
  function verifyGraceMs(value) {
@@ -1112,7 +1112,7 @@ function safeDiscoveryText(value, config) {
1112
1112
  );
1113
1113
  }
1114
1114
 
1115
- // src/run-command-tests.ts
1115
+ // src/run-command/tests.ts
1116
1116
  import {
1117
1117
  DEFAULT_PROVIDER_CONCURRENCY,
1118
1118
  FileClassificationCache,
@@ -1281,7 +1281,7 @@ async function handleOperationalFailure(request, slot, result, outcome) {
1281
1281
  return "complete";
1282
1282
  }
1283
1283
 
1284
- // src/run-command-implementation.ts
1284
+ // src/run-command/implementation.ts
1285
1285
  var SUPPORTED_REPORTERS = [
1286
1286
  "terminal",
1287
1287
  "json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sedum-cli",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.12",
4
4
  "description": "Plain-English browser tests on Playwright. Write steps as sentences, keep TypeScript, and run the suite on every pull request.",
5
5
  "keywords": [
6
6
  "playwright",
@@ -43,10 +43,10 @@
43
43
  "commander": "14.0.2",
44
44
  "minimatch": "10.2.6",
45
45
  "yaml": "2.9.1",
46
- "@sedum-dev/core": "0.1.0-alpha.10",
47
- "@sedum-dev/provider-clef": "0.1.0-alpha.10",
48
- "@sedum-dev/reporters": "0.1.0-alpha.10",
49
- "@sedum-dev/provider-typesafe": "0.1.0-alpha.10"
46
+ "@sedum-dev/core": "0.1.0-alpha.12",
47
+ "@sedum-dev/provider-clef": "0.1.0-alpha.12",
48
+ "@sedum-dev/provider-typesafe": "0.1.0-alpha.12",
49
+ "@sedum-dev/reporters": "0.1.0-alpha.12"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsup src/index.ts src/cli.ts --format esm --dts --clean --out-dir dist",
@@ -1,206 +0,0 @@
1
- import {
2
- discoverRunTests
3
- } from "./chunk-7M7YUTRH.js";
4
- import {
5
- createCliProvider,
6
- providerDiagnostic
7
- } from "./chunk-NOGCXR4U.js";
8
- import {
9
- loadProjectConfig
10
- } from "./chunk-VNGIF7AY.js";
11
-
12
- // src/affected-selection.ts
13
- import { execFile } from "child_process";
14
- import { readFile, realpath } from "fs/promises";
15
- import path from "path";
16
- import { promisify } from "util";
17
- import {
18
- isScriptTestFile,
19
- loadFlowFile,
20
- ProviderError,
21
- resolveFlowModules
22
- } from "@sedum-dev/core";
23
- var exec = promisify(execFile);
24
- var AffectedSelectionError = class extends Error {
25
- };
26
- async function readBranchDiff(cwd, base, signal) {
27
- const git = async (...args) => (await exec("git", args, {
28
- cwd,
29
- maxBuffer: 2 * 1024 * 1024,
30
- ...signal ? { signal } : {}
31
- })).stdout;
32
- try {
33
- const root = (await git("rev-parse", "--show-toplevel")).trim();
34
- let reference = base;
35
- if (!reference) {
36
- for (const candidate of [
37
- "refs/heads/main",
38
- "refs/remotes/origin/main",
39
- "refs/heads/master",
40
- "refs/remotes/origin/master"
41
- ]) {
42
- try {
43
- await git(
44
- "rev-parse",
45
- "--verify",
46
- "--end-of-options",
47
- `${candidate}^{commit}`
48
- );
49
- reference = candidate;
50
- break;
51
- } catch {
52
- signal?.throwIfAborted();
53
- }
54
- }
55
- }
56
- if (!reference)
57
- throw new AffectedSelectionError(
58
- "No main or master ref found. Fetch the base branch or pass --base <ref>."
59
- );
60
- const commit = (await git(
61
- "rev-parse",
62
- "--verify",
63
- "--end-of-options",
64
- `${reference}^{commit}`
65
- )).trim();
66
- const mergeBase = (await git("merge-base", commit, "HEAD")).trim();
67
- if ((await git("ls-files", "--others", "--exclude-standard", "--", ":/")).length)
68
- throw new AffectedSelectionError(
69
- "Untracked files are not represented in git diff. Stage intended files or ignore unrelated files before using --affected."
70
- );
71
- const diff = await git(
72
- "diff",
73
- "--no-ext-diff",
74
- "--no-textconv",
75
- "--no-color",
76
- "--no-renames",
77
- "--no-relative",
78
- "--ignore-submodules=none",
79
- "--submodule=short",
80
- mergeBase,
81
- "--",
82
- ":/"
83
- );
84
- if (/^Binary files .* differ$/mu.test(diff) || /^[+ -]Subproject commit /mu.test(diff))
85
- throw new AffectedSelectionError(
86
- "Binary or submodule changes cannot be scored reliably. Run the full suite without --affected."
87
- );
88
- const changed = (await git(
89
- "diff",
90
- "--no-ext-diff",
91
- "--no-textconv",
92
- "--name-only",
93
- "--no-renames",
94
- "--no-relative",
95
- "--ignore-submodules=none",
96
- "-z",
97
- mergeBase,
98
- "--",
99
- ":/"
100
- )).split("\0").filter(Boolean);
101
- return { root, base: reference, mergeBase, diff, changed };
102
- } catch (error) {
103
- if (error instanceof AffectedSelectionError) throw error;
104
- throw new AffectedSelectionError(
105
- "Could not read a complete Git diff. Check the base ref and merge-base history (fetch deeper for shallow clones), or run without --affected."
106
- );
107
- }
108
- }
109
- async function selectAffectedTests(options) {
110
- const config = await loadProjectConfig(options.cwd, process.env, {
111
- ...options.environment ? { environment: options.environment } : {}
112
- });
113
- const canonicalProjectRoot = await realpath(config.projectRoot);
114
- const selection = await discoverRunTests(
115
- config,
116
- options.paths,
117
- options.filters
118
- );
119
- if (selection.invalid.length || selection.problems.length || !selection.tests.length)
120
- throw new AffectedSelectionError(
121
- "Test discovery is empty or invalid. Run sedum validate and fix discovery before using --affected."
122
- );
123
- const branch = await readBranchDiff(
124
- config.projectRoot,
125
- options.base,
126
- options.signal
127
- );
128
- const changed = new Set(
129
- branch.changed.map((file) => path.resolve(branch.root, file))
130
- );
131
- for (const file of [...changed])
132
- changed.add(await realpath(file).catch(() => file));
133
- const tests = [];
134
- const forced = [];
135
- for (const test of selection.tests) {
136
- const file = path.join(config.projectRoot, test.file);
137
- if (isScriptTestFile(file)) {
138
- if (tests.some((scored) => scored.file === test.file)) continue;
139
- forced.push(changed.has(await realpath(file)));
140
- tests.push({
141
- file: test.file,
142
- source: await readFile(file, "utf8"),
143
- modules: []
144
- });
145
- continue;
146
- }
147
- const parsed = await loadFlowFile(file, {
148
- repoRoot: config.projectRoot,
149
- rejectSymlinks: true
150
- });
151
- const resolved = await resolveFlowModules(parsed, {
152
- repoRoot: config.projectRoot
153
- });
154
- if (!resolved.value || resolved.diagnostics.some((item) => item.severity === "error"))
155
- throw new AffectedSelectionError(
156
- "A test or module is invalid. Run sedum validate before using --affected."
157
- );
158
- const files = [await realpath(file), ...resolved.moduleFiles];
159
- forced.push(files.some((source) => changed.has(source)));
160
- tests.push({
161
- file: test.file,
162
- source: await readFile(file, "utf8"),
163
- modules: await Promise.all(
164
- resolved.moduleFiles.map(async (module) => ({
165
- file: path.relative(canonicalProjectRoot, module).split(path.sep).join("/"),
166
- source: await readFile(module, "utf8")
167
- }))
168
- )
169
- });
170
- }
171
- options.signal?.throwIfAborted();
172
- let scores;
173
- try {
174
- scores = branch.diff ? await (options.createProvider ? await options.createProvider(config) : await createCliProvider(config)).scoreRelevance(
175
- branch.diff,
176
- tests,
177
- options.signal ? { signal: options.signal } : void 0
178
- ) : { probabilities: tests.map(() => 0), calls: [] };
179
- } catch (error) {
180
- if (error instanceof ProviderError && (error.code === "authentication" || error.code === "configuration")) {
181
- const diagnostic = providerDiagnostic(config.providerName, error.code);
182
- throw new AffectedSelectionError(
183
- `${diagnostic.message}
184
- Fix: ${diagnostic.fix}`
185
- );
186
- }
187
- throw error;
188
- }
189
- return {
190
- base: branch.base,
191
- mergeBase: branch.mergeBase,
192
- threshold: options.threshold,
193
- calls: scores.calls,
194
- tests: tests.map((test, index) => ({
195
- file: test.file,
196
- probability: scores.probabilities[index],
197
- selected: branch.diff !== "" && (forced[index] || scores.probabilities[index] >= options.threshold),
198
- reason: forced[index] ? "test-or-module-changed" : branch.diff ? "model" : "no-diff"
199
- }))
200
- };
201
- }
202
- export {
203
- AffectedSelectionError,
204
- readBranchDiff,
205
- selectAffectedTests
206
- };