bivium 0.9.0 → 0.10.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/compute.js CHANGED
@@ -6,9 +6,10 @@ import {
6
6
  computePlan2,
7
7
  prepare2,
8
8
  plan2
9
- } from "./shared-07rt4zr7.js";
10
- import"./shared-550cvwt2.js";
11
- import"./shared-211m8fjt.js";
9
+ } from "./shared-70w84x4c.js";
10
+ import"./shared-px5a17nj.js";
11
+ import"./shared-118ck8qt.js";
12
+ import"./shared-a8ebfhzf.js";
12
13
  export {
13
14
  collectPackages2 as collectPackages,
14
15
  computePlan2 as computePlan,
package/config.js CHANGED
@@ -4,8 +4,9 @@ import {
4
4
  inRoot2,
5
5
  checkConfig2,
6
6
  loadConfig2
7
- } from "./shared-550cvwt2.js";
8
- import"./shared-211m8fjt.js";
7
+ } from "./shared-px5a17nj.js";
8
+ import"./shared-118ck8qt.js";
9
+ import"./shared-a8ebfhzf.js";
9
10
  export {
10
11
  checkConfig2 as checkConfig,
11
12
  defineConfig2 as defineConfig,
package/docs/api.md CHANGED
@@ -34,6 +34,7 @@ except `schemaVersion` and `config`:
34
34
  | Field | Holds |
35
35
  | --- | --- |
36
36
  | `suites` | each suite's selection: `{ mode: "all" }`, `{ mode: "none" }`, or `{ mode: "some", files }` |
37
+ | `cases` | per suite, each selected test that needs only some of its [`@depends-on-each`](config.md#cases) cases → those cases |
37
38
  | `totals` | how many test files each suite has |
38
39
  | `reasons` | why a suite runs in full, as sentences |
39
40
  | `causes` | the same reasons as data, one `FullRunCause` each, in order |
package/docs/ci.md CHANGED
@@ -45,6 +45,27 @@ The value is `all`, `none`, or the selected files, separated by spaces.
45
45
  The `unit` job skips on `none`, runs every test on `all`,
46
46
  and otherwise passes the files to Vitest.
47
47
 
48
+ A suite whose selected tests need only some of their
49
+ [cases](config.md#cases) also gets `<suite>-cases`: the case paths,
50
+ separated by spaces.
51
+ A job that runs the runner itself writes them to a file, one per line,
52
+ and names it in `BIVIUM_CASES`; when the output is empty,
53
+ it sets nothing, and every case runs:
54
+
55
+ ```yaml
56
+ - run: |
57
+ if [ -n "$CASES" ]; then
58
+ printf '%s\n' $CASES > "$RUNNER_TEMP/cases.txt"
59
+ export BIVIUM_CASES="$RUNNER_TEMP/cases.txt"
60
+ fi
61
+ bunx playwright test ${{ needs.plan.outputs.e2e != 'all' && needs.plan.outputs.e2e || '' }}
62
+ env:
63
+ CASES: ${{ needs.plan.outputs.e2e-cases }}
64
+ ```
65
+
66
+ The `plan` job passes it on as it does the selections,
67
+ under `outputs`: `e2e-cases: ${{ steps.plan.outputs.e2e-cases }}`.
68
+
48
69
  Three decisions shape the workflow: the checkout, the cache,
49
70
  and the cost of a plan.
50
71
 
package/docs/cli.md CHANGED
@@ -75,6 +75,9 @@ Options:
75
75
  - `--github` also writes each suite's selection to `$GITHUB_OUTPUT` as
76
76
  `<output>=all`, `none`, or the files separated by spaces.
77
77
  `<output>` is the suite's `output`, `<name>-tests` by default.
78
+ When a selected test needs only some of its [cases](config.md#cases),
79
+ it writes `<name>-cases` too: the case list `run` would pass,
80
+ separated by spaces.
78
81
 
79
82
  | Field | Holds |
80
83
  | --- | --- |
@@ -82,6 +85,7 @@ Options:
82
85
  | `config` | the config file |
83
86
  | `changed` | the files changed since the merge base |
84
87
  | `suites` | each suite's selection: `{ mode: "all" }`, `{ mode: "none" }`, or `{ mode: "some", files }` |
88
+ | `cases` | per suite, each selected test that needs only some of its [cases](config.md#cases) → those cases; a test not listed runs every case |
85
89
  | `totals` | how many test files each suite has |
86
90
  | `reasons` | why a suite runs in full, as sentences |
87
91
  | `causes` | the same reasons as data, each a `FullRunCause`: `{ kind, suites, file?, package?, narrower?, message }` |
@@ -108,8 +112,15 @@ When every test is selected, the suite's `root` goes there instead,
108
112
  so a runner that would run every suite's tests runs only this one's;
109
113
  `runAll` in the config replaces the command for that case.
110
114
  When no test is selected, `run` skips the command and exits 0.
111
- Otherwise it exits with the command's status,
112
- or 130 when Ctrl-C interrupted it.
115
+ Otherwise it exits with the command's status.
116
+
117
+ When a selected test needs only some of its [cases](config.md#cases),
118
+ `run` writes the case list to a temporary file,
119
+ one repository path per line, and names it in the command's
120
+ `BIVIUM_CASES` variable.
121
+ The list holds every case each selected test needs,
122
+ so a test runs the cases it finds there.
123
+ Without `BIVIUM_CASES`, every case runs, as in a full run.
113
124
 
114
125
  On a terminal, it opens as `plan` does, names the suites it didn't run,
115
126
  echoes the command, then closes with the result:
@@ -133,6 +144,19 @@ then the runner's output.
133
144
  bivium run --suite e2e
134
145
  ```
135
146
 
147
+ Ctrl-C reaches the runner too, as one job;
148
+ `run` waits for the runner to stop, says what stopped it, and exits 130:
149
+
150
+ ```console
151
+ ✗ unit stopped by Ctrl-C · 1.04 s
152
+ ```
153
+
154
+ A second Ctrl-C, while the runner cleans up, kills it and exits at once.
155
+ `SIGTERM` reaches only `run`, which passes it to the runner,
156
+ and exits 143.
157
+ Piped, or for a coding agent, the line is on
158
+ stderr: `bivium run: unit stopped by Ctrl-C after 1.04 s`.
159
+
136
160
  ## why
137
161
 
138
162
  `why` shows the shortest chain of edges from a changed file to a test.
@@ -221,6 +245,7 @@ The sections cover:
221
245
  (see [A change no test reaches](tuning.md#a-change-no-test-reaches));
222
246
  - `tsconfig.json` files that don't parse;
223
247
  - [dead globs](tuning.md#dead-globs);
248
+ - [globs that match files outside `roots`](tuning.md#globs-outside-the-roots);
224
249
  - repository paths a test spells that nothing declares.
225
250
 
226
251
  `check` exits 1 on any of these:
@@ -230,6 +255,7 @@ The sections cover:
230
255
  list, or an entry whose dependencies are all known;
231
256
  - a dead glob `deadGlobs` doesn't allow,
232
257
  or a `deadGlobs` entry that matches none;
258
+ - a glob that matches files outside `roots`;
233
259
  - a repository path a test spells that nothing declares.
234
260
 
235
261
  Options:
package/docs/config.md CHANGED
@@ -130,6 +130,13 @@ With `types: false`, the orphan rule counts a type-only reach only for a
130
130
  declaration file, since the runner may load any other file by name.
131
131
  List a types-only module under `root` in `nonInputs`.
132
132
 
133
+ With `types: false`, an edit to a script's comments alone selects only
134
+ what reads it as text.
135
+ With `types: true`, JSDoc is a type,
136
+ so it selects the file's
137
+ importers
138
+ ([Edits only some files can see](how-it-works.md#edits-only-some-files-can-see)).
139
+
133
140
  ## What the graph reads
134
141
 
135
142
  The graph is bivium's map of which file depends on which.
@@ -147,6 +154,8 @@ These keys set which files it reads and how it resolves imports.
147
154
  A changed file outside the roots that isn't ignored runs everything.
148
155
  That is the backstop for wiring the graph can't see,
149
156
  such as a CI workflow.
157
+ `check` fails on an annotation or config glob that matches files outside
158
+ the roots, and names what to add.
150
159
 
151
160
  `alias` is tried before tsconfig `paths` and `package.json` `exports`.
152
161
  A key ending in `/` is a prefix, as Vite reads it:
@@ -321,6 +330,7 @@ const css = readFileSync("src/tokens.css", "utf-8");
321
330
  | Comment | Declares | A change that counts |
322
331
  |:---|:---|:---|
323
332
  | `// @depends-on <glob> [glob…]` | Inputs that aren't imports: files a script reads, a tool it spawns, pages a `goto()` opens | One to an input, or to what it depends on |
333
+ | `// @depends-on-each <glob> [glob…]` | The same, where each input is a [case](#cases) of its own, such as a page a sweep test opens | The same; it runs only the cases it reaches |
324
334
  | `// @reads <glob> [glob…]` | Files read as text | A direct change to one, not to what it imports |
325
335
  | `// @lists <glob> [glob…]` | Files whose names it lists, not their contents | Adding, deleting or renaming one |
326
336
  | `// @glob-registry` | This file's `import.meta.glob` is a lookup table | None: it adds no edges |
@@ -340,6 +350,46 @@ and doesn't run its suite by the orphan rule either.
340
350
  `@glob-registry` is for an `import.meta.glob` used as a lookup table:
341
351
  whatever loads an entry names it itself.
342
352
 
353
+ ### Cases
354
+
355
+ A sweep test makes one test case per input,
356
+ such as a test that opens every fixture page.
357
+ With `@depends-on`, a change that reaches one page runs every
358
+ page's case.
359
+ `@depends-on-each` declares the same inputs and says each is a case of
360
+ its own, so a plan can pass the test the cases a change reaches:
361
+
362
+ ```ts
363
+ // e2e/layout-sweep.test.ts
364
+ // @depends-on-each e2e/fixtures/*.html
365
+ import { readdirSync, readFileSync } from "node:fs";
366
+
367
+ // The pages to run: the ones bivium lists, or every page without a list.
368
+ const list = process.env.BIVIUM_CASES;
369
+ const cases = list && new Set(readFileSync(list, "utf-8").split("\n"));
370
+ const pages = readdirSync("e2e/fixtures")
371
+ .filter((file) => file.endsWith(".html"))
372
+ .filter((file) => !cases || cases.has(`e2e/fixtures/${file}`));
373
+
374
+ for (const page of pages) {
375
+ test(page, async ({ page: tab }) => {
376
+ await tab.goto(`/${page}`);
377
+ });
378
+ }
379
+ ```
380
+
381
+ A test runs only some of its cases when a change reaches it through
382
+ them alone.
383
+ A change to the test itself, to another of its dependencies,
384
+ or to a file it depends on through an unknown runs every case,
385
+ and so does a full run.
386
+ `plan --json` lists the cases each test needs under `cases`,
387
+ `plan --github` writes them as `<suite>-cases`,
388
+ and `bivium run` names a file of them in `BIVIUM_CASES`:
389
+ one repository path per line.
390
+ Two tests can share cases, so the list holds every case of a test that
391
+ needs them all.
392
+
343
393
  ## Related
344
394
 
345
395
  - [Tuning a plan](tuning.md): which key to reach for
@@ -30,6 +30,10 @@ A one-pass lexer reads the code in these files:
30
30
  - `.vue` and `.astro`: the scripts;
31
31
  - `.html`: the scripts, and the `script[src]`,
32
32
  `link[href]` and `iframe[src]`.
33
+ A root-absolute one, as Vite's `/src/main.ts`,
34
+ resolves from the page's folder, or the nearest folder above it that
35
+ has the file, since the folder a site is served from isn't in
36
+ the page.
33
37
 
34
38
  Only code counts: an import spelled in a string
35
39
  or a comment adds no edge.
@@ -86,6 +90,100 @@ CSS isn't scanned.
86
90
  A generated stylesheet reaches its inputs through `edges`,
87
91
  and a [narrower](api.md#narrowers) can do better.
88
92
 
93
+ ## Edits only some files can see
94
+
95
+ A changed file seeds the walk whole: everything that imports it,
96
+ directly or not, can observe the change.
97
+ Two kinds of edit to a script are narrower,
98
+ and bivium reads the file's version at the merge base to tell
99
+ them apart.
100
+ Anything else it can't prove harmless is a change to the whole file.
101
+
102
+ ```console
103
+ $ bunx bivium plan
104
+ 2 of 40 tests run for 1 changed file
105
+ since origin/main (merge base 1c0ffee) · config bivium.config.ts
106
+ src/utils/keyboard-shortcut.js: only comments or line breaks changed
107
+ …
108
+ ```
109
+
110
+ ### Comments only
111
+
112
+ When a JavaScript or TypeScript file, or a `.svelte` file's `<script>`,
113
+ is the same code as at the merge base, token for token,
114
+ only a file that reads it as text can observe the edit:
115
+ an `@reads` or `reads` entry, an import with a query (`?raw`),
116
+ an `@depends-on` or `edges` glob, or an `import.meta.glob`.
117
+ Its importers aren't selected.
118
+ The same code means the comments, and the spaces and line breaks between
119
+ tokens, are all that changed; a line break still counts
120
+ where there was none, and a component's markup counts as it's written.
121
+
122
+ A barrel, a module made only of re-exports, isn't read this way:
123
+ its change already selects by the names that moved.
124
+
125
+ This applies to a suite with `types: false`.
126
+ For a suite that checks types, JSDoc is a type in JavaScript,
127
+ so a comment is code.
128
+
129
+ A comment a tool reads is code too.
130
+ An edit to one, or a move, changes the whole file:
131
+
132
+ - bivium's annotations: `@depends-on`, `@reads`,
133
+ `@lists`, `@glob-registry`;
134
+ - bundler and minifier hints: `@vite-ignore`,
135
+ `webpack…` and `turbopack…` magic comments, `#__PURE__`,
136
+ `@__NO_SIDE_EFFECTS__` and any other `#__…__` or `@__…__`;
137
+ - compiler pragmas: `@jsx`, `@jsxImportSource` and the rest of `@jsx…`,
138
+ `@ts-…` (`@ts-check`, `@ts-expect-error`), a `/// <reference …>` line,
139
+ `@flow`, `@noflow`, `@bun`, `@ngInject`;
140
+ - test environments: `@vitest-environment`, `@jest-environment`;
141
+ - coverage hints: `istanbul ignore`, `c8 ignore`, `v8 ignore`;
142
+ - `svelte-ignore`;
143
+ - comments a build keeps or reads: `@license`, `@preserve`, `/*!`,
144
+ `sourceMappingURL=`, `sourceURL=`.
145
+
146
+ ### Added exports only
147
+
148
+ When a module's only change is new `export const`,
149
+ `let` or `var` declarations whose values are literals,
150
+ loading it runs nothing new, so only a file that imports one of the new
151
+ names, or the module whole, can observe it.
152
+ That's a named import or re-export of a new name,
153
+ and any import that takes the whole module: `import * as`,
154
+ a default import, a side-effect import, `export *`, `require()`,
155
+ a dynamic `import()`, `vi.mock()`.
156
+ Text readers and globs see it, as for any change.
157
+ A barrel that re-exports a new name is a change of its own,
158
+ and selects the importers of that name.
159
+
160
+ A literal is a number, a string, a template without `${`, `true`,
161
+ `false`, `null`, `undefined`, `NaN` or `Infinity`,
162
+ or an array or object of them, joined by arithmetic and unary operators.
163
+ TypeScript adds simple annotations, as `: Array<string>`,
164
+ and `as const`.
165
+ The declarations are whole lines, between two top-level statements,
166
+ each ending with `;`, and no name they declare appears in the base
167
+ version of the file, comments included.
168
+
169
+ Everything else is a change to the whole module:
170
+
171
+ - a changed or removed export, or any other edit in the same file;
172
+ - a value that names a binding, calls, interpolates,
173
+ or is a BigInt (mixing one with a number throws);
174
+ - `export function`: bivium doesn't parse a function's body,
175
+ and one that doesn't parse would break every importer;
176
+ - `export class`, whose static fields run, `export default`,
177
+ `export { … }` and any re-export;
178
+ - a declaration without `;`, or one that would continue the statement
179
+ around it;
180
+ - a comment a tool reads, in the new lines.
181
+
182
+ For a suite that checks types, a comment edit elsewhere in the file
183
+ makes the change whole, as above.
184
+ A component's `<script>` declares no exports this way,
185
+ so a `.svelte` edit is only ever comments or the whole file.
186
+
89
187
  ## Lockfiles
90
188
 
91
189
  A dependency bump changes a lockfile, and no file imports a lockfile,
@@ -158,6 +256,7 @@ What bivium leaves to other tools, and what to use instead:
158
256
  | parse `yarn.lock` or `bun.lockb` | they're files like any other, so a change to one doesn't seed packages |
159
257
  | select below the file | a test file is selected whole, every case in it |
160
258
  | follow an import it can't read | the file counts as depending on every change, so its tests always run |
259
+ | see code read its own source at run time (`fn.toString()`, a stack trace's line numbers) | name the file in the test's `@reads`, so an edit to its comments selects the test |
161
260
  | build or cache outputs | Nx, Turborepo, or Bazel, which skip whole projects |
162
261
 
163
262
  ## Compared with
package/docs/tuning.md CHANGED
@@ -175,7 +175,8 @@ under the config's file.
175
175
  Two cases aren't dead.
176
176
  An ignored file the graph reads still starts a walk to the tests that
177
177
  reach it.
178
- A change outside the roots runs everything.
178
+ A change outside the roots runs everything; `check` reports that apart,
179
+ as a [glob outside the roots](#globs-outside-the-roots).
179
180
 
180
181
  A glob that's dead on purpose goes in `deadGlobs` with a reason:
181
182
 
@@ -189,6 +190,28 @@ deadGlobs: [
189
190
  ],
190
191
  ```
191
192
 
193
+ ## Globs outside the roots
194
+
195
+ A change to a file outside `roots` runs everything,
196
+ so a glob that points outside them never selects only its file's tests.
197
+ `check` fails on such a glob, in the same places it looks for dead ones,
198
+ and names the path to add to `roots`:
199
+
200
+ ```console
201
+ $ bunx bivium check
202
+ bivium can follow every file a test reaches
203
+ 1 glob outside roots
204
+
205
+ glob outside `roots`: a change to a match runs everything · 1 glob in 1 file
206
+ └ tests/scripts/strings.test.ts:1 reads i18n/strings.json: 1 match outside…
207
+ fix add `i18n` to `roots`: a change outside them runs everything
208
+
209
+ ✗ 1 glob outside roots · checked in 261 ms · --all for every file
210
+ ```
211
+
212
+ A match that's ignored, a `self` file or a suite's `wiring` doesn't
213
+ count: a change to it already does what the config says.
214
+
192
215
  ## Related
193
216
 
194
217
  - [Config](config.md): every key named here
package/errors.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  BiviumError2,
3
3
  didYouMean2
4
- } from "./shared-211m8fjt.js";
4
+ } from "./shared-118ck8qt.js";
5
+ import"./shared-a8ebfhzf.js";
5
6
  export {
6
7
  BiviumError2 as BiviumError,
7
8
  didYouMean2 as didYouMean
package/index.d.ts CHANGED
@@ -277,6 +277,12 @@ export type NarrowResult = {
277
277
  export interface PlanResult<Suite extends string = string> {
278
278
  /** Each suite's tests: `all`, `none`, or the files that can be affected. */
279
279
  suites: Record<Suite, Selection>;
280
+ /**
281
+ * Per suite, each selected test that needs only some of its
282
+ * `@depends-on-each` cases → those cases: the matches a change reaches. A
283
+ * test not listed runs every case, and a full run lists none.
284
+ */
285
+ cases: Record<Suite, Record<string, string[]>>;
280
286
  /** Why a suite runs in full. */
281
287
  reasons: string[];
282
288
  /** The same, as data: one per reason, in order. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bivium",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "Run only the tests your change can reach.",
5
5
  "license": "MIT",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
@@ -0,0 +1,40 @@
1
+ import {
2
+ nearest2
3
+ } from "./shared-a8ebfhzf.js";
4
+
5
+ // src/errors.ts
6
+ var KINDS = {
7
+ BV_MISSING_ARGUMENT: "usage",
8
+ BV_UNKNOWN_COMMAND: "usage",
9
+ BV_UNKNOWN_OPTION: "usage",
10
+ BV_BAD_OPTION_VALUE: "usage",
11
+ BV_UNEXPECTED_ARGUMENT: "usage",
12
+ BV_UNKNOWN_SUITE: "usage",
13
+ BV_UNKNOWN_TEST: "usage",
14
+ BV_UNKNOWN_FILE: "usage",
15
+ BV_NO_RUN_COMMAND: "usage",
16
+ BV_NO_GITHUB_OUTPUT: "usage",
17
+ BV_CONFIG_NOT_FOUND: "config",
18
+ BV_CONFIG_UNREADABLE: "config",
19
+ BV_CONFIG_INVALID: "config",
20
+ BV_GIT_NO_BASE: "git",
21
+ BV_GIT_NO_MERGE_BASE: "git",
22
+ BV_GIT_FAILED: "git",
23
+ BV_INTERNAL: "other"
24
+ };
25
+
26
+ class BiviumError2 extends Error {
27
+ code;
28
+ kind;
29
+ constructor(code, message, options) {
30
+ super(message, options);
31
+ this.code = code;
32
+ this.kind = KINDS[code];
33
+ }
34
+ }
35
+ function didYouMean2(input, candidates) {
36
+ const match = nearest2(input, candidates);
37
+ return match === undefined ? "" : ` (did you mean ${match}?)`;
38
+ }
39
+
40
+ export { BiviumError2, didYouMean2 };