sedum-cli 0.1.0-alpha.0 → 0.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/affected-selection-5YF7ZHKG.js +182 -0
- package/dist/{chunk-BEV24G7S.js → chunk-72CYPRWT.js} +4 -4
- package/dist/{chunk-OB6ZUJ6X.js → chunk-UACA6VAM.js} +25 -18
- package/dist/chunk-UVCFRFDV.js +136 -0
- package/dist/{chunk-TU5MIKGA.js → chunk-V4JF5CPE.js} +135 -18
- package/dist/{chunk-TZGSCV23.js → chunk-W2BEUHUB.js} +98 -10
- package/dist/cli.js +3 -3
- package/dist/{doctor-command-2PMOA32Y.js → doctor-command-EU5OJJ5P.js} +2 -2
- package/dist/index.d.ts +25 -3
- package/dist/index.js +3 -3
- package/dist/{init-command-54R2FQ2U.js → init-command-4RYOB737.js} +6 -4
- package/dist/{run-command-VAVFPCWG.js → run-command-SUPJIEY5.js} +58 -157
- package/package.json +4 -4
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
clearLocatorCache,
|
|
4
4
|
parseParallel,
|
|
5
5
|
renderDiagnostic
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-72CYPRWT.js";
|
|
7
7
|
import {
|
|
8
8
|
ProjectConfigError,
|
|
9
9
|
discoverConfiguredTests,
|
|
10
10
|
loadProjectConfig
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-W2BEUHUB.js";
|
|
12
12
|
|
|
13
13
|
// src/exit-policy.ts
|
|
14
14
|
import {
|
|
@@ -33,6 +33,7 @@ function listExitCode(listing, failedBeforeListing) {
|
|
|
33
33
|
|
|
34
34
|
// src/output.ts
|
|
35
35
|
import { validateRunResult as validateRunResult2 } from "@sedum-dev/core";
|
|
36
|
+
import { usageLines, visionSummary } from "@sedum-dev/reporters";
|
|
36
37
|
var ansi = {
|
|
37
38
|
green: "\x1B[32m",
|
|
38
39
|
red: "\x1B[31m",
|
|
@@ -128,6 +129,20 @@ function renderRunSummary(result, capabilities, artifacts, showCosts) {
|
|
|
128
129
|
`flags ${value.totals.flaggedSteps} flagged step(s), low_confidence ${flagCounts.low_confidence}, contradiction ${flagCounts.contradiction}`
|
|
129
130
|
);
|
|
130
131
|
lines.push(...executionLines(value));
|
|
132
|
+
for (const test of value.tests)
|
|
133
|
+
for (const attempt of test.attempts)
|
|
134
|
+
for (const step of attempt.steps) {
|
|
135
|
+
const vision = visionSummary(step);
|
|
136
|
+
if (vision)
|
|
137
|
+
lines.push(
|
|
138
|
+
`${test.file} \xB7 attempt ${attempt.ordinal} \xB7 step ${step.index}: ${vision}`.replace(
|
|
139
|
+
// Strip terminal control characters from provider metadata.
|
|
140
|
+
// eslint-disable-next-line no-control-regex
|
|
141
|
+
/[\u0000-\u001f\u007f-\u009f]/g,
|
|
142
|
+
" "
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
131
146
|
if (artifacts.authoritative) {
|
|
132
147
|
lines.push(`progress ${artifacts.progressPath}`);
|
|
133
148
|
lines.push(`result ${artifacts.resultPath}`);
|
|
@@ -141,6 +156,7 @@ function renderRunSummary(result, capabilities, artifacts, showCosts) {
|
|
|
141
156
|
lines.push(`result unavailable (intended ${artifacts.resultPath})`);
|
|
142
157
|
}
|
|
143
158
|
if (capabilities.stdoutIsTTY || showCosts) {
|
|
159
|
+
lines.push(...usageLines(value));
|
|
144
160
|
lines.push(
|
|
145
161
|
`model ${value.totals.modelCalls} call(s), ${value.totals.inputTokens} input tokens, ${value.totals.outputTokens} output tokens`
|
|
146
162
|
);
|
|
@@ -285,12 +301,13 @@ import {
|
|
|
285
301
|
validateProject
|
|
286
302
|
} from "@sedum-dev/core";
|
|
287
303
|
import path2 from "path";
|
|
288
|
-
var CLASSIFICATION_MODEL = "jev-latest";
|
|
289
304
|
var createTypeSafeClassifier = async ({
|
|
290
|
-
apiKey
|
|
305
|
+
apiKey,
|
|
306
|
+
baseURL,
|
|
307
|
+
model
|
|
291
308
|
}) => {
|
|
292
309
|
const { TypeSafeAdapter } = await import("@sedum-dev/provider-typesafe");
|
|
293
|
-
return new TypeSafeAdapter(apiKey ? { apiKey } : {});
|
|
310
|
+
return new TypeSafeAdapter({ ...apiKey ? { apiKey } : {}, baseURL, model });
|
|
294
311
|
};
|
|
295
312
|
function emptyProjectProblem(paths, testDirectory) {
|
|
296
313
|
const shown = paths.length ? paths.join(", ") : testDirectory || ".";
|
|
@@ -303,13 +320,20 @@ function emptyProjectProblem(paths, testDirectory) {
|
|
|
303
320
|
}
|
|
304
321
|
var missingKey = {
|
|
305
322
|
code: "missing_key",
|
|
306
|
-
message: "`sedum validate --online` needs a configured
|
|
307
|
-
fix: "Set TYPESAFE_API_KEY
|
|
323
|
+
message: "`sedum validate --online` needs a configured model provider.",
|
|
324
|
+
fix: "Set TYPESAFE_API_KEY for the configured endpoint and rerun; otherwise omit --online."
|
|
308
325
|
};
|
|
309
326
|
async function onlineProvider(options) {
|
|
310
327
|
try {
|
|
311
|
-
const
|
|
312
|
-
return
|
|
328
|
+
const config = await loadProjectConfig(options.cwd);
|
|
329
|
+
return {
|
|
330
|
+
provider: await options.createProvider({
|
|
331
|
+
...config.apiKey ? { apiKey: config.apiKey } : {},
|
|
332
|
+
baseURL: config.providerBaseUrl,
|
|
333
|
+
model: config.providerModel
|
|
334
|
+
}),
|
|
335
|
+
model: config.providerModel
|
|
336
|
+
};
|
|
313
337
|
} catch (error) {
|
|
314
338
|
if (error instanceof ProviderError && error.code === "configuration")
|
|
315
339
|
return missingKey;
|
|
@@ -351,14 +375,16 @@ async function executeValidateCommand(options) {
|
|
|
351
375
|
null
|
|
352
376
|
);
|
|
353
377
|
let provider;
|
|
378
|
+
let classificationModel = config.providerModel;
|
|
354
379
|
if (options.online) {
|
|
355
380
|
const prepared = await onlineProvider(options);
|
|
356
381
|
if ("code" in prepared) return stop(discovery, prepared);
|
|
357
|
-
provider = prepared;
|
|
382
|
+
provider = prepared.provider;
|
|
383
|
+
classificationModel = prepared.model;
|
|
358
384
|
}
|
|
359
385
|
const cache = await FileClassificationCache.load(
|
|
360
386
|
path2.join(discovery.root, ".sedum", "classifications.json"),
|
|
361
|
-
|
|
387
|
+
classificationModel
|
|
362
388
|
);
|
|
363
389
|
const result = await validateProject(discovery, {
|
|
364
390
|
repoRoot: discovery.root,
|
|
@@ -393,7 +419,7 @@ function renderValidation(result, root, capabilities) {
|
|
|
393
419
|
for (const item of result.diagnostics) {
|
|
394
420
|
const where = `${displayPath(root, item.source.file)}:${item.source.line}:${item.source.col}`;
|
|
395
421
|
const label = item.severity === "warning" ? paint2(`warning ${item.code}`, "yellow", capabilities) : item.code === NOT_CHECKED_OFFLINE_CODE ? paint2("not checked offline", "yellow", capabilities) : paint2(`error ${item.code}`, "red", capabilities);
|
|
396
|
-
const fix = item.code === NOT_CHECKED_OFFLINE_CODE ? "Rephrase with a supported verb, or run `sedum validate --online` with
|
|
422
|
+
const fix = item.code === NOT_CHECKED_OFFLINE_CODE ? "Rephrase with a supported verb, or run `sedum validate --online` with a provider API key configured and commit .sedum/classifications.json." : item.fix;
|
|
397
423
|
lines.push(`${where}: ${label}: ${item.message}`, ` Fix: ${fix}`);
|
|
398
424
|
}
|
|
399
425
|
const { counts } = result;
|
|
@@ -562,6 +588,12 @@ function positiveMinutes(value) {
|
|
|
562
588
|
);
|
|
563
589
|
return number;
|
|
564
590
|
}
|
|
591
|
+
function relevanceThreshold(value) {
|
|
592
|
+
const number = Number(value);
|
|
593
|
+
if (!value.trim() || !Number.isFinite(number) || number < 0 || number > 1)
|
|
594
|
+
throw new InvalidArgumentError("Expected a probability from 0 to 1.");
|
|
595
|
+
return number;
|
|
596
|
+
}
|
|
565
597
|
function commandHelp(command, writeErr) {
|
|
566
598
|
command.outputHelp({ error: true });
|
|
567
599
|
const commandPath = [];
|
|
@@ -579,7 +611,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
579
611
|
const writeOut = runtime.stdout ?? ((value) => stdout.push(value));
|
|
580
612
|
const writeErr = runtime.stderr ?? ((value) => stderr.push(value));
|
|
581
613
|
const capabilities = runtime.capabilities ?? plainOutput;
|
|
582
|
-
const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-
|
|
614
|
+
const executeRun = runtime.executeRun ?? (async (options) => (await import("./run-command-SUPJIEY5.js")).executeRunCommand(options));
|
|
583
615
|
const cwd = runtime.cwd ?? process.cwd();
|
|
584
616
|
let exitCode = 3;
|
|
585
617
|
const program = new Command().name("sedum").description(
|
|
@@ -597,7 +629,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
597
629
|
"after",
|
|
598
630
|
"\nCreates a config, a SauceDemo example, .env.example, and ignore rules.\nExisting files are never replaced.\n"
|
|
599
631
|
).action(async () => {
|
|
600
|
-
const { executeInitCommand } = await import("./init-command-
|
|
632
|
+
const { executeInitCommand } = await import("./init-command-4RYOB737.js");
|
|
601
633
|
const interactive = capabilities.stdoutIsTTY && (process.stdin.isTTY === true || runtime.confirmInit !== void 0);
|
|
602
634
|
const confirm = runtime.confirmInit ?? (interactive ? async (question) => {
|
|
603
635
|
const { createInterface } = await import("readline/promises");
|
|
@@ -626,6 +658,18 @@ async function runCli(args, version, runtime = {}) {
|
|
|
626
658
|
program.command("run").description("run configured tests, files, or directories").argument(
|
|
627
659
|
"[paths...]",
|
|
628
660
|
"test files or directories relative to the project root"
|
|
661
|
+
).option(
|
|
662
|
+
"--affected",
|
|
663
|
+
"experimental: send Git diff and test sources to Jev; run relevant tests",
|
|
664
|
+
false
|
|
665
|
+
).option("--base <ref>", "base ref for --affected (default main or master)").option(
|
|
666
|
+
"--threshold <probability>",
|
|
667
|
+
"minimum relevance probability for --affected (default 0.1)",
|
|
668
|
+
relevanceThreshold
|
|
669
|
+
).option(
|
|
670
|
+
"--selection-only",
|
|
671
|
+
"with --affected, print selection JSON without running tests (calls Jev)",
|
|
672
|
+
false
|
|
629
673
|
).option(
|
|
630
674
|
"--include <glob>",
|
|
631
675
|
"include matching project-relative paths (repeatable)",
|
|
@@ -646,7 +690,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
646
690
|
"match id or description substring (repeatable)",
|
|
647
691
|
collectValue,
|
|
648
692
|
[]
|
|
649
|
-
).option("--env <name>", "select a named environment").option("--browser <kind>", "chrome or chromium").option(
|
|
693
|
+
).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(
|
|
650
694
|
"--url-override <url>",
|
|
651
695
|
"replace entry URL origin for preview deployments"
|
|
652
696
|
).option("--output-dir <path>", "run output directory").option("--reporter-dir <path>", "reporter artifact directory").option("--headed", "show the browser", false).option(
|
|
@@ -694,7 +738,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
694
738
|
false
|
|
695
739
|
).addHelpText(
|
|
696
740
|
"after",
|
|
697
|
-
"\nPrerequisites:\n Install Chromium with `sedum browsers install chromium` and set TYPESAFE_API_KEY.\n\nExamples:\n sedum run tests/login.test.yaml\n sedum run tests/login.test.yaml --strict --costs\n"
|
|
741
|
+
"\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.yaml\n sedum run tests/login.test.yaml --strict --costs\n"
|
|
698
742
|
).action(
|
|
699
743
|
async (paths, options) => {
|
|
700
744
|
if (options.shardIndex === void 0 !== (options.shardCount === void 0) || options.shardIndex !== void 0 && options.shardIndex > options.shardCount) {
|
|
@@ -708,6 +752,77 @@ async function runCli(args, version, runtime = {}) {
|
|
|
708
752
|
exitCode = 3;
|
|
709
753
|
return;
|
|
710
754
|
}
|
|
755
|
+
if (options.affected && (options.shardCount ?? 1) > 1) {
|
|
756
|
+
writeErr(
|
|
757
|
+
renderDiagnostic({
|
|
758
|
+
code: "affected_sharding_unsupported",
|
|
759
|
+
message: "--affected cannot be combined with multiple shards: independent relevance selections can leave tests unexecuted.",
|
|
760
|
+
fix: "Remove the shard options, or run without --affected. --parallel is supported."
|
|
761
|
+
})
|
|
762
|
+
);
|
|
763
|
+
exitCode = 3;
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
if (!options.affected && (options.base !== void 0 || options.threshold !== void 0 || options.selectionOnly)) {
|
|
767
|
+
writeErr(
|
|
768
|
+
"--base, --threshold, and --selection-only require --affected.\n"
|
|
769
|
+
);
|
|
770
|
+
exitCode = 3;
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (options.affected) {
|
|
774
|
+
const { selectAffectedTests, AffectedSelectionError } = await import("./affected-selection-5YF7ZHKG.js");
|
|
775
|
+
const { ProviderError: ProviderError2 } = await import("@sedum-dev/core");
|
|
776
|
+
writeErr(
|
|
777
|
+
"Experimental selection sends the tracked Git diff and test/module sources to the configured TypeSafe provider. Full CI is still recommended.\n"
|
|
778
|
+
);
|
|
779
|
+
try {
|
|
780
|
+
const selection = await selectAffectedTests({
|
|
781
|
+
cwd,
|
|
782
|
+
paths,
|
|
783
|
+
filters: {
|
|
784
|
+
include: options.include,
|
|
785
|
+
exclude: options.exclude,
|
|
786
|
+
labels: options.labels,
|
|
787
|
+
names: options.name
|
|
788
|
+
},
|
|
789
|
+
threshold: options.threshold ?? 0.1,
|
|
790
|
+
...options.base !== void 0 ? { base: options.base } : {},
|
|
791
|
+
...options.env ? { environment: options.env } : {},
|
|
792
|
+
...runtime.signal ? { signal: runtime.signal } : {},
|
|
793
|
+
...runtime.createRelevanceProvider ? { createProvider: runtime.createRelevanceProvider } : {}
|
|
794
|
+
});
|
|
795
|
+
paths = selection.tests.filter((test) => test.selected).map((test) => test.file);
|
|
796
|
+
if (options.selectionOnly) {
|
|
797
|
+
writeOut(`${JSON.stringify(selection, null, 2)}
|
|
798
|
+
`);
|
|
799
|
+
exitCode = 0;
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
writeErr(
|
|
803
|
+
`Affected selection: ${paths.length}/${selection.tests.length} tests, threshold ${selection.threshold}, base ${selection.base}.
|
|
804
|
+
`
|
|
805
|
+
);
|
|
806
|
+
for (const test of selection.tests)
|
|
807
|
+
writeErr(
|
|
808
|
+
`${test.selected ? "RUN " : "SKIP"} ${test.probability.toFixed(4)} ${JSON.stringify(test.file)} (${test.reason})
|
|
809
|
+
`
|
|
810
|
+
);
|
|
811
|
+
if (!paths.length) {
|
|
812
|
+
writeErr("No relevant tests selected; no tests were executed.\n");
|
|
813
|
+
exitCode = 0;
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
} catch (error) {
|
|
817
|
+
writeErr(
|
|
818
|
+
`${error instanceof AffectedSelectionError || error instanceof ProviderError2 ? error.message : "Affected selection could not complete."}
|
|
819
|
+
No tests were run. Fix the selection error or run without --affected.
|
|
820
|
+
`
|
|
821
|
+
);
|
|
822
|
+
exitCode = 3;
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
711
826
|
const lifecycle = new ReporterLifecycle();
|
|
712
827
|
const terminalNames = options.reporter.length ? options.reporter.filter(
|
|
713
828
|
(name) => name !== "json" && name !== "markdown" && name !== "junit"
|
|
@@ -753,6 +868,8 @@ async function runCli(args, version, runtime = {}) {
|
|
|
753
868
|
},
|
|
754
869
|
...options.env ? { environment: options.env } : {},
|
|
755
870
|
...options.browser ? { browser: options.browser } : {},
|
|
871
|
+
...options.vision !== void 0 ? { vision: options.vision } : {},
|
|
872
|
+
...options.visionModel !== void 0 ? { visionModel: options.visionModel } : {},
|
|
756
873
|
...options.urlOverride ? { urlOverride: options.urlOverride } : {},
|
|
757
874
|
...options.outputDir ? { outputDir: options.outputDir } : {},
|
|
758
875
|
...options.reporterDir ? { reporterDir: options.reporterDir } : {},
|
|
@@ -838,7 +955,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
838
955
|
"after",
|
|
839
956
|
"\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"
|
|
840
957
|
).action(async (options) => {
|
|
841
|
-
const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-
|
|
958
|
+
const { executeDoctorCommand, renderDoctorText } = await import("./doctor-command-EU5OJJ5P.js");
|
|
842
959
|
const result = await executeDoctorCommand(cwd, runtime.doctorProbes);
|
|
843
960
|
writeOut(
|
|
844
961
|
options.json ? `${JSON.stringify(result)}
|
|
@@ -853,7 +970,7 @@ async function runCli(args, version, runtime = {}) {
|
|
|
853
970
|
"test files, module files, or directories relative to the project root (default: configured tests)"
|
|
854
971
|
).option(
|
|
855
972
|
"--online",
|
|
856
|
-
"classify sentences the offline cache cannot, using
|
|
973
|
+
"classify sentences the offline cache cannot, using the configured provider API key, and update .sedum/classifications.json",
|
|
857
974
|
false
|
|
858
975
|
).addHelpText(
|
|
859
976
|
"after",
|
|
@@ -25,8 +25,15 @@ var DEFAULTS = {
|
|
|
25
25
|
contradictionCutoff: 0.5
|
|
26
26
|
},
|
|
27
27
|
outputDir: ".sedum/runs",
|
|
28
|
-
reporterDir: ".sedum/reports"
|
|
28
|
+
reporterDir: ".sedum/reports",
|
|
29
|
+
vision: {
|
|
30
|
+
enabled: false,
|
|
31
|
+
model: "google/gemini-3.8-flash",
|
|
32
|
+
timeoutMs: 1e4
|
|
33
|
+
}
|
|
29
34
|
};
|
|
35
|
+
var DEFAULT_PROVIDER_BASE_URL = "https://api.typesafe.ai";
|
|
36
|
+
var DEFAULT_PROVIDER_MODEL = "jev-latest";
|
|
30
37
|
var allowed = {
|
|
31
38
|
root: /* @__PURE__ */ new Set([
|
|
32
39
|
"tests",
|
|
@@ -38,12 +45,14 @@ var allowed = {
|
|
|
38
45
|
"baseUrl",
|
|
39
46
|
"environment",
|
|
40
47
|
"variables",
|
|
41
|
-
"environments"
|
|
48
|
+
"environments",
|
|
49
|
+
"vision"
|
|
42
50
|
]),
|
|
43
51
|
tests: /* @__PURE__ */ new Set(["directory", "include", "exclude"]),
|
|
44
52
|
viewport: /* @__PURE__ */ new Set(["width", "height"]),
|
|
45
53
|
thresholds: /* @__PURE__ */ new Set(["verify", "lowConfidenceBand", "contradiction"]),
|
|
46
|
-
environment: /* @__PURE__ */ new Set(["baseUrl", "variables"])
|
|
54
|
+
environment: /* @__PURE__ */ new Set(["baseUrl", "variables"]),
|
|
55
|
+
vision: /* @__PURE__ */ new Set(["enabled", "model", "timeoutMs"])
|
|
47
56
|
};
|
|
48
57
|
function source(file, counter, node) {
|
|
49
58
|
const position = counter.linePos(node?.range?.[0] ?? 0);
|
|
@@ -95,7 +104,7 @@ function scalarVariables(value, key, diagnostics, file, counter, node) {
|
|
|
95
104
|
}
|
|
96
105
|
const result = {};
|
|
97
106
|
for (const [name, item] of Object.entries(value)) {
|
|
98
|
-
if (name === "TYPESAFE_API_KEY") {
|
|
107
|
+
if (name === "TYPESAFE_API_KEY" || name === "OPEN_ROUTER_API_KEY") {
|
|
99
108
|
diagnostic(
|
|
100
109
|
diagnostics,
|
|
101
110
|
file,
|
|
@@ -103,8 +112,8 @@ function scalarVariables(value, key, diagnostics, file, counter, node) {
|
|
|
103
112
|
node,
|
|
104
113
|
`${key}.${name}`,
|
|
105
114
|
"api_key_in_config",
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
`${name} must not be stored in sedum.config.yaml.`,
|
|
116
|
+
`Put ${name} in the project-root .env or invoking process environment.`
|
|
108
117
|
);
|
|
109
118
|
continue;
|
|
110
119
|
}
|
|
@@ -273,6 +282,7 @@ function freeze(config) {
|
|
|
273
282
|
Object.freeze(config.exclude);
|
|
274
283
|
Object.freeze(config.viewport);
|
|
275
284
|
Object.freeze(config.thresholds);
|
|
285
|
+
Object.freeze(config.vision);
|
|
276
286
|
Object.freeze(config.variables);
|
|
277
287
|
return Object.freeze(config);
|
|
278
288
|
}
|
|
@@ -371,7 +381,8 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
371
381
|
const maps = [
|
|
372
382
|
["tests", allowed.tests],
|
|
373
383
|
["viewport", allowed.viewport],
|
|
374
|
-
["thresholds", allowed.thresholds]
|
|
384
|
+
["thresholds", allowed.thresholds],
|
|
385
|
+
["vision", allowed.vision]
|
|
375
386
|
];
|
|
376
387
|
for (const [key, names] of maps)
|
|
377
388
|
mapUnknownKeys(
|
|
@@ -410,7 +421,8 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
410
421
|
for (const [key, value] of [
|
|
411
422
|
["viewport", raw.viewport],
|
|
412
423
|
["thresholds", raw.thresholds],
|
|
413
|
-
["environments", raw.environments]
|
|
424
|
+
["environments", raw.environments],
|
|
425
|
+
["vision", raw.vision]
|
|
414
426
|
])
|
|
415
427
|
if (value !== void 0 && !object(value))
|
|
416
428
|
diagnostic(
|
|
@@ -426,6 +438,7 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
426
438
|
const viewport = object(raw.viewport) ? raw.viewport : {};
|
|
427
439
|
const thresholds = object(raw.thresholds) ? raw.thresholds : {};
|
|
428
440
|
const environments = object(raw.environments) ? raw.environments : {};
|
|
441
|
+
const vision = object(raw.vision) ? raw.vision : {};
|
|
429
442
|
for (const [name, value] of Object.entries(environments)) {
|
|
430
443
|
if (!object(value)) {
|
|
431
444
|
diagnostic(
|
|
@@ -605,7 +618,72 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
605
618
|
...fileEnvironment,
|
|
606
619
|
...hostEnvironment
|
|
607
620
|
};
|
|
608
|
-
const
|
|
621
|
+
const providerValue = (name) => hostEnvironment[name]?.trim() || fileEnvironment[name]?.trim() || void 0;
|
|
622
|
+
const customProvider = {
|
|
623
|
+
baseUrl: providerValue("TYPESAFE_BASE_URL"),
|
|
624
|
+
model: providerValue("TYPESAFE_DEFAULT_MODEL")
|
|
625
|
+
};
|
|
626
|
+
let providerBaseUrl = DEFAULT_PROVIDER_BASE_URL;
|
|
627
|
+
if (customProvider.baseUrl) {
|
|
628
|
+
try {
|
|
629
|
+
const parsed = new URL(customProvider.baseUrl);
|
|
630
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.search || parsed.hash)
|
|
631
|
+
throw new Error("unsafe provider URL");
|
|
632
|
+
providerBaseUrl = parsed.href.replace(/\/$/u, "");
|
|
633
|
+
} catch {
|
|
634
|
+
diagnostics.push({
|
|
635
|
+
code: "invalid_provider_url",
|
|
636
|
+
file: environmentFile,
|
|
637
|
+
line: 1,
|
|
638
|
+
col: 1,
|
|
639
|
+
key: "TYPESAFE_BASE_URL",
|
|
640
|
+
message: "TYPESAFE_BASE_URL must be an absolute HTTPS URL without credentials, query, or fragment.",
|
|
641
|
+
fix: "Use a base URL such as https://api.typesafe.ai."
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
const providerModel = customProvider.model ?? DEFAULT_PROVIDER_MODEL;
|
|
646
|
+
const apiKey = providerValue("TYPESAFE_API_KEY");
|
|
647
|
+
const visionApiKey = providerValue("OPEN_ROUTER_API_KEY");
|
|
648
|
+
variables.OPEN_ROUTER_API_KEY = void 0;
|
|
649
|
+
const visionEnabledValue = overrides.vision?.enabled ?? vision.enabled;
|
|
650
|
+
const visionEnabled = visionEnabledValue ?? DEFAULTS.vision.enabled;
|
|
651
|
+
if (typeof visionEnabled !== "boolean")
|
|
652
|
+
diagnostic(
|
|
653
|
+
diagnostics,
|
|
654
|
+
file,
|
|
655
|
+
counter,
|
|
656
|
+
node("vision.enabled"),
|
|
657
|
+
"vision.enabled",
|
|
658
|
+
"invalid_config_type",
|
|
659
|
+
"Configuration key `vision.enabled` must be a boolean.",
|
|
660
|
+
"Use `vision.enabled: true` or `vision.enabled: false`."
|
|
661
|
+
);
|
|
662
|
+
const visionModelValue = overrides.vision?.model ?? vision.model;
|
|
663
|
+
const visionModel = visionModelValue ?? DEFAULTS.vision.model;
|
|
664
|
+
if (typeof visionModel !== "string" || !visionModel.trim())
|
|
665
|
+
diagnostic(
|
|
666
|
+
diagnostics,
|
|
667
|
+
file,
|
|
668
|
+
counter,
|
|
669
|
+
node("vision.model"),
|
|
670
|
+
"vision.model",
|
|
671
|
+
"invalid_config_type",
|
|
672
|
+
"Configuration key `vision.model` must be nonempty text.",
|
|
673
|
+
`Use a model such as \`${DEFAULTS.vision.model}\`.`
|
|
674
|
+
);
|
|
675
|
+
const visionTimeoutValue = vision.timeoutMs ?? DEFAULTS.vision.timeoutMs;
|
|
676
|
+
if (!Number.isSafeInteger(visionTimeoutValue) || visionTimeoutValue < 1)
|
|
677
|
+
diagnostic(
|
|
678
|
+
diagnostics,
|
|
679
|
+
file,
|
|
680
|
+
counter,
|
|
681
|
+
node("vision.timeoutMs"),
|
|
682
|
+
"vision.timeoutMs",
|
|
683
|
+
"invalid_config_type",
|
|
684
|
+
"Configuration key `vision.timeoutMs` must be a positive integer.",
|
|
685
|
+
"Use a timeout such as `10000`."
|
|
686
|
+
);
|
|
609
687
|
const testDirectory = relativePath(
|
|
610
688
|
found.root,
|
|
611
689
|
tests.directory,
|
|
@@ -669,7 +747,15 @@ async function loadProjectConfig(start = process.cwd(), hostEnvironment = proces
|
|
|
669
747
|
reporterDir,
|
|
670
748
|
baseUrl,
|
|
671
749
|
variables,
|
|
672
|
-
apiKey
|
|
750
|
+
apiKey,
|
|
751
|
+
providerBaseUrl,
|
|
752
|
+
providerModel,
|
|
753
|
+
vision: {
|
|
754
|
+
enabled: visionEnabled === true,
|
|
755
|
+
model: typeof visionModel === "string" && visionModel.trim() ? visionModel : DEFAULTS.vision.model,
|
|
756
|
+
timeoutMs: Number.isSafeInteger(visionTimeoutValue) && visionTimeoutValue > 0 ? visionTimeoutValue : DEFAULTS.vision.timeoutMs
|
|
757
|
+
},
|
|
758
|
+
visionApiKey
|
|
673
759
|
});
|
|
674
760
|
}
|
|
675
761
|
async function discoverConfiguredTests(config) {
|
|
@@ -699,6 +785,8 @@ async function discoverConfiguredTests(config) {
|
|
|
699
785
|
|
|
700
786
|
export {
|
|
701
787
|
ProjectConfigError,
|
|
788
|
+
DEFAULT_PROVIDER_BASE_URL,
|
|
789
|
+
DEFAULT_PROVIDER_MODEL,
|
|
702
790
|
loadProjectConfig,
|
|
703
791
|
discoverConfiguredTests
|
|
704
792
|
};
|
package/dist/cli.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
runCli
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-V4JF5CPE.js";
|
|
5
|
+
import "./chunk-72CYPRWT.js";
|
|
6
|
+
import "./chunk-W2BEUHUB.js";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
9
|
import { createRequire } from "module";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RunResult, BrowserKind, VerifyPolicy, ClassificationProvider, BrowserInstallResult } from '@sedum-dev/core';
|
|
2
|
-
import { AuthProbeResult } from '@sedum-dev/provider-typesafe';
|
|
2
|
+
import { TypeSafeAdapter, AuthProbeResult } from '@sedum-dev/provider-typesafe';
|
|
3
3
|
|
|
4
4
|
interface OutputCapabilities {
|
|
5
5
|
readonly stdoutIsTTY: boolean;
|
|
@@ -42,6 +42,10 @@ interface ProjectConfigOverrides {
|
|
|
42
42
|
readonly outputDir?: string;
|
|
43
43
|
readonly reporterDir?: string;
|
|
44
44
|
readonly baseUrl?: string;
|
|
45
|
+
readonly vision?: {
|
|
46
|
+
readonly enabled?: boolean;
|
|
47
|
+
readonly model?: string;
|
|
48
|
+
};
|
|
45
49
|
}
|
|
46
50
|
interface ResolvedProjectConfig {
|
|
47
51
|
readonly projectRoot: string;
|
|
@@ -61,6 +65,14 @@ interface ResolvedProjectConfig {
|
|
|
61
65
|
readonly baseUrl: string | null;
|
|
62
66
|
readonly variables: Readonly<Record<string, string | undefined>>;
|
|
63
67
|
readonly apiKey: string | undefined;
|
|
68
|
+
readonly providerBaseUrl: string;
|
|
69
|
+
readonly providerModel: string;
|
|
70
|
+
readonly vision: {
|
|
71
|
+
readonly enabled: boolean;
|
|
72
|
+
readonly model: string;
|
|
73
|
+
readonly timeoutMs: number;
|
|
74
|
+
};
|
|
75
|
+
readonly visionApiKey: string | undefined;
|
|
64
76
|
}
|
|
65
77
|
interface ProjectConfigLoadOptions {
|
|
66
78
|
/**
|
|
@@ -99,6 +111,8 @@ interface RunCommandOptions {
|
|
|
99
111
|
readonly filters?: RunFilters;
|
|
100
112
|
readonly environment?: string;
|
|
101
113
|
readonly browser?: string;
|
|
114
|
+
readonly vision?: boolean;
|
|
115
|
+
readonly visionModel?: string;
|
|
102
116
|
readonly urlOverride?: string;
|
|
103
117
|
readonly outputDir?: string;
|
|
104
118
|
readonly reporterDir?: string;
|
|
@@ -135,17 +149,24 @@ interface RunCommandExecution {
|
|
|
135
149
|
readonly onReporterFailure?: () => Promise<RunCommandExecution>;
|
|
136
150
|
}
|
|
137
151
|
|
|
152
|
+
type RelevanceProviderFactory = (config: ResolvedProjectConfig) => Pick<TypeSafeAdapter, "scoreRelevance">;
|
|
153
|
+
|
|
138
154
|
interface DoctorProbes {
|
|
139
155
|
readonly nodeVersion?: string;
|
|
140
156
|
readonly loadConfig?: (cwd: string) => Promise<ResolvedProjectConfig>;
|
|
141
157
|
readonly browser?: (kind: BrowserKind) => boolean;
|
|
142
|
-
readonly network?: () => Promise<boolean>;
|
|
143
|
-
readonly auth?: (apiKey: string
|
|
158
|
+
readonly network?: (baseURL: string) => Promise<boolean>;
|
|
159
|
+
readonly auth?: (apiKey: string, options: {
|
|
160
|
+
readonly baseURL: string;
|
|
161
|
+
readonly model: string;
|
|
162
|
+
}) => Promise<AuthProbeResult>;
|
|
144
163
|
readonly output?: (config: ResolvedProjectConfig) => Promise<void>;
|
|
145
164
|
}
|
|
146
165
|
|
|
147
166
|
type ClassificationProviderFactory = (options: {
|
|
148
167
|
readonly apiKey?: string;
|
|
168
|
+
readonly baseURL: string;
|
|
169
|
+
readonly model: string;
|
|
149
170
|
}) => ClassificationProvider | Promise<ClassificationProvider>;
|
|
150
171
|
|
|
151
172
|
interface CliOutput {
|
|
@@ -166,6 +187,7 @@ interface CliRuntime {
|
|
|
166
187
|
readonly cwd?: string;
|
|
167
188
|
/** Used only by `validate --online`. */
|
|
168
189
|
readonly createClassificationProvider?: ClassificationProviderFactory;
|
|
190
|
+
readonly createRelevanceProvider?: RelevanceProviderFactory;
|
|
169
191
|
readonly doctorProbes?: DoctorProbes;
|
|
170
192
|
readonly confirmInit?: (question: string) => Promise<boolean>;
|
|
171
193
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,13 @@ import {
|
|
|
2
2
|
renderRunSummary,
|
|
3
3
|
runCli,
|
|
4
4
|
runExitCode
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-V4JF5CPE.js";
|
|
6
|
+
import "./chunk-72CYPRWT.js";
|
|
7
7
|
import {
|
|
8
8
|
ProjectConfigError,
|
|
9
9
|
discoverConfiguredTests,
|
|
10
10
|
loadProjectConfig
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-W2BEUHUB.js";
|
|
12
12
|
export {
|
|
13
13
|
ProjectConfigError,
|
|
14
14
|
discoverConfiguredTests,
|
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
browserAvailable,
|
|
3
3
|
keyPresent,
|
|
4
4
|
supportedNode
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-UACA6VAM.js";
|
|
6
6
|
import {
|
|
7
7
|
ProjectConfigError,
|
|
8
8
|
loadProjectConfig
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-W2BEUHUB.js";
|
|
10
10
|
|
|
11
11
|
// src/init-command.ts
|
|
12
12
|
import { constants } from "fs";
|
|
@@ -31,6 +31,7 @@ steps:
|
|
|
31
31
|
- verify a list of products with prices is shown
|
|
32
32
|
`;
|
|
33
33
|
var ENV_EXAMPLE = `# Get a TypeSafe key and put it in .env, or set it in your shell.
|
|
34
|
+
# For a compatible provider, also set TYPESAFE_BASE_URL and optionally TYPESAFE_DEFAULT_MODEL.
|
|
34
35
|
TYPESAFE_API_KEY=
|
|
35
36
|
# Public SauceDemo sample account; no Sauce Labs account is required.
|
|
36
37
|
SAUCE_PASSWORD=secret_sauce
|
|
@@ -189,10 +190,11 @@ ${++step}. ${title}
|
|
|
189
190
|
const hasBrowser = (options.browser ?? browserAvailable)(config.browser);
|
|
190
191
|
const hasEnv = await pathExists(path.join(root, ".env"));
|
|
191
192
|
if (!keyPresent(config))
|
|
192
|
-
next("Add
|
|
193
|
+
next("Add a provider API key", [
|
|
193
194
|
"Get a key at https://typesafe.ai/.",
|
|
194
195
|
...hasEnv ? [] : ["cp .env.example .env"],
|
|
195
|
-
"Open .env and set TYPESAFE_API_KEY to your key (or set it in your shell)."
|
|
196
|
+
"Open .env and set TYPESAFE_API_KEY to your key (or set it in your shell).",
|
|
197
|
+
"For a compatible provider, also set TYPESAFE_BASE_URL and use that provider's key as TYPESAFE_API_KEY."
|
|
196
198
|
]);
|
|
197
199
|
if (!hasBrowser)
|
|
198
200
|
next(
|