bivium 0.6.1 → 0.7.0
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 +27 -24
- package/cli.js +573 -273
- package/docs/api.md +78 -23
- package/docs/ci.md +67 -29
- package/docs/cli.md +325 -38
- package/docs/config.md +330 -42
- package/docs/how-it-works.md +141 -67
- package/docs/recipes.md +117 -47
- package/docs/tuning.md +154 -47
- package/index.d.ts +91 -45
- package/package.json +1 -1
- package/shared.js +189 -40
package/docs/cli.md
CHANGED
|
@@ -1,39 +1,310 @@
|
|
|
1
1
|
# CLI
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
3
|
+
The `bivium` command picks the tests a change needs, runs them,
|
|
4
|
+
and explains each choice.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
bivium plan origin/main # which tests this branch needs
|
|
8
|
+
bivium run --suite unit # run the unit suite's selection
|
|
9
|
+
bivium why tests/Button.test.ts # how a change reaches this test
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
It has five commands:
|
|
13
|
+
|
|
14
|
+
| Command | What it answers |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| [`plan`](#plan) | which tests of each suite a change can reach |
|
|
17
|
+
| [`run`](#run) | whether one suite's selected tests pass, in its runner |
|
|
18
|
+
| [`why`](#why) | how a change reaches one test, edge by edge |
|
|
19
|
+
| [`check`](#check) | what makes plans wider than they need to be |
|
|
20
|
+
| [`graph`](#graph) | which files reach the most tests |
|
|
21
|
+
|
|
22
|
+
## plan
|
|
23
|
+
|
|
24
|
+
`plan` prints the tests each suite needs for the changes since a base.
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
bivium plan [base] [--json] [--github] [--list]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`base` defaults to the config's `base`,
|
|
31
|
+
else the upstream default branch.
|
|
32
|
+
|
|
33
|
+
On a terminal, each suite gets a verdict first:
|
|
34
|
+
how many of its tests run, and for how many changed files;
|
|
35
|
+
or that all of them run, or none, and why.
|
|
36
|
+
A gray line says what it planned against: the base, its merge base,
|
|
37
|
+
and the config file.
|
|
38
|
+
Lines for each other full-run cause,
|
|
39
|
+
package change and narrower note follow it.
|
|
40
|
+
Then a table counts the selected tests by folder,
|
|
41
|
+
and a last line says how many tests it planned and what that took:
|
|
42
|
+
|
|
43
|
+
```console
|
|
44
|
+
$ bunx bivium plan
|
|
45
|
+
3 of 12 tests run for 1 changed file (unit)
|
|
46
|
+
no tests run (e2e): no change reaches a test
|
|
47
|
+
since origin/main (merge base 6b844dd) · config bivium.config.ts
|
|
48
|
+
|
|
49
|
+
directory unit
|
|
50
|
+
tests/* 2
|
|
51
|
+
tests/css/ 1
|
|
52
|
+
────
|
|
53
|
+
2 directories 3
|
|
54
|
+
|
|
55
|
+
✓ Planned 3 tests · 323 ms · --list for the files
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Piped, run by a coding agent, or with `--list`,
|
|
59
|
+
it prints the files instead.
|
|
60
|
+
The first line says what it planned against: the base, its merge base,
|
|
61
|
+
how many files changed, and the config file.
|
|
62
|
+
Then each suite gets one line:
|
|
63
|
+
|
|
64
|
+
| Selection | Means |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `none` | no test of the suite reaches a change |
|
|
67
|
+
| `3 of 12 files` | these tests reach a change; the files follow, one per line |
|
|
68
|
+
| `all 12 files (each reaches a change)` | every test reaches a change |
|
|
69
|
+
| `all (full run)` | a cause runs the suite in full; a `Full run:` line above names it |
|
|
70
|
+
|
|
71
|
+
Options:
|
|
72
|
+
|
|
73
|
+
- `--list` prints the files on a terminal too, as a pipe gets them.
|
|
74
|
+
- `--json` prints the plan as data, with the fields below.
|
|
75
|
+
- `--github` also writes each suite's selection to `$GITHUB_OUTPUT` as
|
|
76
|
+
`<output>=all`, `none`, or the files separated by spaces.
|
|
77
|
+
`<output>` is the suite's `output`, `<name>-tests` by default.
|
|
78
|
+
|
|
79
|
+
| Field | Holds |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `base`, `mergeBase` | the base ref, and the merge base the working tree is compared with |
|
|
82
|
+
| `config` | the config file |
|
|
83
|
+
| `changed` | the files changed since the merge base |
|
|
84
|
+
| `suites` | each suite's selection: `{ mode: "all" }`, `{ mode: "none" }`, or `{ mode: "some", files }` |
|
|
85
|
+
| `totals` | how many test files each suite has |
|
|
86
|
+
| `reasons` | why a suite runs in full, as sentences |
|
|
87
|
+
| `causes` | the same reasons as data, each a `FullRunCause`: `{ kind, suites, file?, package?, narrower?, message }` |
|
|
88
|
+
| `packages` | a line per package a lockfile or `package.json` change changed: `bun.lock: svelte 5.1.0 → 5.2.0` |
|
|
89
|
+
| `narrowed` | what each [narrower](api.md#narrowers) returned |
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
bivium plan origin/main --json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## run
|
|
96
|
+
|
|
97
|
+
`run` runs a suite's `run` command on the tests `plan` selects for it.
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
bivium run [base] [--suite <name>]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
- `--suite <name>` picks the suite.
|
|
104
|
+
Default: the first one in the config.
|
|
105
|
+
|
|
106
|
+
It prints the plan first, as `plan` does.
|
|
107
|
+
The selected files go where the command says `{files}`, or at its end.
|
|
108
|
+
When every test is selected, no files are passed,
|
|
109
|
+
so the runner runs them all.
|
|
110
|
+
When none is, `run` skips the command and exits 0.
|
|
111
|
+
Otherwise it exits with the command's status.
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
bivium run --suite e2e
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## why
|
|
118
|
+
|
|
119
|
+
`why` shows the shortest chain of edges from a changed file to a test.
|
|
120
|
+
An edge is one link the graph follows,
|
|
121
|
+
such as an import or a `page.goto()`.
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
bivium why <test> [file] [--base <ref>] [--format <f>] [--all] [--json]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Each edge in the chain names what spells it and the line it's on.
|
|
128
|
+
A last line counts the other changes that reach the test.
|
|
129
|
+
Options:
|
|
130
|
+
|
|
131
|
+
- `file` starts the chain at this file instead of a changed one.
|
|
132
|
+
- `--base <ref>` sets the base to diff against.
|
|
133
|
+
- `--format <f>` picks the layout, from the table below.
|
|
134
|
+
- `--all` shows every change's chain, not only the shortest.
|
|
135
|
+
- `--json` prints the chain as data, as `--format json` does.
|
|
136
|
+
|
|
137
|
+
| Format | Shows |
|
|
138
|
+
| --- | --- |
|
|
139
|
+
| `tree` | the default: the chain drawn from the test down to the change |
|
|
140
|
+
| `chain` | the chain read from the change to the test |
|
|
141
|
+
| `source` | each hop's line of source |
|
|
142
|
+
| `json` | the chain as data |
|
|
143
|
+
|
|
144
|
+
A test that isn't selected gets a line saying so.
|
|
145
|
+
Given a `file`, `why` also counts the tests that file's chains reach,
|
|
146
|
+
and names one.
|
|
147
|
+
|
|
148
|
+
```sh
|
|
149
|
+
bivium why tests/Button.test.ts src/Button.svelte --format chain
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
[Reading `why`](#reading-why) has real output of each format.
|
|
153
|
+
|
|
154
|
+
## check
|
|
155
|
+
|
|
156
|
+
`check` lists what makes plans wider than they need to be,
|
|
157
|
+
each with where it is and how to fix it.
|
|
158
|
+
|
|
159
|
+
```sh
|
|
160
|
+
bivium check [--base <ref>] [--max-unknown <n>] [--all] [--json]
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
A node is a file, a barrel name, or a package in the graph.
|
|
164
|
+
A node has unknown dependencies (an unknown) when bivium can't read all
|
|
165
|
+
it depends on, such as an import it can't resolve or a read from disk.
|
|
166
|
+
Every test that reaches one runs on every change.
|
|
167
|
+
A changed file under a suite's `root` that no test reaches runs the
|
|
168
|
+
whole suite: the orphan rule.
|
|
169
|
+
|
|
170
|
+
`check` leads with a verdict: how many files it can't follow,
|
|
171
|
+
and how many tests those run on every change.
|
|
172
|
+
A gray line counts the rest.
|
|
173
|
+
Then each cause gets a section: the cause, how many,
|
|
174
|
+
up to three places it's at, and its fix once.
|
|
175
|
+
A place whose fix differs carries its own.
|
|
176
|
+
A last line says whether the check passes, and what failed:
|
|
177
|
+
|
|
178
|
+
```console
|
|
179
|
+
$ bunx bivium check
|
|
180
|
+
2 files bivium can't follow send 2 tests to every change
|
|
181
|
+
|
|
182
|
+
reads the disk without @depends-on · 2 files
|
|
183
|
+
├ test/u.test.js:1
|
|
184
|
+
└ test/w.test.js:1
|
|
185
|
+
fix name what it reads: `// @depends-on <glob>`, or `// @reads <glob>` for…
|
|
186
|
+
|
|
187
|
+
unresolved relative import · 1 import in 1 file
|
|
188
|
+
└ test/u.test.js:2 "./gone.js"
|
|
189
|
+
fix no file at that path: fix the import, or add an `edges` entry if a build…
|
|
190
|
+
|
|
191
|
+
✓ Check passes · checked in 152 ms · --all for every file
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
The sections cover:
|
|
195
|
+
|
|
196
|
+
- every unknown a test reaches, by cause,
|
|
197
|
+
with where and how to fix each;
|
|
198
|
+
- unknowns no test depends on, apart and not counted toward
|
|
199
|
+
`--max-unknown`: plans only run tests, so these widen nothing;
|
|
200
|
+
- files under a suite's `root` that no test reaches,
|
|
201
|
+
each with a fix
|
|
202
|
+
(see [A change no test reaches](tuning.md#a-change-no-test-reaches));
|
|
203
|
+
- `tsconfig.json` files that don't parse;
|
|
204
|
+
- [dead globs](tuning.md#dead-globs);
|
|
205
|
+
- repository paths a test spells that nothing declares.
|
|
206
|
+
|
|
207
|
+
`check` exits 1 on any of these:
|
|
208
|
+
|
|
209
|
+
- more than `n` unknowns reach a test, with `--max-unknown <n>`;
|
|
210
|
+
- with `knownUnknowns` set, an unknown a test reaches that it doesn't
|
|
211
|
+
list, or an entry whose dependencies are all known;
|
|
212
|
+
- a dead glob `deadGlobs` doesn't allow,
|
|
213
|
+
or a `deadGlobs` entry that matches none;
|
|
214
|
+
- a repository path a test spells that nothing declares.
|
|
215
|
+
|
|
216
|
+
Options:
|
|
217
|
+
|
|
218
|
+
- `--all` lists every place, and each fix whole.
|
|
219
|
+
`--json` has the rest, such as the tests each unknown runs.
|
|
220
|
+
- `--max-unknown <n>` fails when more than `n` unknowns reach a test.
|
|
221
|
+
- `--base <ref>` sets the base.
|
|
222
|
+
Default: `HEAD`.
|
|
223
|
+
- `--json` prints the report as data.
|
|
224
|
+
`ok` matches the exit status, and `summary` holds the counts the text
|
|
225
|
+
leads with.
|
|
226
|
+
|
|
227
|
+
```sh
|
|
228
|
+
bivium check --max-unknown 0
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## graph
|
|
232
|
+
|
|
233
|
+
`graph` shows, for each file, how many of a suite's tests a change to it
|
|
234
|
+
selects: its fan-in.
|
|
235
|
+
|
|
236
|
+
```sh
|
|
237
|
+
bivium graph [--suite <name>] [--top <n>] [--json]
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
For each suite it lists the `n` files that reach the most tests,
|
|
241
|
+
and how all files spread from reaching none to reaching every test.
|
|
242
|
+
Tests that run on any change are left out and counted apart.
|
|
243
|
+
A few hub files that reach most tests are what make plans wide.
|
|
244
|
+
Options:
|
|
245
|
+
|
|
246
|
+
- `--suite <name>` shows only this suite.
|
|
247
|
+
Default: every suite.
|
|
248
|
+
- `--top <n>` sets how many files to list per suite.
|
|
249
|
+
Default: 10.
|
|
250
|
+
- `--json` prints each suite's `total` and `everyChange` tests,
|
|
251
|
+
and every node with its `imports` and `importers` (its file edges),
|
|
252
|
+
its `fanIn` per suite, and whether it's `unknown`.
|
|
253
|
+
|
|
254
|
+
```sh
|
|
255
|
+
bivium graph --suite e2e --top 5
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Options for every command
|
|
259
|
+
|
|
260
|
+
These work with every command, before or after it:
|
|
261
|
+
|
|
262
|
+
- `--config <file>`: the config file.
|
|
263
|
+
Default: `bivium.config.{ts,mts,mjs,js,json}`.
|
|
264
|
+
- `--cwd <dir>`: the repository.
|
|
265
|
+
Default: the current directory.
|
|
266
|
+
- `--no-cache`: read every file, and skip the extraction cache.
|
|
267
|
+
- `--color` or `--no-color`: force color on or off.
|
|
268
|
+
Default: on when stdout is a terminal and no coding agent runs it;
|
|
269
|
+
`NO_COLOR` and `FORCE_COLOR` are read too.
|
|
270
|
+
- `--help` or `-h`: print usage.
|
|
271
|
+
- `--version` or `-v`: print the version.
|
|
272
|
+
|
|
273
|
+
An option takes its value as `--flag value` or `--flag=value`.
|
|
274
|
+
A switch such as `--json` also takes `=true` or `=false`.
|
|
275
|
+
A path can be repo-relative, relative to the current directory
|
|
276
|
+
(`./tests/a.test.ts`), or absolute.
|
|
277
|
+
|
|
278
|
+
An unknown command, option, suite, test, or `--format` is an error.
|
|
279
|
+
The message names what's close, when something
|
|
280
|
+
is: `unknown option --jsno (did you mean --json?)`.
|
|
281
|
+
|
|
282
|
+
## Exit status
|
|
283
|
+
|
|
284
|
+
The exit status says how a command ended:
|
|
285
|
+
|
|
286
|
+
| Status | Means |
|
|
287
|
+
| --- | --- |
|
|
288
|
+
| 0 | done |
|
|
289
|
+
| 1 | `check` found problems |
|
|
290
|
+
| 2 | a usage, configuration, or git error |
|
|
291
|
+
|
|
292
|
+
`run` exits with its command's status.
|
|
293
|
+
|
|
294
|
+
## JSON and errors
|
|
295
|
+
|
|
296
|
+
Every JSON output carries `schemaVersion`, which is `1`.
|
|
297
|
+
Dropping or retyping a field bumps it; adding a field doesn't.
|
|
298
|
+
|
|
299
|
+
With `--json`, an error goes to stdout as JSON too,
|
|
31
300
|
so a pipeline that parses stdout gets an object either way:
|
|
32
301
|
|
|
33
302
|
```json
|
|
34
303
|
{ "schemaVersion": 1, "error": { "kind": "git", "code": "BV_GIT_NO_BASE", "message": "bivium: no commit nosuchref here to diff against: fetch it." } }
|
|
35
304
|
```
|
|
36
305
|
|
|
306
|
+
`kind` says what to do about it:
|
|
307
|
+
|
|
37
308
|
| `kind` | Means |
|
|
38
309
|
| --- | --- |
|
|
39
310
|
| `usage` | bivium was called wrong |
|
|
@@ -42,23 +313,29 @@ so a pipeline that parses stdout gets an object either way:
|
|
|
42
313
|
| `other` | a failure bivium didn't name |
|
|
43
314
|
|
|
44
315
|
`code` names the failure, such as `BV_UNKNOWN_OPTION`
|
|
45
|
-
or `BV_CONFIG_INVALID
|
|
46
|
-
|
|
316
|
+
or `BV_CONFIG_INVALID`.
|
|
317
|
+
A code never changes meaning.
|
|
318
|
+
The `BiviumErrorCode` type lists them all, each with what it means.
|
|
47
319
|
From the library, `plan()` throws a `BiviumError` with the same `code`
|
|
48
320
|
and `kind`.
|
|
49
321
|
|
|
50
322
|
## From an agent
|
|
51
323
|
|
|
324
|
+
Each command has a JSON form that answers one question:
|
|
325
|
+
|
|
52
326
|
- `bivium plan --json` gives the selection per suite and why:
|
|
53
|
-
`causes` (typed) for each full run, `totals` for the scale,
|
|
54
|
-
`base
|
|
55
|
-
- `bivium why <test> --format json` gives the chain from a change to
|
|
56
|
-
test
|
|
327
|
+
`causes` (typed) for each full run, `totals` for the scale,
|
|
328
|
+
and `changed`, `base`, and `mergeBase`.
|
|
329
|
+
- `bivium why <test> --format json` gives the chain from a change to
|
|
330
|
+
a test.
|
|
331
|
+
Each link has a `kind`, such as `import` or `goto`, and an `at`,
|
|
57
332
|
as `file:line`.
|
|
58
333
|
- `bivium check --json` gives `ok` and a `summary` of what widens plans,
|
|
59
334
|
then each node with a `fix`.
|
|
60
|
-
|
|
61
|
-
|
|
335
|
+
|
|
336
|
+
Read the exit status first: 0 done, 1 `check` found problems,
|
|
337
|
+
2 an error.
|
|
338
|
+
On 2, the JSON has `error.kind` and `error.code`.
|
|
62
339
|
|
|
63
340
|
## Reading `why`
|
|
64
341
|
|
|
@@ -76,6 +353,14 @@ and `kind`.
|
|
|
76
353
|
| `depends-on`, `reads`, `lists` | the annotations |
|
|
77
354
|
| `edges` | the config's `edges` |
|
|
78
355
|
|
|
356
|
+
A barrel is a module made only of re-exports, such as `src/index.js`.
|
|
357
|
+
A named import from one depends on a barrel name,
|
|
358
|
+
such as `src/index.js#AccordionItem`,
|
|
359
|
+
and through it on that name's file alone,
|
|
360
|
+
so a change to another export doesn't select it.
|
|
361
|
+
|
|
362
|
+
The same test in each format:
|
|
363
|
+
|
|
79
364
|
```console
|
|
80
365
|
$ bunx bivium why e2e/accordion.test.ts
|
|
81
366
|
e2e/accordion.test.ts
|
|
@@ -113,8 +398,8 @@ selected: e2e/accordion.test.ts ← src/AccordionItem.svelte (5 hops)
|
|
|
113
398
|
+ 1 more change reaches this test: css/_accordion.scss (--all shows each chain)
|
|
114
399
|
```
|
|
115
400
|
|
|
116
|
-
|
|
117
|
-
and how to fix it, as `check` does:
|
|
401
|
+
A test that depends on every change reaches an unknown.
|
|
402
|
+
For one, `chain` says why, where, and how to fix it, as `check` does:
|
|
118
403
|
|
|
119
404
|
```console
|
|
120
405
|
$ bunx bivium why tests/e2e.test.ts --format chain
|
|
@@ -131,3 +416,5 @@ tests/e2e.test.ts runs on every change
|
|
|
131
416
|
- [CI](ci.md): planning in GitHub Actions
|
|
132
417
|
- [Tuning a plan](tuning.md): fixing what `check` reports
|
|
133
418
|
- [API](api.md): the same plan from code
|
|
419
|
+
- [Not supported](how-it-works.md#not-supported): what bivium leaves to
|
|
420
|
+
other tools
|