sedum-cli 0.1.0-alpha.0 → 0.1.0-alpha.10
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/README.md +64 -0
- package/dist/affected-selection-ENIH4AGP.js +206 -0
- package/dist/{chunk-TU5MIKGA.js → chunk-4LEXNO2M.js} +502 -187
- package/dist/chunk-7M7YUTRH.js +132 -0
- package/dist/{chunk-BEV24G7S.js → chunk-EFRMSNBD.js} +37 -171
- package/dist/{chunk-OB6ZUJ6X.js → chunk-H4QXVVQI.js} +83 -22
- package/dist/chunk-NOGCXR4U.js +208 -0
- package/dist/{chunk-TZGSCV23.js → chunk-VNGIF7AY.js} +186 -15
- package/dist/cli.js +31 -5
- package/dist/{doctor-command-2PMOA32Y.js → doctor-command-XRE6PEGU.js} +2 -2
- package/dist/index.d.ts +54 -11
- package/dist/index.js +11 -4
- package/dist/{init-command-54R2FQ2U.js → init-command-SXAVPVX6.js} +38 -20
- package/dist/run-command-DEWAPQML.js +1605 -0
- package/package.json +23 -4
- package/dist/run-command-VAVFPCWG.js +0 -1269
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# sedum-cli
|
|
2
|
+
|
|
3
|
+
Write browser tests in plain English, keep the full power of TypeScript, and run the whole suite on every pull request for dollars a month instead of thousands.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Sedum is an open-source (MIT) browser end-to-end test runner built on Playwright. Each step is a sentence such as `await ai("click the Checkout button")`. Sedum finds the element on the page with a fast decision model and your own API key. Clicking, typing, waiting, verdicts, and exit codes are deterministic Playwright.
|
|
8
|
+
|
|
9
|
+
> **Status: pre-alpha.** The test format may change before 1.0, and Windows is experimental. Linux and macOS are verified.
|
|
10
|
+
|
|
11
|
+
## Try it
|
|
12
|
+
|
|
13
|
+
You need Node.js 20.19 or newer and credentials for TypeSafe Jev (the default) or Cloudflare Clef.
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
mkdir my-sedum-tests && cd my-sedum-tests
|
|
17
|
+
npm init -y
|
|
18
|
+
git init # locator results are cached in Git metadata
|
|
19
|
+
npm install -D sedum-cli
|
|
20
|
+
npx sedum init # an example test, config, and .env.example
|
|
21
|
+
npx sedum browsers install chromium # if init says it is missing
|
|
22
|
+
cp .env.example .env # then set TYPESAFE_API_KEY in .env
|
|
23
|
+
npx sedum run tests/example.test.ts --headed
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To see a failure, change the last step to a false claim, such as `verify an error message says the password is incorrect`, and run it again. It fails with exit code 1 and says how sure it is. If anything is missing, `npx sedum doctor` says what and how to fix it.
|
|
27
|
+
|
|
28
|
+
## A test
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { secret, test } from "sedum-cli";
|
|
32
|
+
|
|
33
|
+
test(
|
|
34
|
+
"a customer logs in",
|
|
35
|
+
{ url: "https://www.saucedemo.com/" },
|
|
36
|
+
async ({ ai, env }) => {
|
|
37
|
+
await ai("type standard_user in the username field");
|
|
38
|
+
await ai("type {{password}} in the password field", {
|
|
39
|
+
password: secret(env.SAUCE_PASSWORD!),
|
|
40
|
+
});
|
|
41
|
+
await ai("click the login button");
|
|
42
|
+
await ai("verify a list of products with prices is shown");
|
|
43
|
+
},
|
|
44
|
+
);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Between steps you can use Playwright's `page` and `expect`, any test-data library, and API calls. Tests can also be plain YAML files with a list of sentences.
|
|
48
|
+
|
|
49
|
+
## Why Sedum
|
|
50
|
+
|
|
51
|
+
- **Cheap enough for every PR.** In the project's own benchmark, a 20-person team's pull request suite costs $38 to $91 a month on Sedum with Jev, against $4,875 at a per-step platform's published rates. Method and caveats are on [sedum.dev](https://sedum.dev).
|
|
52
|
+
- **Probabilities, not guesses.** Every claim is scored against a threshold and checked for contradicting evidence, so a marginal pass is flagged instead of silently green.
|
|
53
|
+
- **No black box.** Prompts, scoring, and caching are in the repository.
|
|
54
|
+
- **Made for coding agents.** `npx sedum run --reporter markdown` writes a failure report that Claude Code or Cursor can read and fix from.
|
|
55
|
+
|
|
56
|
+
## Documentation
|
|
57
|
+
|
|
58
|
+
- [Full README and quickstart](https://github.com/sedum-dev/sedum#readme)
|
|
59
|
+
- [CLI commands](https://github.com/sedum-dev/sedum/blob/main/docs/cli.md)
|
|
60
|
+
- [Running in CI](https://github.com/sedum-dev/sedum/blob/main/docs/ci.md)
|
|
61
|
+
- [Project configuration](https://github.com/sedum-dev/sedum/blob/main/docs/configuration.md)
|
|
62
|
+
- [Report an issue](https://github.com/sedum-dev/sedum/issues)
|
|
63
|
+
|
|
64
|
+
MIT licensed.
|
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
};
|