bivium 0.6.0 → 0.6.1
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 +65 -565
- package/docs/api.md +69 -0
- package/docs/ci.md +112 -0
- package/docs/cli.md +133 -0
- package/docs/config.md +59 -0
- package/docs/how-it-works.md +106 -0
- package/docs/recipes.md +67 -0
- package/docs/tuning.md +91 -0
- package/package.json +2 -2
- package/shared.js +1 -1
package/README.md
CHANGED
|
@@ -1,47 +1,12 @@
|
|
|
1
1
|
# bivium
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Run only the tests your change can reach.
|
|
4
4
|
|
|
5
|
-
bivium
|
|
6
|
-
and
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
declared inputs) counts as depending on everything,
|
|
11
|
-
and a change it can't place runs the whole suite, with a reason.
|
|
12
|
-
It picks the tests; your runner runs them.
|
|
13
|
-
|
|
14
|
-
It has no dependencies and needs no install of the repository it plans:
|
|
15
|
-
it reads the git index and the working tree, never `node_modules`.
|
|
16
|
-
CI can plan in a job that skips the install,
|
|
17
|
-
and skip the test jobs whose selection is `none`.
|
|
18
|
-
It runs on Node ≥ 22 and Bun.
|
|
19
|
-
It was extracted from
|
|
20
|
-
[carbon-components-svelte](https://github.com/carbon-design-system/carbon-components-svelte)'s
|
|
21
|
-
`test:changed`.
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
bun add -d bivium
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
// bivium.config.ts
|
|
29
|
-
import { defineConfig } from "bivium";
|
|
30
|
-
|
|
31
|
-
export default defineConfig({
|
|
32
|
-
suites: {
|
|
33
|
-
unit: { tests: "tests/**/*.test.ts", run: "vitest run {files}", root: "tests" },
|
|
34
|
-
e2e: {
|
|
35
|
-
tests: "e2e/**/*.test.ts",
|
|
36
|
-
run: "playwright test {files}",
|
|
37
|
-
root: "e2e",
|
|
38
|
-
urls: { "/*": "e2e/fixtures/*" }, // page.goto("/x.html") → e2e/fixtures/x.html
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
roots: ["src", "tests", "e2e"], // a changed file outside them runs everything
|
|
42
|
-
ignore: ["**/*.md", "docs/**"],
|
|
43
|
-
});
|
|
44
|
-
```
|
|
5
|
+
bivium reads your code's imports to work out which tests a change could
|
|
6
|
+
break, and hands those to your test runner: Vitest, Jest, Playwright,
|
|
7
|
+
`bun test`, or any other.
|
|
8
|
+
When it can't tell what a change touches, it runs everything,
|
|
9
|
+
and says why.
|
|
45
10
|
|
|
46
11
|
```console
|
|
47
12
|
$ bunx bivium plan
|
|
@@ -50,323 +15,11 @@ unit tests: 3 of 12 files
|
|
|
50
15
|
tests/Modal.test.ts
|
|
51
16
|
tests/css/unknown.test.ts
|
|
52
17
|
e2e tests: none
|
|
53
|
-
$ bunx bivium run --suite unit # vitest run tests/Button.test.ts …
|
|
54
18
|
```
|
|
55
19
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
(`.js`, `.ts`, `.jsx`, `.tsx`, and their `m`/`c` variants),
|
|
60
|
-
the scripts and markup expressions of `.svelte`, the scripts of `.vue`,
|
|
61
|
-
`.astro` and `.html`, and the `script[src]`,
|
|
62
|
-
`link[href]` and `iframe[src]` of `.html`.
|
|
63
|
-
Only code counts: an import spelled in a string
|
|
64
|
-
or a comment adds no edge.
|
|
65
|
-
|
|
66
|
-
| It follows | As |
|
|
67
|
-
|:---|:---|
|
|
68
|
-
| Static, side-effect and dynamic imports, `export … from`, `require()` | Edges to every file the specifier can load: each extension that exists, each `exports` condition. A missing `x.js` (`.jsx`, `.mjs`, `.cjs`) is its TypeScript source, as TypeScript reads it: `x.ts`, `x.tsx` or `x.d.ts`, through any path, alias or `exports` target. A value import that finds only `x.d.ts` is unknown: what runs isn't in the graph |
|
|
69
|
-
| `vi.mock()`, `vi.importActual()` and the rest of the family | Edges |
|
|
70
|
-
| `import.meta.glob()` | Every matching file, now and later |
|
|
71
|
-
| JSDoc `@type {import("x")}` and `@import` | Edges (TypeScript reads them) |
|
|
72
|
-
| `%sveltekit.assets%/x` in a SvelteKit `app.html` | An edge to `static/x` in the project, the nearest directory with a `svelte.config.*` or a `package.json`. `%sveltekit.head%`, `%sveltekit.body%` and the rest aren't references |
|
|
73
|
-
| `page.goto("/x.html")` in a suite with `urls` | An edge to the page |
|
|
74
|
-
| `compilerOptions.paths` and `baseUrl` of the nearest `tsconfig.json`, with its relative `extends` | Edges to every target that exists, tried after `alias` and before `package.json` `exports`. A `tsconfig.json` that doesn't parse maps nothing, and `check` lists it |
|
|
75
|
-
| `#name` subpath imports, through the `imports` of the importing file's own `package.json` | Edges to every condition's target that exists; an unmatched `#name` is unknown |
|
|
76
|
-
| Named imports from a module made only of re-exports | An edge to the one file that exports each name, when the package declares `sideEffects` |
|
|
77
|
-
| A file's own package and its ancestors' `package.json` dependencies, and builtins | `pkg:` nodes |
|
|
78
|
-
| Anything else | Unknown: the file depends on every change |
|
|
79
|
-
|
|
80
|
-
A root `bun.lock`, `package-lock.json` or `pnpm-lock.yaml` isn't a
|
|
81
|
-
source file: a change to one seeds the packages it changed
|
|
82
|
-
(see [Lockfiles](#lockfiles)).
|
|
83
|
-
|
|
84
|
-
Nor is a `tsconfig.json` (or a file one `extends`)
|
|
85
|
-
or a `package.json` under `roots`: their options, `paths`,
|
|
86
|
-
`type` or `exports` change how the files under them resolve or run,
|
|
87
|
-
which no import says.
|
|
88
|
-
A change to one seeds the files it governs,
|
|
89
|
-
those it's the nearest of its kind to.
|
|
90
|
-
A change the parsed file doesn't show (formatting, comments),
|
|
91
|
-
or to a `package.json`'s metadata alone
|
|
92
|
-
(`version`, `description`, `repository` and the like), seeds nothing,
|
|
93
|
-
and a dependency change is the lockfile's.
|
|
94
|
-
|
|
95
|
-
A file it can't lex cleanly is read by a regex extractor instead,
|
|
96
|
-
which over-approximates.
|
|
97
|
-
CSS isn't scanned: generated stylesheets reach their inputs through
|
|
98
|
-
`edges`, and a [narrower](#narrowers) can do better.
|
|
99
|
-
|
|
100
|
-
## Config
|
|
101
|
-
|
|
102
|
-
`bivium.config.ts` (or `.mts`, `.mjs`, `.js`, `.json`) in the repository
|
|
103
|
-
root, or `--config <file>`.
|
|
104
|
-
A `.ts` config needs Bun or Node ≥ 22.18.
|
|
105
|
-
Every glob key takes one glob or a list.
|
|
106
|
-
An unknown key is an error, since a misspelled one would quietly select
|
|
107
|
-
less.
|
|
108
|
-
|
|
109
|
-
| Key | Meaning |
|
|
110
|
-
|:---|:---|
|
|
111
|
-
| `suites.<name>.tests` | The suite's test files |
|
|
112
|
-
| `suites.<name>.run` | The command `bivium run` runs. `{files}` is replaced by the selection (nothing for `all`); without it, the files are appended |
|
|
113
|
-
| `suites.<name>.root` | Where the orphan rule applies: a changed file here that no test of the suite reaches is wired some other way (a setup file, a runner config), so the whole suite runs. Paths, not globs (`e2e`, not `e2e/**`): a glob is an error. Default: the whole repository |
|
|
114
|
-
| `suites.<name>.urls` | URL pattern → file pattern, for `page.goto()` calls under `root`. A list names the page first, then what else it loads that no import says, such as a router's layouts: `{ "/*": ["app/(site)/*/page.tsx", "app/(site)/layout.tsx", "app/layout.tsx"] }`. The page must exist; the rest are edges where they do |
|
|
115
|
-
| `suites.<name>.pages` | Pages only a `goto()` opens; files only they load are wired to no test |
|
|
116
|
-
| `suites.<name>.setup` | Files the runner loads before every test (Vitest and Jest `setupFiles`, Mocha `--require`, Playwright `globalSetup`): every test of the suite depends on them and what they import. bivium doesn't read the runner's config, so name them here |
|
|
117
|
-
| `suites.<name>.wiring` | Files whose change runs the whole suite: another harness, a runner config |
|
|
118
|
-
| `suites.<name>.nonInputs` | Files under `root` the runner never reads, such as type-check inputs |
|
|
119
|
-
| `suites.<name>.types` | `false` when the suite runs code and can't observe types (Vitest, Jest, Playwright, `bun test`): a change that reaches its tests only through `import type`, `export type … from`, JSDoc types or a declaration file selects none of them. For the orphan rule a type-only reach counts only for a declaration file, since the runner may load any other file by name: list a types-only module under `root` in `nonInputs`. Default: `true`, which a type-checking suite (`tsc`, `vitest --typecheck`) needs. An inline `import { type A }` is always an edge: under `verbatimModuleSyntax` it still loads the module |
|
|
120
|
-
| `suites.<name>.output` | The step output `plan --github` writes. Default: `<name>-tests` |
|
|
121
|
-
| `roots` | Paths (not globs) the graph reads. A changed file outside them that isn't ignored runs everything. Default: the whole repository |
|
|
122
|
-
| `ignore` | Files no test can observe except through an edge (docs, stories). A change to one selects only the tests that reach it, never runs a suite by the orphan rule, and doesn't select the tests whose dependencies are unknown |
|
|
123
|
-
| `alias` | Specifier prefix → path, as the bundler aliases it. Tried before tsconfig `paths` and `package.json` `exports`. A key ending in `/` is the prefix, as Vite reads it: `{ "@/": "src/" }` maps `@/x` to `src/x` |
|
|
124
|
-
| `edges` | Generated file glob → its inputs, which it depends on transitively, as with `@depends-on`: `{ "dist/*.css": "styles/**" }`. A key may name files git doesn't list, such as a gitignored generator output (`{ ".velite/*": "content/**" }`): an import that resolves under it, by extension or as an index, lands on that file instead of being unresolved. In a value, `$1`, `$2`… are what the key's wildcards matched, counted from the left: `{ "examples/*/package.json": "examples/$1/**" }` |
|
|
125
|
-
| `reads` | File glob → the files it reads as text, as with `@reads`: only a direct change to one counts, so their imports and unknowns don't spread to it. An `edges` or `reads` key that names one file (no wildcard) declares what it reads, as its own `@depends-on` or `@reads` would, so its disk reads aren't unknown. Values take `$1`… as in `edges`: `{ "tests/*.test.ts": "tests/__snapshots__/$1.test.ts.snap" }` |
|
|
126
|
-
| `self` | The selector's own files: a change to one runs everything. The config file is always one |
|
|
127
|
-
| `importOnly` | Files only an import reaches: deleting one never orphans a suite |
|
|
128
|
-
| `hermetic` | Files whose disk reads and non-literal imports reach no file of the repository: a library's `fs` calls on its caller's paths, a test that reads only the temporary files it writes. They add no unknown, and `check` still flags a repository path one spells that nothing declares |
|
|
129
|
-
| `barrels` | Modules that may bind named imports. Default: every module made only of re-exports |
|
|
130
|
-
| `external` | Packages a dependency installs that your code imports without declaring |
|
|
131
|
-
| `inert` | Packages no test uses except by importing them: linters, formatters, type packages (`["@biomejs/biome", "knip", "@types/*"]`). A [lockfile change](#lockfiles) that only they reach selects nothing. With `loadedByName` set, only packages with a `bin` need listing. bivium itself always is |
|
|
132
|
-
| `loadedByName` | Packages a test may load other than by an import: a test environment or a plugin a config names by string (`["jsdom", "ts-jest"]`). Setting it, even to `[]`, says every other package without a `bin` is loaded only by imports, so a [lockfile change](#lockfiles) that reaches one no test imports selects only its importers. A package with a `bin` always counts as one a test may run |
|
|
133
|
-
| `extensions` | Suffixes tried after a specifier |
|
|
134
|
-
| `deadGlobs` | Dead globs `check` allows, each `{ file, glob, reason }`, the glob as `file` spells it |
|
|
135
|
-
| `knownUnknowns` | Nodes `check` allows to have unknown dependencies, each `{ file, reason }`. With it set, even to `[]` (which is `--max-unknown 0`), `check` fails on an unknown node some test reaches that it doesn't list, and on an entry that's no longer unknown, so a new unknown can't replace one that went away |
|
|
136
|
-
| `narrowers` | See [Narrowers](#narrowers) |
|
|
137
|
-
| `base` | The default base ref. Otherwise the upstream default branch (`origin/HEAD`, then `origin/main`, `origin/master`, `main`, `master`) |
|
|
138
|
-
| `cache` | The cache's directory, or `false`. Default: `node_modules/.cache/bivium`, or `.bivium/cache` |
|
|
139
|
-
|
|
140
|
-
## A change no test reaches
|
|
141
|
-
|
|
142
|
-
A changed file under a suite's `root` that no test of the suite reaches
|
|
143
|
-
is wired some other way (a runner config, a setup file),
|
|
144
|
-
so the whole suite runs: the orphan rule.
|
|
145
|
-
With the default `root`, the whole repository,
|
|
146
|
-
any file bivium can't trace to a test runs the suite,
|
|
147
|
-
which is sound and coarse.
|
|
148
|
-
Set `root` on every suite to the directories its tests
|
|
149
|
-
and sources live in, and say what the rest is:
|
|
150
|
-
|
|
151
|
-
| You changed… | and want… | Use |
|
|
152
|
-
|:---|:---|:---|
|
|
153
|
-
| a file no test can observe: docs, stories, a changelog | nothing to run, unless some test imports it | `ignore` |
|
|
154
|
-
| a file under the suite's `root` only another tool reads: type-check inputs | nothing to run for this suite | the suite's `nonInputs` |
|
|
155
|
-
| a runner config or a second harness | the whole suite | the suite's `wiring` |
|
|
156
|
-
| a setup file the runner loads before every test, or what it imports | every test of the suite | the suite's `setup` |
|
|
157
|
-
| the selector's config, or its own code | everything | `self` (the config file always is) |
|
|
158
|
-
| a declaration file, in a suite that runs code | nothing | the suite's `types: false` |
|
|
159
|
-
| a types-only module only `import type` reaches, in a suite that runs code | nothing | the suite's `types: false`, and the module in its `nonInputs` |
|
|
160
|
-
| a file a test lists but doesn't read (a route, a story) | the test, when one is added or deleted | `// @lists <glob>` in the test |
|
|
161
|
-
| a file a build turns into what tests load | the tests that load the output | `edges` from the output to its inputs |
|
|
162
|
-
|
|
163
|
-
A file outside `roots` that isn't ignored runs everything:
|
|
164
|
-
it's the backstop for wiring the graph can't see, such as a CI workflow.
|
|
165
|
-
|
|
166
|
-
`bivium check` lists every file under a suite's `root` that no test
|
|
167
|
-
reaches and the config doesn't exempt,
|
|
168
|
-
with a fix for each by what it looks like: a test's snapshot,
|
|
169
|
-
a runner's config, or anything else.
|
|
170
|
-
It's the list to work through when adopting bivium,
|
|
171
|
-
and a new entry is a gap someone added.
|
|
172
|
-
|
|
173
|
-
A file's own disk reads make it unknown,
|
|
174
|
-
but a test that hands a path to the code under test
|
|
175
|
-
(`typecheck({ workspace: "tests/fixtures" })`),
|
|
176
|
-
or a `hermetic` one that reads it, reads nothing the graph can see.
|
|
177
|
-
So `check` also reads the string literals in each test,
|
|
178
|
-
and in what the tests reach under a suite's `root`,
|
|
179
|
-
for repository paths: relative to the root when they have a slash
|
|
180
|
-
(`join(root, "tests/fixtures")`), and relative to the file
|
|
181
|
-
(`new URL("fixtures", import.meta.url)`).
|
|
182
|
-
It fails on one a change to which wouldn't select the tests that reach
|
|
183
|
-
the file, with the `reads`, `edges` or annotation that declares it.
|
|
184
|
-
A path whose change runs the suite anyway, as `wiring`,
|
|
185
|
-
`self` or by the orphan rule, doesn't fail,
|
|
186
|
-
and an unreached file's fix names where it's spelled.
|
|
187
|
-
Strings inside brackets are skipped as data
|
|
188
|
-
(`["src/a.ts", …]`, `map["key"]`), as are the directories a file is in
|
|
189
|
-
and paths outside the graph.
|
|
190
|
-
A path a test only names, such as an expected output,
|
|
191
|
-
takes `// @lists <path>`.
|
|
192
|
-
|
|
193
|
-
## Recipes
|
|
194
|
-
|
|
195
|
-
**Vitest or Jest.**
|
|
196
|
-
Name the setup files the runner loads,
|
|
197
|
-
mirror `resolve.alias` (a Vite key like `"@/"` works as written),
|
|
198
|
-
give snapshots to their tests, and, for a suite that runs code,
|
|
199
|
-
skip type-only edges:
|
|
200
|
-
|
|
201
|
-
```ts
|
|
202
|
-
suites: {
|
|
203
|
-
unit: {
|
|
204
|
-
tests: "src/**/*.test.{ts,tsx}",
|
|
205
|
-
run: "vitest run {files}",
|
|
206
|
-
root: "src",
|
|
207
|
-
setup: ["src/setupTests.ts"], // vitest.config.ts `setupFiles`
|
|
208
|
-
wiring: ["vitest.config.ts"],
|
|
209
|
-
types: false,
|
|
210
|
-
nonInputs: ["src/**/types.ts"], // types only: nothing loads them at runtime
|
|
211
|
-
},
|
|
212
|
-
},
|
|
213
|
-
alias: { "@/": "src/" },
|
|
214
|
-
reads: { "src/**/*.test.{ts,tsx}": "src/$1__snapshots__/$2.test.$3.snap" },
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
tsconfig `paths` (what `vite-tsconfig-paths` reads) are read without an
|
|
218
|
-
`alias`.
|
|
219
|
-
An extensionless `vi.mock("@/x")` resolves as an import does.
|
|
220
|
-
A test environment the runner loads by name (`jsdom`, `happy-dom`) goes
|
|
221
|
-
in `loadedByName` if you set it.
|
|
222
|
-
|
|
223
|
-
**pnpm workspaces.**
|
|
224
|
-
Workspace packages resolve through their `package.json` `exports`,
|
|
225
|
-
and a `.js` specifier into one (`@acme/ui/Button.js`) reaches its `.ts`
|
|
226
|
-
source.
|
|
227
|
-
A `pnpm-lock.yaml` change selects through the packages it changed.
|
|
228
|
-
Set `roots` to the packages and apps whose changes the suites need to
|
|
229
|
-
see, and a suite per test runner.
|
|
230
|
-
|
|
231
|
-
**Playwright.**
|
|
232
|
-
Map `page.goto()` URLs to the pages they open with `urls`,
|
|
233
|
-
list pages only a `goto()` opens in `pages`,
|
|
234
|
-
and name `playwright.config.ts` in `wiring`:
|
|
235
|
-
|
|
236
|
-
```ts
|
|
237
|
-
e2e: {
|
|
238
|
-
tests: "e2e/**/*.spec.ts",
|
|
239
|
-
root: "e2e",
|
|
240
|
-
urls: { "/*": "e2e/fixtures/*.html" },
|
|
241
|
-
wiring: ["playwright.config.ts"],
|
|
242
|
-
},
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
**Generated code.**
|
|
246
|
-
A content or type generator that writes into a gitignored directory
|
|
247
|
-
(`.velite`, `.contentlayer/generated`) is an `edges` entry from what it
|
|
248
|
-
writes to what it reads:
|
|
249
|
-
`{ ".velite/*": ["content/**", "velite.config.ts"] }`.
|
|
250
|
-
An import of `#velite` or `../.velite` then reaches the content,
|
|
251
|
-
and not every change.
|
|
252
|
-
|
|
253
|
-
## Lockfiles
|
|
254
|
-
|
|
255
|
-
A dependency bump changes a lockfile, which no file imports.
|
|
256
|
-
When a root `bun.lock`, `package-lock.json` (v2 or v3)
|
|
257
|
-
or `pnpm-lock.yaml` (v6 or v9) changes,
|
|
258
|
-
bivium diffs it against the merge base and seeds the walk with the
|
|
259
|
-
`pkg:` nodes of the packages whose entries changed,
|
|
260
|
-
and of every package that depends on one,
|
|
261
|
-
so a `svelte` bump selects what imports `svelte`,
|
|
262
|
-
or a package built on it.
|
|
263
|
-
A `package.json` whose only change is to dependencies the lockfile
|
|
264
|
-
records the same way counts as those packages changing.
|
|
265
|
-
|
|
266
|
-
A changed package can also be used in ways the graph can't see:
|
|
267
|
-
a CLI a test spawns, a runner, a type package.
|
|
268
|
-
So when a change reaches a package that a `package.json` declares,
|
|
269
|
-
or that some file imports, and that no test imports, everything runs,
|
|
270
|
-
with the reason
|
|
271
|
-
(`bun.lock: playwright 1.63.0 → 1.64.0, and no test imports it`),
|
|
272
|
-
unless the package is `inert`
|
|
273
|
-
(bivium itself always is: a bump changes which tests later plans pick,
|
|
274
|
-
not what a test does).
|
|
275
|
-
With `loadedByName` set, only a package with a `bin` in the lockfile,
|
|
276
|
-
or one it lists, counts as used that way:
|
|
277
|
-
a bump that reaches a library only a CMS config imports selects nothing.
|
|
278
|
-
Everything also runs for a lockfile bivium can't parse,
|
|
279
|
-
one whose settings other than its packages changed
|
|
280
|
-
(`overrides`, patches, pnpm's `settings`, `catalogs`, or the version of
|
|
281
|
-
pnpm itself), and a `package.json` change the lockfile doesn't record.
|
|
282
|
-
Other lockfiles (`yarn.lock`, `bun.lockb`) are files like any other:
|
|
283
|
-
outside the roots, a change to one runs everything.
|
|
284
|
-
|
|
285
|
-
```console
|
|
286
|
-
$ bunx bivium plan
|
|
287
|
-
bun.lock: @biomejs/biome 2.5.14 → 2.6.3, inert
|
|
288
|
-
bun.lock: svelte 5.57.1 → 5.57.2
|
|
289
|
-
unit tests: 4 of 12 files
|
|
290
|
-
…
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
## Annotations
|
|
294
|
-
|
|
295
|
-
| Comment | Meaning |
|
|
296
|
-
|:---|:---|
|
|
297
|
-
| `// @depends-on <glob> [glob…]` | Inputs that aren't imports: files a script reads, a tool it spawns, the pages a `goto()` the graph can't read opens (a loop over a list of URLs). Transitive. A file that reads the disk without one (or `@reads`, or `@lists`), or calls `goto()` with a URL it can't read, is unknown, unless it's `hermetic` |
|
|
298
|
-
| `// @reads <glob> [glob…]` | Files read as text. Only a direct change to one counts, not a change to what it imports. The config's `reads` says the same for files that can't hold a comment |
|
|
299
|
-
| `// @lists <glob> [glob…]` | Files whose names it lists, not their contents: a convention test that checks every route has a handler. Only adding, deleting or renaming one counts; an edit doesn't select it, and doesn't run its suite by the orphan rule either |
|
|
300
|
-
| `// @glob-registry` | This file's `import.meta.glob` is a lookup table and adds no edges: whatever loads an entry names it itself |
|
|
301
|
-
|
|
302
|
-
## CLI
|
|
303
|
-
|
|
304
|
-
| Command | Does |
|
|
305
|
-
|:---|:---|
|
|
306
|
-
| `bivium plan [base] [--json] [--github]` | Prints what it planned against (the base, its merge base, how many files changed, the config file), then each suite's selection (`none`, the files out of how many, `all` files when each reaches a change, or `all (full run)`) and why a suite runs in full. `--json` adds the base, merge base, config file, changed files, narrower results, changed packages, each suite's test count (`totals`), and the reasons as data (`causes`, each a `FullRunCause`: `{ kind, suites, file?, package?, narrower?, message }`). `--github` also writes each suite's selection to `$GITHUB_OUTPUT` |
|
|
307
|
-
| `bivium run [base] [--suite <name>]` | Runs the suite's `run` command with its selection (default: the first suite), or skips it when nothing is affected |
|
|
308
|
-
| `bivium why <test> [file] [--format tree\|chain\|source\|json] [--all]` | The shortest chain of edges from a changed file, or from `file`, to the test, with what spells each edge and the line it's on, and how many other changes reach the test. `--format tree` (the default) draws it from the test; `chain` reads from the change to the test; `source` prints each hop's line of source; `json` (or `--json`) prints the chain as data. `--all` shows every change's chain. For a test that isn't selected, it says what the file's chains reach instead |
|
|
309
|
-
| `bivium check [--max-unknown <n>] [--json]` | Counts what it found by cause first, then lists every node with unknown dependencies, with where and how to fix each cause, and fails when more than `n` of them reach a test, or on one `knownUnknowns` doesn't list. A node no test depends on is listed apart and not counted: plans only run tests, so it widens nothing. Also lists the files under a suite's `root` that no test reaches, each with a fix (a change to one runs the whole suite; see [A change no test reaches](#a-change-no-test-reaches)), `tsconfig.json` files that don't parse, and [dead globs](#dead-globs), and fails on one `deadGlobs` doesn't allow or on an entry that matches none. Fails on a repository path a test spells that nothing declares (see [A change no test reaches](#a-change-no-test-reaches)). `--json` prints the report as data, with `ok` (what the exit status says) and `summary` (the counts the text leads with) |
|
|
310
|
-
| `bivium graph [--suite <name>] [--top <n>] [--json]` | How many of each suite's tests a change to each file selects through the graph (leaving out the tests that run on any change, which it counts apart): the `n` files that reach the most, and how files spread from none to every test. A few hub files that reach most tests are what make plans wide. `--json` prints each suite's `total` and `everyChange` tests, and every node with its `imports` and `importers` (file edges), `fanIn` per suite and whether it's `unknown` |
|
|
311
|
-
|
|
312
|
-
`--config`, `--cwd` and `--no-cache` work with every command,
|
|
313
|
-
before or after it, and `why` and `check` take `--base <ref>`.
|
|
314
|
-
An option takes its value as `--flag value` or `--flag=value`,
|
|
315
|
-
and a switch such as `--json` also takes `=true` or `=false`.
|
|
316
|
-
A path may be repo-relative, relative to the current directory
|
|
317
|
-
(`./tests/a.test.ts`) or absolute.
|
|
318
|
-
`--help` (or `-h`) prints usage.
|
|
319
|
-
An unknown command, option, suite, test or `--format` is an error,
|
|
320
|
-
which names what's close when something is
|
|
321
|
-
(`unknown option --jsno (did you mean --json?)`).
|
|
322
|
-
Exit status: 0 when done, 1 when `check` finds problems, 2 for a usage,
|
|
323
|
-
configuration or git error; `run` exits with its command's status.
|
|
324
|
-
|
|
325
|
-
Every JSON output carries `schemaVersion`, which is `1`;
|
|
326
|
-
a change that drops or retypes a field bumps it, and new fields don't.
|
|
327
|
-
With `--json`, an error is also printed to stdout as JSON,
|
|
328
|
-
so a pipeline that parses stdout gets an object either way:
|
|
329
|
-
|
|
330
|
-
```json
|
|
331
|
-
{ "schemaVersion": 1, "error": { "kind": "git", "code": "BV_GIT_NO_BASE", "message": "bivium: no commit nosuchref here to diff against: fetch it." } }
|
|
332
|
-
```
|
|
333
|
-
|
|
334
|
-
`kind` is `usage` (bivium was called wrong),
|
|
335
|
-
`config`
|
|
336
|
-
(the config can't be read or is invalid; the message names the file and
|
|
337
|
-
lists every unknown key at once), `git`
|
|
338
|
-
(the base or its history is missing, or git refused, in its own words)
|
|
339
|
-
or `other`.
|
|
340
|
-
`code` names the failure, such as `BV_UNKNOWN_OPTION`
|
|
341
|
-
or `BV_CONFIG_INVALID`, and never changes meaning:
|
|
342
|
-
the `BiviumErrorCode` type lists them all, each with what it means.
|
|
343
|
-
From the library, `plan()` throws a `BiviumError` with the same `code`
|
|
344
|
-
and `kind`.
|
|
345
|
-
|
|
346
|
-
### From an agent
|
|
347
|
-
|
|
348
|
-
- `bivium plan --json` gives the selection per suite and why:
|
|
349
|
-
`causes` (typed) for each full run, `totals` for the scale, `changed`,
|
|
350
|
-
`base` and `mergeBase`.
|
|
351
|
-
- `bivium why <test> --format json` gives the chain from a change to a
|
|
352
|
-
test, each link's `kind` (`import`, `type`, `goto`, `edges`…)
|
|
353
|
-
and `at` (`file:line`).
|
|
354
|
-
- `bivium check --json` gives `ok` and a `summary` of what widens plans,
|
|
355
|
-
then each node with a `fix`.
|
|
356
|
-
- Read the exit status first: 0 done, 1 `check` found problems,
|
|
357
|
-
2 an error, with `error.kind` and `error.code` in the JSON.
|
|
358
|
-
|
|
359
|
-
`why` names each edge by what spells it:
|
|
360
|
-
`import`, `type`
|
|
361
|
-
(an `import type`, `export type … from`, JSDoc type, or an edge to or
|
|
362
|
-
from a declaration file), `setup` (a suite's setup file),
|
|
363
|
-
`goto` (a page `page.goto()` opens),
|
|
364
|
-
`html`
|
|
365
|
-
(a module an HTML page loads: `script[src]`, `link[href]`, `iframe[src]`
|
|
366
|
-
or an inline script's import), `name`
|
|
367
|
-
(a named import bound to a barrel name)
|
|
368
|
-
and `export` (the file that exports it), `glob` (`import.meta.glob`),
|
|
369
|
-
`depends-on`, `edges` (the config's), `reads` and `lists`.
|
|
20
|
+
**Every selection has a reason.**
|
|
21
|
+
`why` shows how a change reaches a test, file by file,
|
|
22
|
+
with the line that connects each one:
|
|
370
23
|
|
|
371
24
|
```console
|
|
372
25
|
$ bunx bivium why e2e/accordion.test.ts
|
|
@@ -377,217 +30,64 @@ e2e/accordion.test.ts
|
|
|
377
30
|
└─ name src/index.js#AccordionItem e2e/fixtures/Fixture.svelte:2
|
|
378
31
|
└─ export src/AccordionItem.svelte src/index.js:2
|
|
379
32
|
● changed
|
|
380
|
-
+ 1 more change reaches this test: css/_accordion.scss (--all shows each chain)
|
|
381
|
-
|
|
382
|
-
$ bunx bivium why e2e/accordion.test.ts --format chain
|
|
383
|
-
src/AccordionItem.svelte changed
|
|
384
|
-
exported as AccordionItem src/index.js:2
|
|
385
|
-
imported by e2e/fixtures/Fixture.svelte:2
|
|
386
|
-
imported by e2e/fixtures/accordion.ts:1
|
|
387
|
-
loaded by page e2e/fixtures/accordion.html:10
|
|
388
|
-
opened by e2e/accordion.test.ts:13 ← selected
|
|
389
|
-
+ 1 more change reaches this test: css/_accordion.scss (--all shows each chain)
|
|
390
|
-
|
|
391
|
-
$ bunx bivium why e2e/accordion.test.ts --format source
|
|
392
|
-
selected: e2e/accordion.test.ts ← src/AccordionItem.svelte (5 hops)
|
|
393
|
-
|
|
394
|
-
--> e2e/accordion.test.ts:13 goto
|
|
395
|
-
13 | await page.goto("/accordion.html");
|
|
396
|
-
--> e2e/fixtures/accordion.html:10 html
|
|
397
|
-
10 | <script type="module" src="./accordion.ts"></script>
|
|
398
|
-
--> e2e/fixtures/accordion.ts:1 import
|
|
399
|
-
1 | import Fixture from "./Fixture.svelte";
|
|
400
|
-
--> e2e/fixtures/Fixture.svelte:2 name
|
|
401
|
-
2 | import { Accordion, AccordionItem } from "carbon-components-svelte";
|
|
402
|
-
--> src/index.js:2 export
|
|
403
|
-
2 | export { default as AccordionItem } from "./AccordionItem.svelte";
|
|
404
|
-
● src/AccordionItem.svelte: changed
|
|
405
|
-
+ 1 more change reaches this test: css/_accordion.scss (--all shows each chain)
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
For a test that depends on every change, `chain` says why, where,
|
|
409
|
-
and how to fix it, as `check` does:
|
|
410
|
-
|
|
411
|
-
```console
|
|
412
|
-
$ bunx bivium why tests/e2e.test.ts --format chain
|
|
413
|
-
tests/e2e.test.ts runs on every change
|
|
414
|
-
because scripts/launcher.js:10 unresolved "./cli-entry.js"
|
|
415
|
-
fix: no file at that path: fix the import, or add an `edges` entry if a build generates it
|
|
416
|
-
reached via scripts/launcher.js
|
|
417
|
-
depended on by scripts/build.ts:1
|
|
418
|
-
depended on by tests/e2e.test.ts:2 ← selected
|
|
419
33
|
```
|
|
420
34
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
`check` evaluates every `@depends-on`, `@reads`,
|
|
426
|
-
`@lists` and `import.meta.glob` pattern,
|
|
427
|
-
every `edges` and `reads` value, and every suite's `setup`,
|
|
428
|
-
against every file git lists
|
|
429
|
-
(tracked and untracked, inside the roots or not) and reports one that:
|
|
430
|
-
|
|
431
|
-
| Problem | Means |
|
|
432
|
-
|:---|:---|
|
|
433
|
-
| matches nothing | No file matches: a typo or a stale path |
|
|
434
|
-
| matches only ignored files, partly ignored | Some matches are ignored and not in the graph, so a change to one selects nothing |
|
|
35
|
+
It has no dependencies and runs on Node ≥ 22 or Bun.
|
|
36
|
+
It started as
|
|
37
|
+
[carbon-components-svelte](https://github.com/carbon-design-system/carbon-components-svelte)'s
|
|
38
|
+
`test:changed`.
|
|
435
39
|
|
|
436
|
-
|
|
437
|
-
every file its key matches, and a key that matches no file the graph
|
|
438
|
-
reads is reported too, under the config's file.
|
|
439
|
-
An ignored file the graph reads still seeds a walk,
|
|
440
|
-
and a change outside the roots runs everything, so neither is dead.
|
|
441
|
-
A glob that's dead on purpose goes in `deadGlobs` with a reason:
|
|
40
|
+
## Quick start
|
|
442
41
|
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
{ file: "tests/css/tokens.test.ts", glob: "docs/src/**", reason: "docs-only changes skip CI" },
|
|
446
|
-
],
|
|
42
|
+
```sh
|
|
43
|
+
bun add -d bivium
|
|
447
44
|
```
|
|
448
45
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
and feed each suite's job its selection:
|
|
46
|
+
```ts
|
|
47
|
+
// bivium.config.ts
|
|
48
|
+
import { defineConfig } from "bivium";
|
|
453
49
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
e2e: ${{ steps.plan.outputs.e2e-tests }}
|
|
461
|
-
steps:
|
|
462
|
-
- uses: actions/checkout@v7
|
|
463
|
-
with:
|
|
464
|
-
# History back to the merge base; see "The checkout" below.
|
|
465
|
-
fetch-depth: 0
|
|
466
|
-
filter: blob:none
|
|
467
|
-
- uses: oven-sh/setup-bun@v2
|
|
468
|
-
- id: merge-base
|
|
469
|
-
run: echo "sha=$(git merge-base origin/main HEAD)" >> "$GITHUB_OUTPUT"
|
|
470
|
-
- uses: actions/cache@v6
|
|
471
|
-
with:
|
|
472
|
-
path: .bivium/cache
|
|
473
|
-
key: bivium-${{ steps.merge-base.outputs.sha }}
|
|
474
|
-
restore-keys: bivium-
|
|
475
|
-
- id: plan
|
|
476
|
-
# --bun: run on Bun, which loads a TypeScript config whatever Node
|
|
477
|
-
# the runner has.
|
|
478
|
-
run: bunx --bun bivium plan origin/main --github
|
|
479
|
-
unit:
|
|
480
|
-
needs: plan
|
|
481
|
-
if: needs.plan.outputs.unit != 'none'
|
|
482
|
-
steps:
|
|
483
|
-
# …install, then run all tests or the selected files:
|
|
484
|
-
- run: bunx vitest run ${{ needs.plan.outputs.unit != 'all' && needs.plan.outputs.unit || '' }}
|
|
50
|
+
export default defineConfig({
|
|
51
|
+
suites: {
|
|
52
|
+
unit: { tests: "tests/**/*.test.ts", run: "vitest run {files}", root: "tests" },
|
|
53
|
+
},
|
|
54
|
+
roots: ["src", "tests"], // a changed file outside them runs everything
|
|
55
|
+
});
|
|
485
56
|
```
|
|
486
57
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
the commit where it forked from the base branch.
|
|
491
|
-
So the job needs the history back to that commit,
|
|
492
|
-
not only the commit under test.
|
|
493
|
-
`actions/checkout` fetches one commit by default (`fetch-depth: 1`),
|
|
494
|
-
with no base branch, and the plan stops with what's missing:
|
|
495
|
-
|
|
496
|
-
```
|
|
497
|
-
bivium: origin/main and HEAD share no commit here, so there's no merge base to diff against. The clone is shallow: fetch the history (actions/checkout: `fetch-depth: 0`).
|
|
58
|
+
```sh
|
|
59
|
+
bunx bivium plan # which tests this branch needs
|
|
60
|
+
bunx bivium run # run them: vitest run tests/Button.test.ts …
|
|
498
61
|
```
|
|
499
62
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
such as a push to the default branch, can keep the default:
|
|
503
|
-
`fetch-depth: ${{ github.event_name == 'pull_request' && '0' || '1' }}`.
|
|
504
|
-
|
|
505
|
-
The history git fetches is three kinds of object:
|
|
506
|
-
commits, trees
|
|
507
|
-
(each directory's file names, each with the ID of its content)
|
|
508
|
-
and blobs (the contents).
|
|
509
|
-
A plan needs the commits, to find the merge base, and the trees,
|
|
510
|
-
to list what changed.
|
|
511
|
-
Of the blobs it needs the working tree's, which the checkout has,
|
|
512
|
-
and the merge base's version of a few changed files only:
|
|
513
|
-
a lockfile, a `package.json`, a `tsconfig.json`, a barrel,
|
|
514
|
-
and what a narrower reads.
|
|
515
|
-
So pick the clone by how big the history is:
|
|
516
|
-
|
|
517
|
-
| History | Checkout | What a plan pays |
|
|
518
|
-
| :--- | :--- | :--- |
|
|
519
|
-
| Small: a full clone takes a second or two | `fetch-depth: 0` | Nothing more: every old version is already on disk |
|
|
520
|
-
| Large: years of commits, big files | `fetch-depth: 0` and `filter: blob:none` | A fetch from the remote for the old versions it reads, when a change needs any: about a second, sometimes several |
|
|
521
|
-
|
|
522
|
-
`filter: blob:none` makes a partial clone: every commit and tree,
|
|
523
|
-
and only the blobs the checkout needs.
|
|
524
|
-
Git fetches any other blob when something reads it,
|
|
525
|
-
and fetches for reads made at once run in parallel.
|
|
526
|
-
Without the filter, a large history's old contents are most of the
|
|
527
|
-
download; with it, a small repository pays a round trip to the remote
|
|
528
|
-
for contents it could have had for free.
|
|
529
|
-
|
|
530
|
-
### The cache
|
|
63
|
+
Exit status: 0 when done, 1 when `check` finds problems, 2 for an error;
|
|
64
|
+
`run` exits with its command's status.
|
|
531
65
|
|
|
532
|
-
|
|
533
|
-
so a warm plan reads only the files a branch changed.
|
|
534
|
-
Key it on the merge base: a pull request can restore caches from the
|
|
535
|
-
default branch, whose run at that commit is the one to hit.
|
|
536
|
-
Without `node_modules`, the cache lives in `.bivium/cache`;
|
|
537
|
-
it writes a `.gitignore` so it never shows up as a change.
|
|
66
|
+
## Common tasks
|
|
538
67
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
(median of five, wall time):
|
|
68
|
+
```sh
|
|
69
|
+
# Plan against a ref you name, as data
|
|
70
|
+
bivium plan origin/main --json
|
|
543
71
|
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
| carbon-components-svelte | 4,680 | 0.15 s | 0.09 s | 0.27 s | 0.13 s | 452 KB |
|
|
547
|
-
| generated TypeScript, 23 MB | 7,000 | 0.14 s | 0.08 s | 0.30 s | 0.12 s | 896 KB |
|
|
72
|
+
# Run one suite's selection
|
|
73
|
+
bivium run --suite e2e
|
|
548
74
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
under a second.
|
|
552
|
-
A cold plan of the generated repository peaks at 88 MB of RSS on Bun
|
|
553
|
-
and 124 MB on Node.
|
|
75
|
+
# Why does this test run, or not?
|
|
76
|
+
bivium why tests/Button.test.ts
|
|
554
77
|
|
|
555
|
-
|
|
78
|
+
# What bivium can't see, each with its fix
|
|
79
|
+
bivium check
|
|
556
80
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
so any style edit selects every e2e test.
|
|
560
|
-
A narrower replaces such a change's coarse seeds with finer ones from a
|
|
561
|
-
semantic diff, such as the sources that render a changed CSS rule.
|
|
81
|
+
# Which files reach the most tests
|
|
82
|
+
bivium graph --top 10
|
|
562
83
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
{
|
|
566
|
-
name: "css",
|
|
567
|
-
match: "styles/**", // the changed files it narrows
|
|
568
|
-
opaque: "dist/*.css", // the generated nodes its seeds stand in for
|
|
569
|
-
suites: ["e2e"],
|
|
570
|
-
async narrow({ base, head, changed, graph }) {
|
|
571
|
-
const rules = diffRules(await compile(base.commit), await compile(head.commit));
|
|
572
|
-
if (!rules) return { all: "a rule that requires no class changed" };
|
|
573
|
-
return { seeds: sourcesSpelling(rules), note: `${rules.length} rules changed` };
|
|
574
|
-
},
|
|
575
|
-
},
|
|
576
|
-
],
|
|
84
|
+
# In GitHub Actions: write each suite's selection to the step's outputs
|
|
85
|
+
bivium plan origin/main --github
|
|
577
86
|
```
|
|
578
87
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
walk without it selects.
|
|
583
|
-
One that returns `{ all: reason }`, throws,
|
|
584
|
-
or returns anything else runs its suites in full with the reason.
|
|
585
|
-
`narrow()` gets the repository `root`,
|
|
586
|
-
the merge base and the working tree as `base`
|
|
587
|
-
and `head` (each with `commit` and `read(path)`),
|
|
588
|
-
the matched `changed` files, and a read-only `graph`
|
|
589
|
-
(`nodes()`, `importers(node)`, `dependents(nodes)`, `tests(suite)`).
|
|
590
|
-
carbon-components-svelte runs one over crassus.
|
|
88
|
+
With `--json`, every command prints data with a `schemaVersion`,
|
|
89
|
+
and an error prints `{ "error": { "kind", "code", "message" } }` too.
|
|
90
|
+
These docs ship in the package, at `node_modules/bivium/docs/`.
|
|
591
91
|
|
|
592
92
|
## From code
|
|
593
93
|
|
|
@@ -599,21 +99,21 @@ const result = await plan({ config, base: "origin/main" });
|
|
|
599
99
|
result.suites.unit; // { mode: "some", files: [...] }; result.suites.e2e is a type error
|
|
600
100
|
```
|
|
601
101
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
the
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
102
|
+
## Docs
|
|
103
|
+
|
|
104
|
+
- [Config](https://github.com/metonym/bivium/blob/master/docs/config.md):
|
|
105
|
+
every key, and the `@depends-on`, `@reads` and `@lists` comments
|
|
106
|
+
- [Tuning a plan](https://github.com/metonym/bivium/blob/master/docs/tuning.md):
|
|
107
|
+
when a change runs too much, and what `check` reports
|
|
108
|
+
- [Recipes](https://github.com/metonym/bivium/blob/master/docs/recipes.md):
|
|
109
|
+
Vitest, Jest, Playwright, pnpm workspaces, generated code
|
|
110
|
+
- [CLI](https://github.com/metonym/bivium/blob/master/docs/cli.md):
|
|
111
|
+
every command and option, the JSON, and reading `why`
|
|
112
|
+
- [CI](https://github.com/metonym/bivium/blob/master/docs/ci.md):
|
|
113
|
+
GitHub Actions, the checkout a plan needs, the cache,
|
|
114
|
+
and what a plan costs
|
|
115
|
+
- [API](https://github.com/metonym/bivium/blob/master/docs/api.md):
|
|
116
|
+
`plan()`, and narrowers for generated files
|
|
117
|
+
- [How it works](https://github.com/metonym/bivium/blob/master/docs/how-it-works.md):
|
|
118
|
+
what the graph follows, lockfiles, and how bivium compares with
|
|
119
|
+
`vitest --changed`, Playwright, Nx and Bazel
|