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

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.
@@ -1,15 +1,17 @@
1
1
  import {
2
2
  discoverRunTests
3
- } from "./chunk-AWBC7NOM.js";
3
+ } from "./chunk-ZAACPFCW.js";
4
+ import {
5
+ createCliProvider
6
+ } from "./chunk-N5CTUO2A.js";
4
7
  import {
5
- createCliProvider,
6
8
  providerDiagnostic
7
- } from "./chunk-S7OB3JEF.js";
9
+ } from "./chunk-GJ5QI7JQ.js";
8
10
  import {
9
11
  affectedPathIgnored,
10
12
  loadProjectConfig,
11
13
  validAffectedGlob
12
- } from "./chunk-FAGJCNV7.js";
14
+ } from "./chunk-OKZ6VJKA.js";
13
15
 
14
16
  // src/affected-selection.ts
15
17
  import { realpath } from "fs/promises";
@@ -355,7 +357,7 @@ async function selectAffectedTests(options) {
355
357
  ) : { probabilities: candidates.map(() => 0), calls: [], chunkCount: 0 };
356
358
  } catch (error) {
357
359
  if (error instanceof ProviderError && (error.code === "authentication" || error.code === "configuration")) {
358
- const diagnostic = providerDiagnostic(config.providerName, error.code);
360
+ const diagnostic = providerDiagnostic(config, error.code);
359
361
  throw new AffectedSelectionError(
360
362
  `${diagnostic.message}
361
363
  Fix: ${diagnostic.fix}`
@@ -1,19 +1,28 @@
1
+ import {
2
+ collectText,
3
+ exploreMode,
4
+ seedValue,
5
+ startUrl,
6
+ watchOrigin
7
+ } from "./chunk-ACDJLEMS.js";
1
8
  import {
2
9
  MAX_PARALLEL,
3
10
  clearLocatorCache,
4
11
  parseParallel
5
12
  } from "./chunk-EFRMSNBD.js";
13
+ import {
14
+ createCliProvider
15
+ } from "./chunk-N5CTUO2A.js";
6
16
  import {
7
17
  configDiagnostic,
8
- createCliProvider,
9
18
  renderDiagnostic
10
- } from "./chunk-S7OB3JEF.js";
19
+ } from "./chunk-GJ5QI7JQ.js";
11
20
  import {
12
21
  ProjectConfigError,
13
22
  discoverConfiguredTests,
14
23
  loadProjectConfig,
15
24
  validAffectedGlob
16
- } from "./chunk-FAGJCNV7.js";
25
+ } from "./chunk-OKZ6VJKA.js";
17
26
 
18
27
  // src/invocation.ts
19
28
  function sedumCommand(env = process.env, script = process.argv[1] ?? "") {
@@ -125,15 +134,9 @@ function visionExecutionLines(value, steps) {
125
134
  const attempts = steps.flatMap(
126
135
  (step) => step.locator?.vision ? [step.locator.vision] : []
127
136
  );
128
- const warnings = {
129
- accepted: null,
130
- rejected: "vision warning: OpenRouter rejected OPEN_ROUTER_API_KEY, so vision fallback cannot work. Check it with `sedum doctor --vision`.",
131
- unreachable: "vision warning: OpenRouter could not be reached to check OPEN_ROUTER_API_KEY."
132
- };
133
137
  return compact([
134
138
  visionOutcomeLine(vision.model, attempts),
135
- failedClickVisionLine(steps),
136
- warnings[vision.key]
139
+ failedClickVisionLine(steps)
137
140
  ]);
138
141
  }
139
142
  function rateLimitLine(value) {
@@ -168,6 +171,16 @@ function cacheLine(step) {
168
171
  const changed = cache.targetChanged ? ", target changed" : "";
169
172
  return ` step ${step.index}: cache ${cache.outcome}${reason}${fallback}${changed}`;
170
173
  }
174
+ function detectionLines(step) {
175
+ return (step.detections ?? []).map(
176
+ (detection) => ` step ${step.index}: suspected bug, ${detection.check}${detection.source ? ` (${detection.source}${detection.probability === void 0 ? "" : ` p=${detection.probability.toFixed(2)}`})` : ""}: ${detection.message}`.replace(
177
+ // Page text and URLs must not move the terminal cursor.
178
+ // eslint-disable-next-line no-control-regex
179
+ /[\u0000-\u001f\u007f-\u009f]/g,
180
+ " "
181
+ )
182
+ );
183
+ }
171
184
  function testDetailLines(test, flagCounts) {
172
185
  const retry = test.attempts.length > 1 ? ` attempts ${test.attempts.length} (${test.attempts.map((attempt) => attempt.verdict ?? attempt.state).join(" -> ")})` : null;
173
186
  const selected = test.attempts.find(
@@ -176,7 +189,7 @@ function testDetailLines(test, flagCounts) {
176
189
  const caches = (selected?.steps ?? []).flatMap((step) => {
177
190
  for (const flag of step.flags) flagCounts[flag] += 1;
178
191
  const line = cacheLine(step);
179
- return line ? [line] : [];
192
+ return [...line ? [line] : [], ...detectionLines(step)];
180
193
  });
181
194
  const details = [...compact([retry]), ...caches];
182
195
  return details.length ? [testLabel(test), ...details] : [];
@@ -199,7 +212,8 @@ function flagCountLine(value, counts) {
199
212
  const flaky = value.tests.filter(
200
213
  (test) => test.flags.includes("flaky")
201
214
  ).length;
202
- return `flags ${value.totals.flaggedSteps} flagged step(s), low_confidence ${counts.low_confidence}, contradiction ${counts.contradiction}, flaky ${flaky} test(s)`;
215
+ const suspected = counts.suspected_bug ? `, suspected_bug ${counts.suspected_bug}` : "";
216
+ return `flags ${value.totals.flaggedSteps} flagged step(s), low_confidence ${counts.low_confidence}, contradiction ${counts.contradiction}${suspected}, flaky ${flaky} test(s)`;
203
217
  }
204
218
  function visionDetailLines(value) {
205
219
  return value.tests.flatMap(
@@ -238,7 +252,7 @@ function renderRunSummary(result, capabilities, artifacts, showCosts) {
238
252
  const value = validateRunResult2(result);
239
253
  const color = capabilities.stdoutIsTTY && capabilities.color;
240
254
  const lines = [];
241
- const flagCounts = { low_confidence: 0, contradiction: 0 };
255
+ const flagCounts = { low_confidence: 0, contradiction: 0, suspected_bug: 0 };
242
256
  for (const test of value.tests)
243
257
  lines.push(...testDetailLines(test, flagCounts));
244
258
  if (hasOutsideGitStep(value))
@@ -396,20 +410,24 @@ function emptyProjectProblem(paths, testDirectory) {
396
410
  fix: paths.length ? "Pass paths relative to the project root that contain tests or modules." : "Add tests under tests.directory, or correct tests.directory/include/exclude in sedum.config.yaml."
397
411
  };
398
412
  }
399
- var missingKey = {
400
- code: "missing_key",
401
- message: "`sedum validate --online` needs a configured model provider.",
402
- fix: "Set the selected provider's credentials (TYPESAFE_API_KEY, or CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN/CLOUDFLARE_API_TOKEN) and rerun; otherwise omit --online."
403
- };
413
+ function missingKey(config) {
414
+ const credentials = config?.apiKeyEnv ? `${config.apiKeyEnv}${config.providerName === "clef" ? " and CLOUDFLARE_ACCOUNT_ID" : ""}` : "the selected provider's credentials (TYPESAFE_API_KEY, OPENROUTER_API_KEY, or CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN/CLOUDFLARE_API_TOKEN)";
415
+ return {
416
+ code: "missing_key",
417
+ message: "`sedum validate --online` needs a configured model provider.",
418
+ fix: `Set ${credentials} and rerun; otherwise omit --online.`
419
+ };
420
+ }
404
421
  async function onlineProvider(options) {
422
+ let config;
405
423
  try {
406
- const config = await loadProjectConfig(options.cwd);
424
+ config = await loadProjectConfig(options.cwd);
407
425
  return {
408
426
  provider: await options.createProvider({
409
427
  ...config.apiKey ? { apiKey: config.apiKey } : {},
410
428
  baseURL: config.providerBaseUrl,
411
429
  model: config.providerModel,
412
- ...config.providerName === "clef" ? {
430
+ ...config.providerName !== "typesafe" ? {
413
431
  providerName: config.providerName,
414
432
  ...config.cloudflareAccountId ? { accountId: config.cloudflareAccountId } : {}
415
433
  } : {}
@@ -419,7 +437,7 @@ async function onlineProvider(options) {
419
437
  } catch (error) {
420
438
  if (error instanceof ProjectConfigError) return configDiagnostic(error);
421
439
  if (error instanceof ProviderError && error.code === "configuration")
422
- return missingKey;
440
+ return missingKey(config);
423
441
  return {
424
442
  code: "setup_error",
425
443
  message: "The classification provider could not be prepared.",
@@ -597,6 +615,7 @@ function renderListJson(listing) {
597
615
 
598
616
  // src/cli-arguments.ts
599
617
  import { InvalidArgumentError } from "commander";
618
+ import { parseAllowRule } from "@sedum-dev/core";
600
619
  var RawOptionText = class {
601
620
  constructor(value) {
602
621
  this.value = value;
@@ -649,6 +668,45 @@ var ValueCollector = class {
649
668
  return [...previous, text.value];
650
669
  }
651
670
  };
671
+ var AllowRuleCollector = class {
672
+ parse(text, previous) {
673
+ try {
674
+ parseAllowRule(text.value);
675
+ } catch (error) {
676
+ invalid(
677
+ `Invalid allow rule ${JSON.stringify(text.value)}: ${error instanceof Error ? error.message : String(error)}`
678
+ );
679
+ }
680
+ return [...previous, text.value];
681
+ }
682
+ };
683
+ var DETECT_MODES = ["off", "browser", "semantic"];
684
+ var DetectModeParser = class {
685
+ parse(text) {
686
+ const mode = DETECT_MODES.find((item) => item === text.trimmed);
687
+ return mode ?? invalid(
688
+ `Unknown detector mode ${JSON.stringify(text.value)}. Use off, browser, or semantic.`
689
+ );
690
+ }
691
+ };
692
+ var EXPLORE_DETECT_MODES = ["browser", "semantic"];
693
+ var ExploreDetectParser = class {
694
+ parse(text) {
695
+ const mode = EXPLORE_DETECT_MODES.find((item) => item === text.trimmed);
696
+ return mode ?? invalid(
697
+ `Unknown detector mode ${JSON.stringify(text.value)}. Use browser or semantic.`
698
+ );
699
+ }
700
+ };
701
+ var EXPLORE_SAFE_MODES = ["on", "strict"];
702
+ var ExploreSafeParser = class {
703
+ parse(text) {
704
+ const mode = EXPLORE_SAFE_MODES.find((item) => item === text.trimmed);
705
+ return mode ?? invalid(
706
+ `Unknown safety mode ${JSON.stringify(text.value)}. Use --safe or --safe strict.`
707
+ );
708
+ }
709
+ };
652
710
  var REPORTERS = ["list", "steps", "terminal", "json", "markdown", "junit"];
653
711
  var ReporterCollector = class {
654
712
  parse(text, previous) {
@@ -713,6 +771,10 @@ function rangedNumber(range) {
713
771
  }
714
772
  var collectOrigin = collector(new OriginCollector());
715
773
  var collectValue = collector(new ValueCollector());
774
+ var collectAllowRule = collector(new AllowRuleCollector());
775
+ var detectMode = scalar(new DetectModeParser());
776
+ var exploreDetect = scalar(new ExploreDetectParser());
777
+ var exploreSafe = scalar(new ExploreSafeParser());
716
778
  var collectReporter = collector(new ReporterCollector());
717
779
  var collectGlob = collector(new GlobCollector());
718
780
  function collectAffectedGlob(value, previous) {
@@ -796,7 +858,7 @@ async function runCli(args, version, runtime = {}) {
796
858
  const writeOut = (value) => rawOut(withCommand(value, command));
797
859
  const writeErr = (value) => rawErr(withCommand(value, command));
798
860
  const capabilities = runtime.capabilities ?? plainOutput;
799
- const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-ZEIANJWZ.js")).executeRunCommand(options));
861
+ const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-EVUWZI4F.js")).executeRunCommand(options));
800
862
  const cwd = runtime.cwd ?? process.cwd();
801
863
  let exitCode = 3;
802
864
  const program = new Command2().name("sedum").description(
@@ -814,7 +876,7 @@ async function runCli(args, version, runtime = {}) {
814
876
  "after",
815
877
  "\nCreates a config, a SauceDemo example, .env.example, and ignore rules.\nExisting files are never replaced.\n"
816
878
  ).action(async () => {
817
- const { executeInitCommand } = await import("./init-command-62IUO5LA.js");
879
+ const { executeInitCommand } = await import("./init-command-DEEVMROG.js");
818
880
  const interactive = capabilities.stdoutIsTTY && (process.stdin.isTTY === true || runtime.confirmInit !== void 0);
819
881
  const confirm = runtime.confirmInit ?? (interactive ? async (question) => {
820
882
  const { createInterface } = await import("readline/promises");
@@ -885,7 +947,10 @@ async function runCli(args, version, runtime = {}) {
885
947
  "select a test by its exact id (repeatable)",
886
948
  collectValue,
887
949
  []
888
- ).option("--env <name>", "select a named environment").option("--browser <kind>", "chrome or chromium").option("--vision", "enable vision fallback for ambiguous clicks").option("--no-vision", "disable vision fallback").option("--vision-model <model>", "override the OpenRouter vision model").option(
950
+ ).option("--env <name>", "select a named environment").option("--browser <kind>", "chrome or chromium").option("--vision", "enable vision fallback for ambiguous clicks").option("--no-vision", "disable vision fallback").option(
951
+ "--screenshots",
952
+ "send screenshots to TypeSafe to check targets and judge claims (default for the TypeSafe API)"
953
+ ).option("--no-screenshots", "send page text only, never screenshots").option(
889
954
  "--url-override <url>",
890
955
  "replace entry URL origin for preview deployments"
891
956
  ).option("--output-dir <path>", "run output directory").option("--reporter-dir <path>", "reporter artifact directory").option("--headed", "show the browser", false).option(
@@ -922,6 +987,15 @@ async function runCli(args, version, runtime = {}) {
922
987
  "omit sensitive page details and frames (repeatable)",
923
988
  collectOrigin,
924
989
  []
990
+ ).option(
991
+ "--detect <mode>",
992
+ "flag steps whose page reported console errors, uncaught exceptions, unhandled rejections, or HTTP errors: off, browser, or semantic (also asks Jev whether each new page looks broken)",
993
+ detectMode
994
+ ).option(
995
+ "--detect-allow <rule>",
996
+ "ignore a known detector finding: [check:]substring or [check:]re:regex (repeatable)",
997
+ collectAllowRule,
998
+ []
925
999
  ).option("--strict", "exit 2 when a passed run has uncertainty flags", false).option(
926
1000
  "--reporter <name>",
927
1001
  "reporter: list, steps, terminal, json, markdown, or junit (repeatable or comma-separated; default list)",
@@ -933,7 +1007,7 @@ async function runCli(args, version, runtime = {}) {
933
1007
  false
934
1008
  ).addHelpText(
935
1009
  "after",
936
- "\nPrerequisites:\n Install Chromium with `sedum browsers install chromium` and set TYPESAFE_API_KEY (and TYPESAFE_BASE_URL for a compatible provider).\n\nExamples:\n sedum run tests/login.test.ts\n sedum run tests/login.test.ts --id 'tests/login.test.ts#signs in'\n sedum run tests/login.test.yaml --strict --costs\n"
1010
+ "\nPrerequisites:\n Install Chromium with `sedum browsers install chromium` and configure the selected provider's credentials. TypeSafe uses TYPESAFE_API_KEY (and TYPESAFE_BASE_URL for a compatible gateway); OpenRouter uses OPENROUTER_API_KEY; Clef uses CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_AUTH_TOKEN.\n\nExamples:\n sedum run tests/login.test.ts\n sedum run tests/login.test.ts --id 'tests/login.test.ts#signs in'\n sedum run tests/login.test.yaml --strict --costs\n"
937
1011
  ).action(
938
1012
  async (paths, options) => {
939
1013
  if (options.shardIndex === void 0 !== (options.shardCount === void 0) || options.shardIndex !== void 0 && options.shardIndex > options.shardCount) {
@@ -966,7 +1040,7 @@ async function runCli(args, version, runtime = {}) {
966
1040
  return;
967
1041
  }
968
1042
  if (options.affected) {
969
- const { selectAffectedTests, AffectedSelectionError } = await import("./affected-selection-WV5WY5NQ.js");
1043
+ const { selectAffectedTests, AffectedSelectionError } = await import("./affected-selection-KRK5HRF4.js");
970
1044
  const { ProviderError: ProviderError2 } = await import("@sedum-dev/core");
971
1045
  writeErr(
972
1046
  "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"
@@ -1069,12 +1143,14 @@ No tests were run. Fix the selection error or run without --affected.
1069
1143
  ...options.env ? { environment: options.env } : {},
1070
1144
  ...options.browser ? { browser: options.browser } : {},
1071
1145
  ...options.vision !== void 0 ? { vision: options.vision } : {},
1072
- ...options.visionModel !== void 0 ? { visionModel: options.visionModel } : {},
1146
+ ...options.screenshots !== void 0 ? { screenshots: options.screenshots } : {},
1073
1147
  ...options.urlOverride ? { urlOverride: options.urlOverride } : {},
1074
1148
  ...options.outputDir ? { outputDir: options.outputDir } : {},
1075
1149
  ...options.reporterDir ? { reporterDir: options.reporterDir } : {},
1076
1150
  reporters: options.reporter,
1077
1151
  strict: options.strict,
1152
+ ...options.detect ? { detect: options.detect } : {},
1153
+ detectAllow: options.detectAllow,
1078
1154
  headed: options.headed,
1079
1155
  ...options.slow !== void 0 ? { slowMoMs: options.slow } : {},
1080
1156
  retries: options.retries,
@@ -1142,6 +1218,84 @@ No tests were run. Fix the selection error or run without --affected.
1142
1218
  exitCode = runExitCode(execution.result, options.strict);
1143
1219
  }
1144
1220
  );
1221
+ program.command("explore").description(
1222
+ "explore a site by a seeded random walk guided by Jev (experimental)"
1223
+ ).argument(
1224
+ "[url]",
1225
+ "absolute start URL; the walk stays on its origin",
1226
+ startUrl
1227
+ ).option("--steps <count>", "actions to take", positiveCount(1e4), 100).option(
1228
+ "--seed <seed>",
1229
+ "seed for a reproducible walk (default: random)",
1230
+ seedValue
1231
+ ).option(
1232
+ "--mode <mode>",
1233
+ "guided (Jev), heuristic (no model) or random (blind walk)",
1234
+ exploreMode,
1235
+ "guided"
1236
+ ).option(
1237
+ "--out <dir>",
1238
+ "directory for traces and emitted tests",
1239
+ ".sedum/explore"
1240
+ ).option(
1241
+ "--shrink",
1242
+ "shrink each failure and write it as a plain-English test",
1243
+ false
1244
+ ).option(
1245
+ "--rerun <trace>",
1246
+ "run a recorded trace.jsonl again instead of exploring"
1247
+ ).option(
1248
+ "--replay",
1249
+ "capture a frame per step and embed them in report.html",
1250
+ false
1251
+ ).option(
1252
+ "--sensitive-origin <url>",
1253
+ "capture no frames on this origin (repeatable)",
1254
+ collectOrigin,
1255
+ []
1256
+ ).option(
1257
+ "--safe [mode]",
1258
+ "skip targets Jev judges destructive and leave settings forms alone; strict also skips names like delete, send or pay. Off by default: only log-out and account-closing targets are skipped",
1259
+ exploreSafe
1260
+ ).option(
1261
+ "--watch-origin <origin>",
1262
+ "also report HTTP 5xx from this origin, such as an API host (repeatable)",
1263
+ watchOrigin,
1264
+ []
1265
+ ).option(
1266
+ "--ignore-console <regex>",
1267
+ "ignore console errors matching this regular expression (repeatable)",
1268
+ collectText,
1269
+ []
1270
+ ).option(
1271
+ "--detect <mode>",
1272
+ "browser (console errors, exceptions, rejections, failed requests; always on) or semantic (also asks Jev whether each new page looks broken, in the same call; guided mode)",
1273
+ exploreDetect,
1274
+ "browser"
1275
+ ).option(
1276
+ "--detect-allow <rule>",
1277
+ "ignore a known finding: [check:]substring or [check:]re:regex (repeatable)",
1278
+ collectAllowRule,
1279
+ []
1280
+ ).option(
1281
+ "--cookies <storage-state.json>",
1282
+ "sign the browser in with the cookies of a Playwright storage-state file"
1283
+ ).option(
1284
+ "--rejected-submits",
1285
+ "also report a 4xx answer to a form submission: the UI let you send something the server refuses",
1286
+ false
1287
+ ).option("--headed", "show the browser", false).addHelpText(
1288
+ "after",
1289
+ "\nGuided mode and --shrink make billable TypeSafe calls (TYPESAFE_API_KEY).\nSafety is off by default, for disposable staging: exploration clicks real buttons\nand completes forms. Use --safe on shared or production-like data.\n\nWrites trace.jsonl, result.json, report.md and report.html into --out/<run-id>/.\n\nExamples:\n sedum explore https://staging.example.com --steps 200 --seed 7 --replay\n sedum explore https://staging.example.com --safe --shrink\n sedum explore --rerun .sedum/explore/<run>/trace.jsonl\n\nExit codes:\n 0 no failures observed\n 1 console errors, page exceptions or HTTP 5xx observed\n 3 command or operational error\n"
1290
+ ).action(async (url, options) => {
1291
+ const { exploreAction } = await import("./explore-command-NRRJADY4.js");
1292
+ exitCode = await exploreAction(url, options, {
1293
+ cwd,
1294
+ write: writeOut,
1295
+ writeErr,
1296
+ ...runtime.signal ? { signal: runtime.signal } : {}
1297
+ });
1298
+ });
1145
1299
  const cache = program.command("cache").description("manage the local locator cache");
1146
1300
  cache.action(() => commandHelp(cache, writeErr));
1147
1301
  cache.command("clear").description("remove the current worktree's locator cache and digest key").action(async () => {
@@ -1151,18 +1305,16 @@ No tests were run. Fix the selection error or run without --affected.
1151
1305
  );
1152
1306
  exitCode = 0;
1153
1307
  });
1154
- program.command("doctor").description("check whether this environment can run Sedum").option("--json", "print versioned JSON checks on stdout", false).option(
1155
- "--vision",
1156
- "also check the vision fallback's OPEN_ROUTER_API_KEY (automatic when vision.enabled is true)",
1157
- false
1158
- ).addHelpText(
1308
+ program.command("doctor").description("check whether this environment can run Sedum").option("--env <name>", "select a named environment").option("--json", "print versioned JSON checks on stdout", false).addHelpText(
1159
1309
  "after",
1160
1310
  "\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"
1161
1311
  ).action(async (options) => {
1162
- const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-F4Y5KW36.js");
1163
- const result = await executeDoctorCommand(cwd, runtime.doctorProbes, {
1164
- vision: options.vision
1165
- });
1312
+ const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-KIGPIDQA.js");
1313
+ const result = await executeDoctorCommand(
1314
+ cwd,
1315
+ runtime.doctorProbes,
1316
+ options.env ? { environment: options.env } : {}
1317
+ );
1166
1318
  writeOut(
1167
1319
  options.json ? `${JSON.stringify(result)}
1168
1320
  ` : renderDoctorText(result)